Hi, You could also try this: Lines<-"-100 -100-3456-3456-3456-100 -100 23 -3456-3456-189 34 56 78 -100 34 56 21 44 65 78" Lines1<-readLines(textConnection(Lines)) res1<-unlist(strsplit(gsub("[-]"," -",Lines2)," ")) matrix(as.numeric(res1[res1!=""]),nrow=length(Lines1),byrow=TRUE) [,1] [,2] [,3] [,4] [,5] [,6] [,7] #[1,] -100 -100 -3456 -3456 -3456 -100 -100 #[2,] 23 -3456 -3456 -189 34 56 78 #[3,] -100 34 56 21 44 65 78
A.K. ----- Original Message ----- From: Jaime Otero Villar <j.o.vil...@bio.uio.no> To: r-help@r-project.org Cc: Sent: Friday, November 30, 2012 7:55 AM Subject: [R] how to separate stuck row elements? Hi, I was wondering if it's possible to separate elements in multiple rows that actually should appear in different columns. I have a file where in certain lines there are elements not separated, and they certainly should appear in different columns (an example of the file is attached). The point is that I do not want to manually add a space in the txt file, however, I did not manage to do it automatically in R... Thanks in advance for any insight. Jaime ______________________________________________ R-help@r-project.org 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. ______________________________________________ R-help@r-project.org 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.