0

I have multiple csv files. I want to place the content of all the column ones from all the csv files in one column. I also want do not want specific number of rows to be included in this.

Example file1.csv

         Column1 Column2
            A       1  
            B       2
            C       3
            D       4
            E       5

file2.csv

         Column1 Column2
           F         6
           G         7
           H         8
           I         9
           J         10

Result Result.csv

        Column1  Column2
          C          3
          D          4
          E          5
          H          8
          I          9
          J          10

My code:

   temp = list.files(pattern="*.csv")
   myfiles = lapply(temp, read.delim,nrow=4292,skip=1472,sep=",")
   nana<-do.call(rbind,myfiles)
   write.table(nana,"result_polmeans.csv",sep=",")

This code produces 2 columns per each csv file. The error stems from do.call function Error in match.names(clabs, names(xi)) : names do not match previous names

1
  • 1
    Try, do.call(rbind,myfiles) Commented Apr 15, 2015 at 18:39

3 Answers 3

3

You may use Reduce after creating myfiles to solve this problem

all.data <- Reduce(function(x,y) rbind(x, y), myfiles)

It will take the myfiles list and rbind all of it's elements together, leaving you with a single data frame to pass into write.table

Sign up to request clarification or add additional context in comments.

Comments

3

Data frames can be appended with "row-bind" syntax like rbind(df1,df2,df3,...).

If you have a list of data frames, do.call can be used to bind them:

do.call(rbind,myfiles)

Comments

0
   temp = list.files(pattern="*.csv")
   new.data <- NULL

   for(i in temp) { 
                   in.data <- read.table(i,skip=1472,sep=",")
                   new.data <- rbind(new.data, in.data)
                }

   write.table(new.data,"result_polmeans.csv",sep=",")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.