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
toStri开发者_开发问答ng(x)
or whatever (for the sake of learning various options)? Thanks.
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"
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.
精彩评论