Reading a list of mixed type values

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Reading a list of mixed type values

Ulrike Grömping-2
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html