Dear group, i have 114 files (all have 5 columns) and variable number of rows.
I want to read all the files and select the first column and 4th column and fill the values into a big matrix. I have a pre-made matrix that would have all rownames (1st column) and coloumn names (4th column from file to be read). mymat <- matrix(data = 1, nrow = length(gomfs), ncol = length(x)) rownames(tarmat)<-gomfs colnames(tarmat)<-x # here gomfs is a large set of rownames from the files to be read. # x (114 files) for(i in x){ xa <- read.table(i,sep='\t') a2 <- as.character(xa[,1]) a3 <- xa[,4] nd <- data.frame(a2,a3) tarmat[a2,i] = a3 } What is the problem then: The problem is a2 has ' (single quotes). So when a2 does not have singles quote, everything works fine. But when a2 has ' - then starting from there to the EOF all values are cluttered. Example: > a2[49] [1] "mRNA guanylyltransferase activity" > a2[50] [1] "polynucleotide 5-phosphatase activity\t1\t1\t0.0160650535501781\t0.0160650535501781\t0.0664390950962566\nribulose-phosphate 3-epimerase activity\t1\t1\t0.0160650535501781\t0.0160650535501781\t0.0664390950962566\n How can I escape the ' quote character when I read each file. So that I do not have the problem of clutter and my matrix is read well. Thank you. ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.