r - Strange interaction of apply with collapse argument to paste -
wanted clarification on unintended output got trying apply paste function collapse argument across data frame. can't find in documentation explicitly suggest should happen, though might missing something.
reproducible example:
data <- data.frame(a = 8:11, b = c('a', 'b', 'c', 'd'), stringsasfactors = false) apply(data, 1, paste, collapse = ' ') desired output:
'8 a', '9 b', '10 c', '11 d' actual output:
' 8 a', ' 9 b', '10 c', '11 d' it seems in case r padding out digits of numbered vectors empty space. not happen if try same paste call outside of apply:
paste(data[1, ], collapse = ' ') result:
'8 a'
Comments
Post a Comment