Hi, I'm a new R user and I'm having trouble with the read.csv command. It somehow treats the first column as a row name field even though it's not a row name. there are no missing columns/entries and i'm not sure how to resolve this. the format of my data is A, B, C, D,......(3984 columns) 12, 13, 41,......(all numeric) it either treats column A as rownames or if I explicitly disable row names with row.names = NULL field it right shifts all the columns like rowno. A B C Last column 1 12 13 41 .... NA Srinivas -- View this message in context: http://r.789695.n4.nabble.com/read-csv-help-tp3677454p3677454.html Sent from the R help mailing list archive at Nabble.com.
Can you explain a little more? I have created a small CSV file following your pattern which looks like this in a text editor: A,B,C,D,E 65,68,71,74,77 67,71,75,79,83 69,73,77,81,85 71,77,83,89,95 When I load it into R with> x <- read.csv( "a.csv" )I get this which I think is what you would expect:> xA B C D E 1 65 68 71 74 77 2 67 71 75 79 83 3 69 73 77 81 85 4 71 77 83 89 95 with> rownames( x )[1] "1" "2" "3" "4" Here is the dput version:> dput( x )structure(list(A = c(65L, 67L, 69L, 71L), B = c(68L, 71L, 73L, 77L), C = c(71L, 75L, 77L, 83L), D = c(74L, 79L, 81L, 89L), E = c(77L, 83L, 85L, 95L)), .Names = c("A", "B", "C", "D", "E"), class = "data.frame", row.names = c(NA, -4L)) What is different with your data? Rgds, Rainer -------- Original-Nachricht --------> Datum: Tue, 19 Jul 2011 00:05:30 -0700 (PDT) > Von: psombe <srinivas.eswar at gmail.com> > An: r-help at r-project.org > Betreff: [R] read.csv help> Hi, > I'm a new R user and I'm having trouble with the read.csv command. It > somehow treats the first column as a row name field even though it's not a > row name. there are no missing columns/entries and i'm not sure how to > resolve this. > > the format of my data is > > A, B, C, D,......(3984 columns) > 12, 13, 41,......(all numeric) > > it either treats column A as rownames or if I explicitly disable row names > with row.names = NULL field it right shifts all the columns like > > rowno. A B C Last column > 1 12 13 41 .... NA > > Srinivas > > -- > View this message in context: > http://r.789695.n4.nabble.com/read-csv-help-tp3677454p3677454.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.-- ------- Windows: Just say No.
Alexander James Rickett
2011-Jul-19 08:11 UTC
[R] tm: Read a single text file into a corpus as single document?
Hello everyone, I'm doing some JGR (a gui frontend for R) development, specifically adding functionality from tm. In order to enable users to select some text files from a file dialog, and turn them into a corpus, I need to be able to generate a corpus using a *SINGLE* text file as a single document, and to append a new document to an existing corpora. I know if I could read files into single character vectors I'd be in business, but I can't find how to do this either. This seems like a no-brainer, so I'm at my wits' end. Here's pseudo code of what I'd like to be able to do: ##########################################> corp1doc <- Corpus(singleTextDocSource("path/to/doc")) #read in 1 text doc as a 1-document corpus > corp1docA corpus with 1 text document> corp1doc[[2]] <- AnotherSingleTextDoc("path/to/doc") #append a second document to the same corpus > corp1docA corpus with 2 text documents ########################################## I can almost do this with dirSource, by setting pattern='filename', but this requires me to also to separate the path to the enclosing directory, which shouldn't be necessary. Thanks for taking a look!