On Wed, Oct 12, 2011 at 1:20 AM, Erin Hodgess wrote:
> Dear R People:
>
> I have the following set of data
>> Block[1:5]
> [1] "5600-5699" "6100-6199" "9700-9799" "9400-9499" "8300-8399"
>
> and I want to split at the -
>
>> strsplit(Block[1:5],"-")
> [[1]]
> [1] "5600" "5699"
>
> [[2]]
> [1] "610
On Oct 12, 2011, at 1:20 AM, Erin Hodgess wrote:
Dear R People:
I have the following set of data
Block[1:5]
[1] "5600-5699" "6100-6199" "9700-9799" "9400-9499" "8300-8399"
and I want to split at the -
strsplit(Block[1:5],"-")
[[1]]
[1] "5600" "5699"
[[2]]
[1] "6100" "6199"
[[3]]
[1] "9
Hi Erin,
this is one way:
Block <- c("5600-5699","6100-6199","9700-9799","9400-9499","8300-8399")
splBlock <- strsplit(Block,"-")
sapply(splBlock, "[", 1)
greetings,
Remko
--
View this message in context:
http://r.789695.n4.nabble.com/strsplit-question-tp3896847p3896850.html
Sent from th
sapply(strsplit(Block[1:5],"-"), function (x) {x[1]})
comes to mind...
---
Jeff Newmiller The . . Go Live...
DCN: Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#.
unlist(strsplit(Block[1:5], "-.+$"))
if you are going to want the other pieces later, the most efficient
way depends on the assumptions you can make about your data. If there
are always two elements from the split:
matrix(unlist(strsplit(Block[1:5], "-")), ncol = 2, byrow = TRUE)
## or
do.call("
Dear R People:
I have the following set of data
> Block[1:5]
[1] "5600-5699" "6100-6199" "9700-9799" "9400-9499" "8300-8399"
and I want to split at the -
> strsplit(Block[1:5],"-")
[[1]]
[1] "5600" "5699"
[[2]]
[1] "6100" "6199"
[[3]]
[1] "9700" "9799"
[[4]]
[1] "9400" "9499"
[[5]]
[1] "8300
6 matches
Mail list logo