[R] For loop on data frame

2013-01-31 Thread Esam Tolba
I am a beginner in R. I wrote a function to read a data frame from a file and then split it into certain number of data frames and write each one of them in a separate txt file. the function is working perfectly for the first four files the it gives me files contain one column of NA values.

Re: [R] For loop on data frame

2013-01-31 Thread Jeff Newmiller
Your example is not reproducible. See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example I would guess you have tabs at the ends of your lines in the input file. This is a fairly common problem when you muck with data in Excel. To find these problems

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-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] -

[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

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 -

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 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