I can reproduce the error you get if AllDat is not a data frame.
class(tmp) #tmp is a tibble, basically a data frame
[1] "grouped_df" "tbl_df" "tbl" "data.frame"
AllDat <- 3 #define AllDat so that it is not a data frame
rbind(AllDat, tmp) #this throws the error
Error: Argument 1 must have names.
Run `rlang::last_error()` to see where the error occurred.
AllDat <- data.frame() #make AllDat an empty data frame
AllDat <- rbind(AllDat, tmp) # No error
The following code works for me to read in two csv files and rbind them into one data frame.
library(dplyr)
Files <- list.files(path = "~/R/Play/", pattern = ".csv")
AllDat <- data.frame()
summary(AllDat) #This line is not necessary, just for illustration
< table of extent 0 x 0 > #AllDat is an empty data frame
for ( FileName in Files) {
tmp <- read.csv(paste0("~/R/Play/", FileName),sep=" ")
tmp$File <- FileName
tmp <- tmp %>% group_by(File) %>%
mutate(Grp = (row_number() - 1) %/% 3)
AllDat <- rbind(AllDat, tmp)
}
summary(AllDat)
dur energy f01 values val File
Min. :35 Min. :100 Min. :234.0 Min. : 633 Min. : 2.00 Length:24
1st Qu.:41 1st Qu.:100 1st Qu.:238.8 1st Qu.:2790 1st Qu.: 9.25 Class :character
Median :47 Median :101 Median :245.0 Median :5392 Median :18.00 Mode :character
Mean :47 Mean :101 Mean :245.9 Mean :5252 Mean :17.33
3rd Qu.:53 3rd Qu.:102 3rd Qu.:249.2 3rd Qu.:7762 3rd Qu.:25.50
Max. :59 Max. :102 Max. :275.0 Max. :9713 Max. :32.00
Grp
Min. :0.00
1st Qu.:0.75
Median :1.50
Mean :1.50
3rd Qu.:2.25
Max. :3.00