r - How do I get rid of the space at the end of a word in paste0 function? -


i have following code:

canada <- c(50, 50, 50) korea <- c(70, 70, 70) brazil <- c(100, 100, 100) fruit <- rbind(canada, korea, brazil) colnames(fruit) <- c("apple", "orange", "banana") 

i want this:

there 50 thousand farms in canada. 

this tried:

one <- function(x){   x <- tolower(x) # assuming row names in lower case   myrow <- fruit[x,]   country <- paste0(tools::totitlecase(x))    count <- sapply(seq_along(myrow),                    function(x, n, i){paste0(x)},                   x=myrow[1], n=names(myrow))   count[length(count)] <- paste0(count[length(count)])   count <- paste0(count[1])    cat("there are", count, "thousand farms in", country, ".") } cat(one("canada")) 

but, get:

there 50 thousand farms in canada . 

i need keep code i've demonstrated here. far, tried paste function, know paste0 should using getting rid of space @ end. appreciated.

use paste0 on string parts instead of counts. , write spaces need manually. this:

one <- function(x){   x <- tolower(x) # assuming row names in lower case   myrow <- fruit[x,]   country <- paste0(tools::totitlecase(x))    count <- sapply(seq_along(myrow),                    function(x, n, i){paste0(x)},                   x=myrow[1], n=names(myrow))   count[length(count)] <- paste0(count[length(count)])   count <- count[1]    cat(paste0("there ", count, " thousand farms in ", country, ".")) } one("canada") 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -