[R] Splitting of Single value data into Multiple columns
arun
smartpink111 at yahoo.com
Fri Mar 14 15:32:09 CET 2014
Hi,
You could use ?strsplit()
dat <- read.table(text="'Column 1'
'AAA--> BBB'
'CCC--> DDD'",sep="",header=TRUE,check.names=FALSE,stringsAsFactors=FALSE)
dat1 <- setNames(as.data.frame(do.call(rbind,strsplit(dat[,1],"--> ")),stringsAsFactors=FALSE),paste("Column", 1:2))
dat1
# Column 1 Column 2
#1 AAA BBB
#2 CCC DDD
#or
dat2 <- setNames(read.table(text=gsub("[^[:alnum:]]+"," ",dat[,1]),sep="",header=FALSE,stringsAsFactors=FALSE),paste("Column", 1:2))
identical(dat1,dat2)
#[1] TRUE
A.K.
Hi All,
I am using Association Algorithm in RStudio.
I am facing a situation, where I need to Split the Single column value into Two column values.
Eg:
Column 1 Column 1 Column 2
AAA--> BBB AAA BBB
CCC--> DDD into CCC DDD
Can anyone help me in this ?
Thanks,
Praveen
More information about the R-help
mailing list