Suppose I have this named vector:
> foo = setNames(c("one", "two"), c(1, 2))
> foo
1 2
"one" "two"
> names(foo)
[1] "1" "2"
> foo
1 2
"one" "two"
What is the easiest way to print the following:
1: one, 2: two
I just want it for debugging.
Could be with or without quotes, I'm not picky.
I've got this, but it seems very chatty:
the_vec = c()
for (idx in 1:length(foo)) {
the_vec = c(the_vec, paste(idx, ":", foo[idx], sep=""))
}
paste(the_vec, collapse=", ")
output:
[1] "1:one, 2:two"
paste(names(foo), foo, sep = ":", collapse = ",")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With