Re: [R] using sapply to apply function to some columns of a dataframe

2009-02-17 Thread Duncan Murdoch
On 17/02/2009 4:42 PM, mwestp...@worldbank.org wrote: Hello: I would like to sum every x columns of a dataframe for each row. For instance, if x is 10, then for dataframe df, this function will sum the first ten elements together and then the next ten: sapply(list(colnames(df)[1:10], colnames(

[R] using sapply to apply function to some columns of a dataframe

2009-02-17 Thread mwestphal
Hello: I would like to sum every x columns of a dataframe for each row. For instance, if x is 10, then for dataframe df, this function will sum the first ten elements together and then the next ten: sapply(list(colnames(df)[1:10], colnames(df)[11:20]),function(x)apply( df[,x], 1, sum)) If the