[R] A list of data frames and a list of colnames.

Rui Barradas ruipbarradas at sapo.pt
Mon Oct 23 23:22:09 CEST 2017


Hello,

I think that your code is simple enough to be considered "nice". If you 
are worried about the for loop, don't, were loops worrying they wouldn't 
exist.

Hope this helps,

Rui Barradas

Em 23-10-2017 22:09, Ed Siefker escreveu:
> I have a list of file names, and a list of data frames contained in those files.
>
> mynames <- list.files()
> mydata <- lapply(mynames, read.delim)
>
> Every file contains two columns.
>
>> colnames(mydata[[1]])
> [1] "Name"     "NumReads"
>> colnames(mydata[[2]])
> [1] "Name"     "NumReads"
>
> I can set the colnames easily enough with a for loop.
>
> for (i in seq_along(mynames)) {
>      colnames(mydata[[i]])[2] <- mynames[i]
> }
>
> Is there a nicer way to do this?
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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