[R] remove NAs from list collectively

Johannes Radinger JRadinger at gmx.at
Wed Feb 8 11:54:19 CET 2012


Hi,

I am importing dataframe from an Excel file (xlsx package).
The columns contain acutally measurements for single species and
the column-length is of variable. As it is imported as a dataframe the difference to the "longest" column is filled with NA.
To explain it with an example, my dataframe looks like:

A <- seq(1:10)
B <- c(seq(1:5),rep(NA,5))
C <- c(seq(1:7),rep(NA,3))

df <- data.frame(A,B,C)


Now I'd like to transform that to a list of vectors of different length. Therefore I need to remove the NAs collectively from the single columns...I tried for transforming:

as.list(df)

...but I don't know how can I remove the NAs now? as.list doesn't take na.rm=TRUE argument. Is there any ready function to perform such tasks?
Or is there a better way then to assign the data to a list of vectors with variable length?

/johannes
--



More information about the R-help mailing list