'Sarah Goslee'
Cc: 'r-help'
Sent: Monday, November 26, 2012 2:33 PM
Subject: Re: [R] Help in splitting the records
Another approach is to use gsub() followed by read.table():
> x <- c("qwer$$12$$qwre", "ewrtr$7789$ewwe")
> x <- gsub("\\$+&
.org] On Behalf Of Bert Gunter
> Sent: Monday, November 26, 2012 1:00 PM
> To: Sarah Goslee
> Cc: r-help
> Subject: Re: [R] Help in splitting the records
>
> Sarah:
>
> You may not agree, but the following avoids the IMHO ugly rbind() and
> separate conversion to numeric
Sarah:
You may not agree, but the following avoids the IMHO ugly rbind() and
separate conversion to numeric by using scan():
## first, as before..
x <- c("qwer$$12$$qwre", "ewrtr$7789$ewwe")
x <- strsplit(x, "\\$+")
## Then, instead ...
x.convert <- data.frame(scan(textConnection(unlist(x)),wh
In the example below, I don't see any "$$$" separators. Are you sure this is
supposed to be the separate or just a single dollar sign? If this is the case,
you don't specify what is to happen when multiple separators appear next to
each other. From your example, it appears that two separators
Hi,
You could do this:
Lines<-"qwer$$12$$qwre
ewrtr$7789$ewwe
"
res<-unlist(strsplit(Lines,split="\\$|\n"))
as.data.frame(matrix(res[res!=""],nrow=2,byrow=TRUE),stringsAsFactors=FALSE)
V1 V2 V3
#1 qwer 12 qwre
#2 ewrtr 7789 ewwe
A.K.
- Original Message -
From: ar
You state that you want "$$$" as the separator, but your example has
"$$" and "$" so I'm assuming an indeterminate number of consecutive
$.
x <- c("qwer$$12$$qwre", "ewrtr$7789$ewwe")
x <- strsplit(x, "\\$+")
x <- do.call(rbind, x)
x <- data.frame(x, stringsAsFactors = FALSE)
x$X2 <- as.numeric(x
6 matches
Mail list logo