Hi, I have a list called ds which has the following attributes: attributes(ds) $names [1] "adj.r.squared" "fstatistic" "intercept" "slope" [5] "std.error" "tstatistic" I want to replace all the NaN is ds with 0, and after searching past posts I found I can hardcode it like this: ds$adj.r.squared=replace(ds$adj.r.squared,is.nan(ds$adj.r.squared),0) ds$fstatistic=replace(ds$fstatistic,is.nan(ds$fstatistic),0) ... ds$tstatistic=replace(ds$tstatistic,is.nan(ds$tstatistic),0) But, there has to be a more elegant/general solution. I've tried messing around with lapply but can't seem to get it to work. Any suggestion? thanks, mishkin -- View this message in context: http://r.789695.n4.nabble.com/replacing-NaN-for-every-attribute-in-my-data-tp4636160.html Sent from the R help mailing list archive at Nabble.com.
replacing NaN for every attribute in my data
3 messages · Yasir, mishkind
You can try this:
for (i in 1:length(ds)) {
dummy<-ds[[i]];
dummy[is.nan(dummy)]<-0
ds[[i]]<-dummy
}
if is.nan doesn't work, replace with is.na
-----
Yasir Kaheil
--
View this message in context: http://r.789695.n4.nabble.com/replacing-NaN-for-every-attribute-in-my-data-tp4636160p4636163.html
Sent from the R help mailing list archive at Nabble.com.
Thanks. That worked. -- View this message in context: http://r.789695.n4.nabble.com/replacing-NaN-for-every-attribute-in-my-data-tp4636160p4636185.html Sent from the R help mailing list archive at Nabble.com.