[R] Stringr Package
Ista Zahn
istazahn at gmail.com
Wed Apr 10 19:26:44 CEST 2013
On Wed, Apr 10, 2013 at 12:25 PM, Sudip Chatterjee
<sudipanalyst at gmail.com> wrote:
> Hi Group,
>
> I have a question on Stringr package
>
> I have a table like this
> X Y
> ab su - di
> ac pi - tu
> ad tu - tu
>
> I want output like this
> X Y
> ab su
> ab di
> ac pi
> ac tu
> ad tu
> ad tu
>
> I am wondering if this operation can be done using stringr package (only)
I doubt it. stringr manipulates strings, you also want to reshape the
data. You can do
dat <- read.table(text = ' X Y
ab "su - di"
ac "pi - tu"
ad "tu - tu"', header=TRUE)
library(stringr)
with(dat, data.frame(X=rep(X, each=2), Y=unlist(strsplit(Y, split=" - "))))
but 'with', 'rep', 'data.frame' and 'unlist' are all in the base
package, not stringr.
Best,
Ista
> ?
>
> [[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.
More information about the R-help
mailing list