This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Error While Combining Multiple Csv
> 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.

r microarray

Are the columns the same length for each file?

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

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

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

1 answer

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.

Log in to answer this question.