# Is there a way to map data from Binary format to Numerical numbers?

6 messages
Open this post in threaded view
|

## Is there a way to map data from Binary format to Numerical numbers?

 This post has NOT been accepted by the mailing list yet. Hi, Is there a way to map data from Binary format to Numerical numbers? example:I have text files, where each record consists of several items (9 items) 1, means item appear 0, means item absent 1,1,1,0,0,1,1,1,1 1,1,1,0,0,1,0,1,1 1,0,1,1,0,1,1,1,1 1,0,0,0,0,0,0,1,0 1,0,1,0,0,1,1,1,1 1,0,1,1,0,1,0,1,1 1,0,1,0,1,0,0,0,1 I want transform my data to numerical numbers in ascending order, such that when items is absent, i didn't print it, but keep increase the counter. for example, the above binary format will be: , 1,2,3,6,7,8,9 1,2,3,6,8,9 1,3,4,6,7,8,9 1,8, 1,3,6,7,8,9 1,3,4,5,7,8 1,3,5,9
Open this post in threaded view
|

## Re: Is there a way to map data from Binary format to Numerical numbers?

 This post has NOT been accepted by the mailing list yet. I found solution: A <- readLines(con <- file("1.txt")) mat<- as.matrix(read.table(text=A,header=FALSE,fill=TRUE)) b<-apply(!!mat ,1,which) capture.output(writeLines(unlist(lapply(b, paste, collapse=","))), file="num.txt") But the problem is, my file has 100k lines, and i got error: Error in !mat : invalid argument type
Open this post in threaded view
|

## Re: Is there a way to map data from Binary format to Numerical numbers?

 In reply to this post by memi Try indx <- which(!!mat, arr.ind=TRUE) v1 <-unname(sapply(split(indx[,2], indx[,1]),toString)) cat(paste(v1, collapse="\n"), sep="\n") 1, 2, 3, 6, 7, 8, 9 1, 2, 3, 6, 8, 9 1, 3, 4, 6, 7, 8, 9 1, 8 1, 3, 6, 7, 8, 9 1, 3, 4, 6, 8, 9 1, 3, 5, 9 A.K.     Hi, Is there a way to map data from Binary format to Numerical numbers? example: I have text files, where each record consists of several items (9 items) 1, means item appear 0, means item absent 1,1,1,0,0,1,1,1,1 1,1,1,0,0,1,0,1,1 1,0,1,1,0,1,1,1,1 1,0,0,0,0,0,0,1,0 1,0,1,0,0,1,1,1,1 1,0,1,1,0,1,0,1,1 1,0,1,0,1,0,0,0,1 I want transform my data to numerical numbers in ascending order, such that when items is absent, i didn't print it, but keep increase the counter. for example, the above binary format will be: , 1,2,3,6,7,8,9 1,2,3,6,8,9 1,3,4,6,7,8,9 1,8, 1,3,6,7,8,9 1,3,4,5,7,8 1,3,5,9 ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Is there a way to map data from Binary format to Numerical numbers?

 This post has NOT been accepted by the mailing list yet. Thank you so much, its work. when I tried this code on 100k lines with 9 col, I got the results, but not all of them, the number of lines become 90k instead of 100kA <- readLines(con <- file("Example21.txt")) mat1<- as.matrix(read.table(text=A,header=FALSE,fill=TRUE)) b<-apply(!!mat1,1,which) c<-matrix(b,nrow = 100000,ncol = 9) capture.output(writeLines(unlist(lapply(c, paste, collapse=" "))), file="NEWnum2.txt") but with your code, i got it correctly thank you so muchA <- readLines(con <- file("Example21.txt")) mat<- as.matrix(read.table(text=A,header=FALSE,fill=TRUE)) indx <- which(!!mat, arr.ind=TRUE) v1 <-unname(sapply(split(indx[,2], indx[,1]),toString)) capture.output(cat(paste(v1, collapse="\n"), sep="\n") , file="tonum.txt")