r - reading several files in loop -
i have bunch of csv files want read r. when use following code last file (in case file.100.csv) stored inside variable named i.
for (i in seq(10,100,10)) = read.csv(file=paste("file.", i, ".csv",sep=""), header=t, sep=",", skip=0, check.names=true) i want store every file inside separate variable named 10, 20, 30 ... 100. i've tried store in array:
for (i in seq(10,100,10)) file_csv[[i]] = read.csv(file=paste("file.", i, ".csv",sep=""), header=t, sep=",", skip=0, check.names=true) but gives me following error:
error in file_csv[[i]] = read.csv(file = paste("file.", i, ".csv", sep = ""), : object 'file_csv' not found anyway, i'm not sure if r array can contain numbers not ascending 1 instead ten. guess purpose kind of hash table more useful.
this not work because assign outcome of read.csv (and not interpretation of i, instance 1 in first round of loop). need assign:
for (i in 1:10) {assign(paste0("variable", i), 5)} with assign variable name is interpreted. running above assign 5 variable1 - variable10. in case need
for (i in seq(10,100,10)) { assign(i, read.csv(file=paste("file.", i, ".csv",sep=""), header=t, sep=",", skip=0, check.names=true)) }
Comments
Post a Comment