[R] Reshaping columns
arun
smartpink111 at yahoo.com
Sat Jun 9 21:46:31 CEST 2012
Hi,
Try this:
dat1<- read.table(text="
V1 V2
8098 110000
9099 001100
0023 110011
6545 111111
",sep="",colClasses=c(V1="character",V2="character"),header=TRUE)
dat2<-as.data.frame(apply(dat1,2,FUN=function(x){do.call(rbind,strsplit(x,""))})$V2)
dat2<-data.frame(V1=dat1$V1,dat2)
names(dat2)<-c("V1",LETTERS[1:6])
> dat2
V1 A B C D E F
1 8098 1 1 0 0 0 0
2 9099 0 0 1 1 0 0
3 0023 1 1 0 0 1 1
4 6545 1 1 1 1 1 1
A.K.
----- Original Message -----
From: efulas <ef_ulas at hotmail.com>
To: r-help at r-project.org
Cc:
Sent: Saturday, June 9, 2012 6:21 AM
Subject: [R] Reshaping columns
Dear all,
I have a data frame with 2 columns and 102500 rows. The data looks like
below
V1 V2
8098 110000.......
9099 001100.......
0023 110011.......
6545 111111.......
. .
. .
. .
. .
. .
I want to split the colums like this ;
V1 V2 V3 V4 V5 V6 v7
8098 1 1 0 0 0 0 ......
9099 0 0 1 1 0 0 .......
0023 1 1 0 0 1 1 .......
6545 1 1 1 1 1 1 .......
. . . . . . .
. .
. .
. .
. .
Is there anyway to do this in R.
Many Thanks
--
View this message in context: http://r.789695.n4.nabble.com/Reshaping-columns-tp4632875.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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