How to automate read.csv command in R? -
i'm doing stupid , cannot read.csv write lot of files.
if write:
write.csv(x1, file = "x1.csv")
then writes ~2mb csv file ok. have around 2000 variables in memory , i've tried
for (i in seq_along(fotos)) { write.csv(paste("x", i, sep = ""), file = paste(paste("x", i, sep = ""),"csv", sep="."))}
i obtain desired files files ~2kb , x1.csv contains 1 cell saying "x1.csv", , all files similar because x1000.csv contains "x1000.csv", unlike command write.csv(x1, file = "x1.csv") creates file x1.csv containing matrix of 96x96.
any idea of i'm doing wrong?
many in advance.
you can object name function get
. however, better read data frames list objects related having common names.
so can create list of data frames:
x <- lapply(seq_along(fotos), function(i) get(paste0("x", i))) names(x) <- fotos
and write them (and you'd use if had list start with):
lapply(names(x), function(name) write.csv(x[[name]], paste(name, 'csv', sep='.')))
Comments
Post a Comment