I have a .csv file with data for different chromosomes. The chromosomes names are stored in the first column(column name: Chr). My aim is to separate the data for each chrom
Read Data
fn <- dir(pattern="csv") data_in <- do.call(rbind,lapply(fn,read.csv))
Split by chromosome
data_out <- split(data_in,data_in[[1]])
Write by chromosome
chn <- unlist(lapply(data_out,"[",1,1)) for(i in seq_along(chn)) write.csv(data_out[[i]],file=paste(chn[i],"csv",sep="."))