[R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread dankelley
I have a comma-separated data file in which trailing commas sometimes occur. I am using strsplit to extract the data from this file, and it seems great except in cases with trailing comma characters. The example below illustrates. What I'd like is to get a fourth element in the answer, being an

Re: [R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread Benilton Carvalho
my understanding is that this behavior is known (the help file mentions something along these lines in the example). i'd use something like: theText <- "a,,b," theText <- gsub("\\,$", ", ", theText) and then use strsplit() on "theText" b On Dec 3, 2007, at 6:22 PM, dankelley wrote: I hav

Re: [R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread Peter Dalgaard
dankelley wrote: > I have a comma-separated data file in which trailing commas sometimes occur. > I am using strsplit to extract the data from this file, and it seems great > except in cases with trailing comma characters. > > The example below illustrates. What I'd like is to get a fourth elemen

Re: [R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread Gabor Grothendieck
Try appending another comma: strsplit(paste("a,,b,", ",", sep = ""), ",") On Dec 3, 2007 6:22 PM, dankelley <[EMAIL PROTECTED]> wrote: > > I have a comma-separated data file in which trailing commas sometimes occur. > I am using strsplit to extract the data from this file, and it seems great > e

Re: [R] strsplit on comma, with a trailing comma in input

2007-12-03 Thread dankelley
This works perfectly. Thanks! Peter Dalgaard wrote: > >> > Hmm, I don't think strsplit can do that. However: > > > scan(textConnection("a,,b,"), sep=",", what="") > Read 4 items > [1] "a" "" "b" "" > > -- >O__ Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B > c/ /'_