tags:

views:

97

answers:

2

Spaces are redundant when reporting a binary sequence. This code

x <- '1 0 0 0 0 0 1 1 0 1 0 1 1 0 '
y<-gsub(' +', '', x)

does the job so I can copy and paste from R. How do I do the same for 0-1 sequences (and other one-digit data) in others formats, e.g.,

x <- c(1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0)

or

toString(x)

or whatever (for the sake of learning various options)? Thanks.

+9  A: 

For vectors, use the paste() function and specify the collapse argument:

x <- c(1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0)
paste( x, collapse = '' )

[1] "10000011010110"
Sharpie
+1  A: 

Have you tried

write.table(x,row.names=FALSE,col.names=FALSE,eol="\t")
1   0 0 0 0 0 1 1 0 1 0 1 1 0

By changing the eol (end of line) character, you can decide if and what separator to use.

Thrawn