I would like to split my data.frame
depending of a column tagged as "Chr"
. I would like to write these splitted objects in a .txt
file automatically too.
My input:
Name Chr Position LTR
Prob1 1 55 0.2
Prob2 2 25 0.9
Prob3 3 25 0.7
Prob4 1 45 0.5
My First output:
Name Chr Position LTR
Prob1 1 55 0.2
Prob4 1 45 0.5
My second output:
Name Chr Position LTR
Prob2 2 25 0.9
My last output:
Name Chr Position LTR
Prob3 3 25 0.7
I am trying to do something like:
outfile <- paste0("newsplit",i,".txt") SPLIT PROCEDURES write.table(all, outfile, sep=";")
Where "i"
is the correspondent chromosome (value in a "Chr"
collumn).
Cheers!
First split your data.frame.
df.split <-split(df,df$Chr)# where df is your original dataframe
#and we split on Chr
Now, write it out to separate tab-separated files
lapply(names(df.split),function(x)
write.table(file = paste0("df",x,".txt"),
df.split[[x]], sep = "\t"))
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.