Question: (Closed) Error While Combining Multiple Csv
0
gravatar for Bmusungu
6.6 years ago by
Bmusungu20
Bmusungu20 wrote:
> files <- list.files(pattern=".csv")
> files
[1] "GDS2475.csv"       "GDS2477.csv"       "GSE12594_soft.csv"
[4] "GSE15435.csv"      "GSE20130.csv"     

> data()
> DF <- NULL
> for (f in files) {
+    dat <- read.csv(f, header=T, sep="\t", na.strings="", 
+ colClasses="character")
+    DF <- rbind(DF, dat)
+ }
Error in match.names(clabs, names(xi)) : 
  names do not match previous names
>

I saw this script for reading multiple csv files and combining. I got the error in the bottom. Any suggestions would be helpful, because I am new to R.

microarray R • 2.6k views
ADD COMMENTlink modified 10 weeks ago by RamRS18k • written 6.6 years ago by Bmusungu20

Are the columns the same length for each file?

ADD REPLYlink written 6.6 years ago by Zev.Kronenberg11k

I would say: "are the number of columns the same..." ;-)

ADD REPLYlink written 6.6 years ago by Manu Prestat3.8k

No, because I've been trying to combine microarray soft files together.

ADD REPLYlink written 6.6 years ago by Bmusungu20

This is a basic R question with little bioinformatics research content. Closing as off-topic: try stackoverflow.com.

ADD REPLYlink written 6.6 years ago by Neilfws48k
1
gravatar for Manu Prestat
6.6 years ago by
Manu Prestat3.8k
Marseille, France
Manu Prestat3.8k wrote:

Hi, I'm not sure it's the best place for "R only" questions here, but let's give it a try: first, perhaps the data() line is unuseful. I think the error here is due to rbind() (means combine by rows) which checks your dataframes have the same column names. Try by putting the same names, for instance by adding in the loop a colnames() call:

for (f in files) {
 dat <- read.csv(f, header=T, sep="\t", na.strings="", colClasses="character")
 colnames(dat)<-c("col1","col2","col3")
 DF <- rbind(DF, dat)
 }

If it's not a good answer, try on R-help, or stackoverflow.

ADD COMMENTlink modified 6.6 years ago • written 6.6 years ago by Manu Prestat3.8k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 672 users visited in the last hour