[R] selection of character
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.be
Wed Apr 4 16:21:29 CEST 2007
one way is the following:
x <- c("10_1", "1_1", "11_1", "2_1", "3_1", "4_1",
"5_1", "6_1", "7_1", "8_1")
#########
sapply(strsplit(x, "_"), "[", 2)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Leonardo Lami" <lami at faunalia.it>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, April 04, 2007 4:11 PM
Subject: [R] selection of character
> Hi all,
>
> I have a simple question:
> I have a character vector like this
>
> [1] "10_1" "1_1" "11_1" "2_1" "3_1" "4_1" "5_1" "6_1" "7_1"
> "8_1"
> [11] "9_1" "1_3" "2_3" "3_3" "4_3" "1_4" "2_4" "3_4" "4_4"
> "5_4"
> [21] "6_4" "7_4" "1_5" "2_5" "10_6" "11_6" "12_6" "1_6" "2_6"
> "3_6"
> [31] "4_6" "5_6" "6_6" "7_6" "8_6" "9_6" "1_7" "1_8" "2_8"
> "3_8"
> [41] "10_9" "1_9" "2_9" "3_9" "4_9" "5_9" "6_9" "7_9" "8_9"
> "9_9"
> [43] "1_10" "2_10"
>
> and I'd like to have a vector with only the value after the under
> scor,
> like this:
>
> [1] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
> [11] "1" "3" "3" "3" "3" "4" "4" "4" "4" "4"
> [21] "4" "4" "5" "5" "6" "6" "6" "6" "6" "6"
> [31] "6" "6" "6" "6" "6" "6" "7" "8" "8" "8"
> [41] "9" "9" "9" "9" "9" "9" "9" "9" "9" "9"
> [43] "10" "10"
>
> Is there a simple function to do this?
>
> Thank you for your help
> All the best
>
> Leonardo
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
More information about the R-help
mailing list