Re: [R] reading a column as a character vector

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Fri, 06 May 2011 10:09:11 -0600

The strsplit function is probably the closest R function to perls split function. For more detailed control the gsubfn package can be useful.

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Gamliel Beyderman Sent: Thursday, May 05, 2011 3:35 PM
To: r-help_at_r-project.org
Subject: [R] reading a column as a character vector

Hi!

I have 2 columns (even though the data looks like there's more columns than just two) of data in the following format:

0,"58905313R0EOL" "229742002R0EOL" "58905312R0EOL"
1,"58905317R0DBL" "58905303R0DBL" "58905313R0IL" "58905313R0VH"

"58905313R0EOL" "223354003R0IL" "223354003R0VH" "58905308R0DBL"
"58905308R0VM" "58905301R0DBL" "229742002R0IL" "229742002R0VH"
"229742002R0EOL"
I can change the format of the input (remove quotes, add spaces, only put quotes around the entire list of codes...)

The first column is numeric, the second column is a character vector of event codes. Ultimately, I want to to transform the second column into a factor where each event code (such as 58905313R0EOL or 216918000R0DBL) is a separate level.

while the following statement works:

reduce2<-read.table("reduce2.csv", sep=",", colClasses=c("integer","factor"))

it does not know to break the event vectors into separate levels, the factor it creates is wrong.

Perhaps there's something in R similar to split in Perl...

Thanks!

        [[alternative HTML version deleted]]



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.

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. Received on Fri 06 May 2011 - 16:12:54 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

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 Fri 06 May 2011 - 16:40:05 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.

list of date sections of archive