[R] Help batch saving elements of a list into unique files

Jim Lemon drjimlemon at gmail.com
Tue Mar 22 22:48:22 CET 2016


Hi Christian,
This untested script might get you going (assuming you want a CSV format):

for(affdf in 1:length(out)) {
 names(out[[affdf]])<-lapply(strsplit(names(out[[affdf]]),"[.]"),"[",2)
 write.csv(out[[affdf]],file=paste("affymetrix",affdf,".txt",sep=""))
}

Jim


On Wed, Mar 23, 2016 at 6:32 AM, Christian T Stackhouse (Campus)
<ctstackh at uab.edu> wrote:
> Hello!
>
>
> The overall goal I have is taking a large data frame and splitting it into several smaller data frames (preserving column headers) which I can save as txt files to feed into my APACHE ANY23 server for conversion into RDF.
>
>
> This is what I call to split up the original file:
>
>
> out <- split(affymetrix, (seq(nrow(affymetrix))-1) %/% 140)
>
>
> I have a list (out) of length 187 for which each element is a dataframe. I want to iteratively save each data frame as a separate tab file with a naming structure such as: affymetrix1.txt, affymetrix2.txt, ... affymetrix187.txt
>
>
> Before that, I need to modify the headers to remove a prefix "X0. , X1., ... X187." that was introduced during my original splitting. I need to remove all characters before and including the first "."
>
>
> If anyone has a better way of doing this, please let me know. Otherwise, help with how to perform batch editing of the headers and batch saving of the files would be greatly appreciated!
>
>
> Best,
>
> Christian T. Stackhouse | Graduate Student
> GBS Neuroscience Theme
> Department of Neurosurgery
> Department of Radiation Oncology
> UAB | The University of Alabama at Birmingham
> Hazelrig-Salter Radiation Oncology Center | 1700 6th Ave S | Birmingham, AL 35233
> M: 919.724.6890 | ctstackh at uab.edu | cstackhouse at uabmc.edu | ctstackh at gmail.com
>
> uab.edu<http://uab.edu/>
> Knowledge that will change your world
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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