On Tuesday, December 3, 2013 2:31 PM, Luis Santom? Collazo <santomecjl at
gmail.com> wrote:
Hi everyone,
HI,
##Creating a reproducible example
set.seed(45)
lst1 <- lapply(1:3,function(i)
data.frame(AAA=sample(c(NA,1:10),20,replace=TRUE),BBB=sample(40,20,replace=TRUE)))
lapply(seq_along(lst1),function(i)
write.table(lst1[[i]],paste0("file",i,".tab"),quote=FALSE))
dataset <- list.files(pattern="*.tab")
dataset
[1] "file1.tab" "file2.tab" "file3.tab"
?replace_empty <- llply(dataset,function(x) {x1 <-
read.table(x,header=TRUE); x1$AAA[is.na(x1$AAA)]<- 0; x1})##no errors here
A.K.
I'd like to replace the empty cells from a numerical variable (let's say
variable "AAA") with zero in multiple dataframes using
"plyr" package.
Of course all the dataframes have the same structure but different
number of lines.
I've been trying variations of:
|dataset <- list.files(pattern = "*.tab")
replace_empty <- llply(dataset,function(x){x$AAA[is.na(x$AAA)] <-0;
return(x)})
|
But I always get the same error message:
? ? unexpected numeric constant in
"llply(dataframes,function(x){x$AAA"
Any suggestion?
Thank you in advance!
Regards,
--
??? [[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.