I have an ffdf object with 200K rows and 12K columns.
This is from a LEFT JOIN with another ffdf object, so has a lot of NA across the different columns.
How can I replace all NA with a specific value (say, FALSE, since the additional columns from the LEFT JOIN are all LOGICAL)?
I can successfully use the following syntax over one column to replace all NA in that column ("coltest"):
ffdfOut$coltest <- with(ffdfOut, ifelse(is.na(coltest), FALSE, coltest))
but the following loop:
cnamesLogical) <- colnames(ffdfOut)[12:12000]
for(colname in cnamesLogical)
{
ffdfOut[, colname] <- with(ffdfOut, ifelse(is.na(colname), FALSE, colname))
}
gives me error:
Error in with.ffdf(ffdfOut, ifelse(is.na(colname), FALSE, colname)) : 'with.ffdf' only returns ff object of equal length of nrow(data)
Thanks for any help on this!
您可以使用lapply()
遍历数据集的每一列
lapply(ffdfOut[,12:12000], FUN=function(coltest) ifelse(is.na(coltest), FALSE, coltest))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.