Re: [R] Replacing NAs with 0 for a list of data frames

2010-05-31 Thread Kang Min
Thanks, it works except that I had to add xx <- as.data.frame(xx) into func. I am trying to calculate diversity indices using the vegan package, and the functions require zeroes instead of NAs. Thanks. Kang Min On May 31, 5:09 pm, Tal Galili wrote: > I would consider trying the plyr package usi

Re: [R] Replacing NAs with 0 for a list of data frames

2010-05-31 Thread Tal Galili
I would consider trying the plyr package using the llply function. With something like: require(plyr) func <- function(xx) { xx[is.na(xx)] <- 0 return(xx) } llply(your.df.list, func) What I wondering is why you want to do this. Best, Tal Contact Details:-

[R] Replacing NAs with 0 for a list of data frames

2010-05-31 Thread Kang Min
Hi, I have a list of 100 data frames, each data frame has 50 obs of 377 variables. I would like to replace all the NAs with 0 in all the dataframes. Should I have a for loop for every data frame? Below is an extract of how the data looks like. List of 100 $ :'data.frame':50 obs. of 377