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

From: dankelley <Dan.Kelley_at_dal.ca>
Date: Mon, 3 Dec 2007 15:22:36 -0800 (PST)

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 empty string just like the second element. Is there a way I can express my patter (or perhaps specify perl or extended) to get that?

> strsplit("a,,b,", ",")[[1]]

[1] "a" "" "b"

View this message in context: http://www.nabble.com/strsplit-on-comma%2C-with-a-trailing-comma-in-input-tf4940023.html#a14141151
Sent from the R help mailing list archive at Nabble.com.

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 03 Dec 2007 - 23:26:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 04 Dec 2007 - 00:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.