[R] Reading a list of mixed type values

Ulrike Grömping groemping at tfh-berlin.de
Thu Mar 16 12:34:40 CET 2006


Dear helpeRs,

I have a column of various different entry types denoting missing value codes 
for a data frame. Elements can be numbers (e.g. 9), combinations of numbers 
e.g. in the form c(0,9,99), or NULL (for no valid missing data code).

I used 

codes<-read.table(paste
   (path2, "MissingCodes.csv",sep=""),header=FALSE,as.is=T) 
codes <- as.list(codes$V1)

to read the codes and transform them into a list, which unfortunately is a 
list of character entries:

codes <- as.list(c("NULL", "9", "999", "c(0,9)", "c(999,99)")) 
### reproducible mini version of what I get

I do not know how to transform these to the numeric versions I need. With

codesnum<-lapply(codes,function(obj){if (!is.na(as.double(obj))) 
    as.double(obj) else { if (obj=="NULL") NULL 
    else obj)}})

I can handle everything but the "c(0,9)" type characters. I have without 
success tried various ways to get these into numeric versions (c(0,9)). 
Any suggestions ? There might even be something quite simple around?

Thanks and regards, Ulrike




More information about the R-help mailing list