Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread jim holtman
The '[[' is just the index access to an object. type: ?'[[' to see the help page. Actually I should have used '[' in this case: > sapply(y, '[', 1) [1] "1234567" "1234567" "1234567" is equivalent to: > sapply(y, function(a) a[1]) [1] "1234567" "1234567" "1234567" > So set a value based o

Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread Su C.
Yes, that was perfect! Thank you so much! Just to clarify, since I'm kind of new to string manipulation-- is that '[[' in the sapply function what is designating splits/elements within the string? So that's the part that says "I want this particular element" and the "1" or "2" or "number" is what

Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread hadley wickham
On Fri, Feb 5, 2010 at 9:29 AM, jim holtman wrote: > Does this help: > >> x <- >> c("1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12") >> y <- strsplit(x, '[.]') Here's another way with the stringr package: library(stringr) x <- c("1234567.z3.abcdef-gh.12","1234567.

Re: [R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread jim holtman
Does this help: > x <- > c("1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12") > y <- strsplit(x, '[.]') > > y [[1]] [1] "1234567" "z3""abcdef-gh" "12" [[2]] [1] "1234567" "z3""abcdef-gh" "12" [[3]] [1] "1234567" "z3""abcdef-gh" "12" > y

[R] String Manipulation- Extract numerical and alphanumerical segment

2010-02-05 Thread Su C.
I am currently attempting to split a long list of strings (let's call it "string.list") that is of the format: "1234567.z3.abcdef-gh.12" I have gotten it to: "1234567" "z3" "abcdef-gh" "12" by use of the strsplit function. This leaves me with each element of "string.list" having a split stri