Re: [R] Conditional Loop For Data Frame Columns

2012-01-09 Thread Rui Barradas
P.S. If you want to use your function, revised, it may be a good idea: it's faster #write indexed mean function meanfun <- function(x, inx, na.rm=FALSE) { meanSD <- matrix(0, nrow=length(levels(inx)), ncol=length(3:ncol(x))) for(i in 3:ncol(x)) { meanSD[, i - 2] <

Re: [R] Conditional Loop For Data Frame Columns

2012-01-09 Thread Rui Barradas
Hello, I believe that the following solves it: aggregate(SD[, 3:ncol(SD)], by=list(ID), mean) aggregate(SD[, 3:ncol(SD)], by=list(ID), mean, na.rm=TRUE) It's the second you want, it will compute the means for groups that aren't only NA and return NaN for groups with all values NA. Rui Barradas

Re: [R] Conditional Loop For Data Frame Columns

2012-01-08 Thread David Winsemius
On Jan 9, 2012, at 12:02 AM, jawbonemurphy wrote: Hi Dave, Thanks for your response! I'm new at R, and I'm afraid I'm not sure what you mean by: ?lapply ?"[" ?order It means I thought you might get the answers you needed by looking at those functions' help pages. Were these suggestio

Re: [R] Conditional Loop For Data Frame Columns

2012-01-08 Thread jawbonemurphy
Hi Dave, Thanks for your response! I'm new at R, and I'm afraid I'm not sure what you mean by: ?lapply ?"[" ?order Were these suggestions for other commands to try? If so, can you be more specific? I apologize for being clueless :) Secondly, you're right that the script I have now leaves me

Re: [R] Conditional Loop For Data Frame Columns

2012-01-08 Thread David Winsemius
On Jan 8, 2012, at 4:48 PM, jawbonemurphy wrote: Hi, I am trying to create a script that will evaluate each column of a data frame, regardless of # columns, using some function and sorting the results by an index vector: ?lapply ?"[" ?order #upload data (112 rows x 73 columns) SD <- r

[R] Conditional Loop For Data Frame Columns

2012-01-08 Thread jawbonemurphy
Hi, I am trying to create a script that will evaluate each column of a data frame, regardless of # columns, using some function and sorting the results by an index vector: #upload data (112 rows x 73 columns) SD <- read.csv("/Users/johnjacob/Desktop/StudentsData_RInput.csv", header=TRUE) #assign