Message-ID: <1357662126.30546.YahooMailNeo@web142602.mail.bf1.yahoo.com>
Date: 2013-01-08T16:22:06Z
From: arun
Subject: Logical operator and lists
In-Reply-To: <CALvVS-HFLtqpFKmTtGYTuNOf-C_SB9RoN1BHBeB+Ti+S6k2Y1A@mail.gmail.com>
Hi,
Try this:
?set.seed(5)
?list1<-lapply(1:3,function(i) data.frame(col1=sample(c(1:5,""),10,replace=TRUE), value=rnorm(10),stringsAsFactors=FALSE))
?res<-lapply(list1,function(x) {x[apply(x,2,function(y) y=="")]<-NA;x})
res[[1]]
#?? col1????? value
#1???? 2 -0.6029080
#2???? 5 -0.4721664
#3? <NA> -0.6353713
#4???? 2 -0.2857736
#5???? 1? 0.1381082
#6???? 5? 1.2276303
#7???? 4 -0.8017795
#8???? 5 -1.0803926
#9? <NA> -0.1575344
#10??? 1 -1.0717600
A.K.
----- Original Message -----
From: Dominic Roye <dominic.roye at gmail.com>
To: R help <r-help at r-project.org>
Cc:
Sent: Tuesday, January 8, 2013 7:16 AM
Subject: [R] Logical operator and lists
Hello R-Helpers,
I have a slight problem with the expresion data[data==""] <- NA which works
well for a data.frame. But now i must use the same for a list of
data.frames.
My idea is data[[]][data==""] but it don?t work.
Thanks!!
Dominic
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.