Skip to content

An averaged model based on Quartile and Mean of Quartiles

3 messages · Elahe chalabi, David Winsemius, Ulrik Stervbo

#
Hi all,

Here is my df and I want to make an averaged model of my variables based on Time like the following:

    
   $ Protocol   : Factor w/ 48 levels "DP FS QTSE SAG",..: 2 3 43 42 
   $ Time       : num  182 185 189 234 186 ... 

   $ Systemtype   : Factor w/ 2 levels "Aera XJ","AERA XQ": 1 1 1 
   $ ADJ        : Factor w/ 2 levels "auto","manu": 1 1 
   $ BR         : int  384 384 384 384 512 384
   $ TF         : int  10 10 13 7 7 5 5 
I split my df into quartiles for time,

   
   df$quant=findInterval(df$Time, quantile(df$Time), rightmost.closed=TRUE)
by the column df$quant I see quartiles 1 to 4 for time, next I want to create a new column for example for BR and if df$quant==1 then put mean of first quartile of BR in that,if df$quant==2 put mean of second quartile of BR in that and so on. I do the same for every numeric variable. Does anyone know how to that?


Thanks for any help!
Elahe
#
Perhaps, but untested in the absence of a reproducible example and choosing to instead use a name for the dataframe which is not also a function name:

aggregate( dfrm[ , sapply( dfrm, inherits, "numeric")],   # logical indexing for `[, j]`
           dfrm['quant']      # using "[" keeps it a list
           mean)
#
Hi Chalabi,

Maybe you can use ddply to look over the intervals and add the means as new
colum

Best wishes
Ulrik

David Winsemius <dwinsemius at comcast.net> schrieb am Sa., 21. Mai 2016 17:16: