How attach a sequence of numbers to a string using `paste0` in R?

Viewed 925

I'm trying to a create labels for dotchart() below. Specifically, I'm trying to create Yes_1 to Yes_5 under group 1 in groups below, and create No_1 to No_15 under group 2 in groups below (see picture below).

Here is the R code I have tried with no success:(problem is in paste0())

y = rnorm(20)
groups = factor( rep(1:2, times = c(5, 15) ) )
dotchart(y, groups = groups, labels = c(paste0("Yes_",1:5), paste0("No_", 1:15))[groups])

enter image description here

2 Answers
Related