r - why does rbind need a loop to create a data frame and not just a vector of matrixes -


for (i in 1:5) {         dat <- rbind(dat, read.csv(files_full[i])) 

works,

dat <- rbind(dat, read.csv(files_full[1:5])) 

doesn't:

error in file(file, "rt") : invalid 'description' argument

files_full returns this:

[1] "diet_data/andy.csv"  "diet_data/david.csv" "diet_data/john.csv"  [4] "diet_data/mike.csv"  "diet_data/steve.csv" 

from exercise: https://github.com/rdpeng/practice_assignment/blob/master/practice_assignment.rmd

rbind() meant bind it's parameters, not elements contained in lists inside of parameters. example

dat <- rbind(read.csv(files_full[1]), read.csv(files_full[2], read.csv(files_full[3]) 

would work. if want turn list parameter, use do.call

dat <- do.call("rbind", vectorize(read.csv, simplify = false)(files_full)) 

here used vectorize() allow read.csv return list when given vector of file names.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -