[R] Stringr Package

arun smartpink111 at yahoo.com
Wed Apr 10 19:24:50 CEST 2013


Hi,
Assuming that this is a data.frame.
dat1<-read.table(text="
X,Y
ab,su-di
ac,pi-tu
ad,tu-tu
",sep=",",header=TRUE,stringsAsFactors=FALSE)
library(stringr)
dat2<-data.frame(X=rep(dat1$X,each=2),Y= unlist(str_split(dat1$Y,"-")),stringsAsFactors=FALSE)
 dat2
#   X  Y
#1 ab su
#2 ab di
#3 ac pi
#4 ac tu
#5 ad tu
#6 ad tu
A.K.





----- Original Message -----
From: Sudip Chatterjee <sudipanalyst at gmail.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Wednesday, April 10, 2013 12:25 PM
Subject: [R] Stringr Package

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)
?

    [[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