I am using apply to generate strings from a data frame.
For example:
df2 <- data.frame(a=c(1:3), b=c(9:11))
apply(df2, 1, function(row) paste0("hello", row['a']))
apply(df2, 1, function(row) paste0("hello", row['b']))
works as I would expect and generates
[1] "hello1" "hello2" "hello3"
[1] "hello9" "hello10" "hello11"
However, if I have
df <- data.frame(a=c(1:3), b=c(9:11), c=c("1", "2", "3"))
apply(df, 1, function(row) paste0("hello", row['a']))
apply(df, 1, function(row) paste0("hello", row['b']))
the output is
[1] "hello1" "hello2" "hello3"
[1] "hello 9" "hello10" "hello11"
Can any one please explain why I get a padded space to make all the strings the same length in the second case? I can work around the problem using gsub, but I would like to have a better understanding of why this happens