Re: [R] apply formula over columns by subset of rows in a dataframe (to get a new dataframe)

2016-05-14 Thread Massimo Bressan
thank you, what a nice compact solution with ave() I learned something new about the subtleties of R let me here summarize the alternative solutions, just in case someonelse might be interested... thanks, bye # # my user function (an example) mynorm <- function(x) {(x - min(x,

Re: [R] apply formula over columns by subset of rows in a dataframe (to get a new dataframe)

2016-05-13 Thread William Dunlap via R-help
ave() encapsulates the split/lapply/unsplit stuff so transform(mydf, v1.mod = ave(v1, blocks, FUN=mynorm)) also gives what you got above. Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, May 13, 2016 at 7:44 AM, Massimo Bressan < massimo.bres...@arpa.veneto.it> wrote: > yes, thanks > >

Re: [R] apply formula over columns by subset of rows in a dataframe (to get a new dataframe)

2016-05-13 Thread Massimo Bressan
yes, thanks you pointed me in the right direction: split/unplist was the trick I completely left behind that possibility! here the final version mynorm <- function(x) {(x - min(x, na.rm=TRUE))/(max(x, na.rm=TRUE) - min(x, na.rm=TRUE))}

Re: [R] apply formula over columns by subset of rows in a dataframe (to get a new dataframe)

2016-05-13 Thread David L Carlson
You can do this with split/unsplit: > mydf.split <- split(mydf, mydf$blocks) > str(mydf.split) List of 3 $ a:'data.frame': 5 obs. of 3 variables: ..$ blocks: Factor w/ 3 levels "a","b","c": 1 1 1 1 1 ..$ v1: num [1:5] 19 15 17 22 16 ..$ v2: num [1:5] 35 31 35 31 39 $

[R] apply formula over columns by subset of rows in a dataframe (to get a new dataframe)

2016-05-13 Thread Massimo Bressan
hi I need to apply a user defined formula over some selected columns of a dataframe by subsetting group of rows (blocks) and get back a new dataframe I’ve been managed to get the the calculations right but I’m not satisfied at all by the form of the results please refer to my reproducible