Hi, Just noticed that there is space before and after the "-" dat1 <- read.table(text = ' X Y ab "su - di" ac "pi - tu" ad "tu - tu"', header=TRUE,stringsAsFactors=FALSE)
library(stringr) Y<-str_trim(unlist(str_split(dat$Y,"-")),side="both") X<-unlist(str_split(str_trim(str_dup(str_pad(dat1$X,width=3,side="right"),2))," ")) data.frame(X,Y,stringsAsFactors=FALSE) # 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: arun <smartpink...@yahoo.com> To: Sudip Chatterjee <sudipanal...@gmail.com> Cc: R help <r-help@r-project.org> Sent: Wednesday, April 10, 2013 1:24 PM Subject: Re: [R] Stringr Package 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 <sudipanal...@gmail.com> To: R help <r-help@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@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. ______________________________________________ R-help@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.