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.
Perhaps something like this: x <- c("110000", "001100", "001001") # Test data strsplit(x,"") # See what strsplit does do.call(rbind, strsplit(x,"")) # Now combine the list elements nicely. Incidentally, your question was grossly malformed, involving both incomplete data and that in a non-reproducible form. If you would be so kind as to use dput() [as suggested by the posting guide] to make a useful test data set next time, that'd be much appreciated. [And you could get help that is more tailed to your problem instead of my general-ish solution here] Michael On Sat, Jun 9, 2012 at 5:21 AM, efulas <ef_ulas at hotmail.com> wrote:> 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.
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.
Possibly Parallel Threads
- [TableGen] What to do if there are overlapping instruction patterns?
- generating Venn diagram with 6 sets
- I want to move the MySQL server out to another machine
- DO NOT REPLY [Bug 6545] New: when crashing, announce the last file that was correctly copied
- rnorm??