[R] extract all data frames from a list & remove NAs

Rui Barradas ruipbarradas at sapo.pt
Tue Sep 25 20:34:26 CEST 2012


Hello,

You should have kept it in the R-Help list, the odds of having more 
answers would be greater.

There was a bug in the loop. It should be cleanDataSets[[i]] not 
cleanDataSets[i].
Anyway, I've simplified it a bit.


fls <- list.files(pattern = "*.csv")
files <- lapply(fls, read.csv, header=T)
good <- lapply(files, complete.cases)

cleanDataSets <- lapply(seq_along(fls), function(i) files[[i]][ 
good[[i]], ])


Hope this helps,

Rui Barradas

Em 25-09-2012 15:29, Dimitris r escreveu:
> hi,
>
> steps taken :
>
> files<-lapply(list.files(),read.csv,header=T)
>   numberOfFiles<-length(list.files())
> good<-lapply(files,complete.cases)
> cleanDataSets<-list()
>
> for (i in 1:numberOfFiles){
>      cleanDataSets[i]=files[[i]][good[[i]],]
>    }
>
> with this loop for some reason i get only the first column from each data
> frame from the list
>
>
> if want to retrieve the only one data frame from the list i can do like
> this:
>
> files<-lapply(list.files(),read.csv,header=T)
> good<-complete.cases(files[[1]])
> files[[1]][good,]
>
> thanks in advance
> Dimitris
>
> 	[[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.




More information about the R-help mailing list