How can I unlist and rbind the csv files?
I had many csv files in a directory. They all have two columns and unequal number of rows. I made a list using
list.files(pattern=".csv$") # use the pattern argument to define a common pattern for import files with regex. Here: .csv
list.filenames<-list.files(pattern=".csv$")
list.data<-list()
for (i in 1:length(list.filenames))
{
list.data[[i]]<-read.csv(list.filenames[i])
}
names(list.data)<-list.filenames
The data look as follows:
$`xxx-xxx.csv`
PositionX Value
1 2 -107.068
2 6 -35.074
...
$`xxx1-xxx1.csv`
PositionX Value
1 2 -9.230
2 6 -9.230
...
There are thousands of csv files in the format mentioned above. I just would like to rbind them together and, without the header. For example I want to have:
PositionX Value 1 2 -107.068 2 6 -35.074 3 2 -9.230 4 6 -9.230
I have already tried the following solutions:
big.list.of.data.frames <- lapply(list.data, function(x){
+ read.table(x, skip = 3, header = TRUE, stringsAsFactors = FALSE)
+ })
I get the following:
Error in read.table(x, header = TRUE, stringsAsFactors = FALSE) :
'file' must be a character string or connection
I have also tried
myMergedData <- do.call(rbind,list.data)
I get the error:
Error in rbind(deparse.level, ...) :
numbers of columns of arguments do not match
I've made sure all my csv files have 2 columns.