Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

0-1 sequence without spaces

Tags:

r

spaces

sequence

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.

like image 591
andrekos Avatar asked May 30 '26 11:05

andrekos


1 Answers

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"
like image 155
Sharpie Avatar answered Jun 01 '26 02:06

Sharpie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!