Reputation:
I have a vector in R:
x <- c(25, 53, 37, 84, 883, 55, 55, 173, 34, 12, 30, 214, 25, 109, 277, 228, NA, 89, 133, 213, 309, 232, 67, 49, 75, 48, 34, 160, 101, NA, 12, 49, 40, 304, 18, 139, 371, 211, 17, 31, 111, 133, 279, 29, 50, 13, 94, 60, 24, NA, 211, 140, 26, 44, 72, 386, 19, 188, 986, 51, 52, 80, 108, 466, 515, 127)
When I print that vector, it looks like this:
> x
[1] 25 53 37 84 883 55 55 173 34 12 30 214 25 109 277 228 NA
[18] 89 133 213 309 232 67 49 75 48 34 160 101 NA 12 49 40 304
[35] 18 139 371 211 17 31 111 133 279 29 50 13 94 60 24 NA 211
[52] 140 26 44 72 386 19 188 986 51 52 80 108 466 515 127
This makes it a hassle to copy values into a new vector.
How can I tell R to print the vector in R's own "vector notation"?
Like this (fake code), with or without the c( )
:
> print.as.vector(x)
c(25, 53, 37, 84, 883, 55, 55, 173, 34, 12, 30, 214, 25, 109, 277, 228, NA, 89, 133, 213, 309, 232, 67, 49, 75, 48, 34, 160, 101, NA, 12, 49, 40, 304, 18, 139, 371, 211, 17, 31, 111, 133, 279, 29, 50, 13, 94, 60, 24, NA, 211, 140, 26, 44, 72, 386, 19, 188, 986, 51, 52, 80, 108, 466, 515, 127)
I believe there is a special command for this, but I forgot it.
Upvotes: 5
Views: 1339
Reputation:
You can use function dput()
for this purpose. With your example, it gives:
dput(x)
# c(25, 53, 37, 84, 883, 55, 55, 173, 34, 12, 30, 214, 25, 109,
# 277, 228, NA, 89, 133, 213, 309, 232, 67, 49, 75, 48, 34, 160,
# 101, NA, 12, 49, 40, 304, 18, 139, 371, 211, 17, 31, 111, 133,
# 279, 29, 50, 13, 94, 60, 24, NA, 211, 140, 26, 44, 72, 386, 19,
# 188, 986, 51, 52, 80, 108, 466, 515, 127)
Upvotes: 6