M. Bow
M. Bow

Reputation: 41

How to add multiple suffixes to a vector string

I am looking to add the suffixes "-r1i1p1_rcp45" and "-r1i1p1_rcp85" onto a character vector string, however I want the output to be the model.list values with suffixes on the end of every model.list value, with separate values for each suffix. This may be confusing, so....

My vector string is:

model.list <- c("ACCESS1-0", "ACCESS1-3", "bcc-csm1-1", "bcc-csm1-1-m")

And right now, my code to append these suffixes reads:

gcm<- paste(model.list, "-r1i1p1_rcp45", "-r1i1p1_rcp85", sep = "")

but the output (as expected) gives:

> gcm
[1] "ACCESS1-0-r1i1p1_rcp45-r1i1p1_rcp85"    "ACCESS1-3-r1i1p1_rcp45-
r1i1p1_rcp85"   
[3] "bcc-csm1-1-r1i1p1_rcp45-r1i1p1_rcp85"   "bcc-csm1-1-m-r1i1p1_rcp45-
r1i1p1_rcp85"

I want the output to look as follows:

> gcm
[1] "ACCESS1-0-r1i1p1_rcp45"    "ACCESS1-0-r1i1p1_rcp85"
[3] "ACCESS1-3-r1i1p1_rcp45"    "ACCESS1-3-r1i1p1_rcp85"
[5] "bcc-csm1-1-r1i1p1_rcp45"    "bcc-csm1-1-r1i1p1_rcp85"
[7] "bcc-csm1-1-m-r1i1p1_rcp45"    "bcc-csm1-1-m-r1i1p1_rcp85"

Upvotes: 2

Views: 1683

Answers (1)

Matt
Matt

Reputation: 994

You have to do them separately:

> model.list2=c(paste0(model.list, "-r1i1p1_rcp45"), paste0(model.list, "-r1i1p1_rcp85"))
> model.list2
[1] "ACCESS1-0-r1i1p1_rcp45"    "ACCESS1-3-r1i1p1_rcp45"    "bcc-csm1-1-r1i1p1_rcp45"   "bcc-csm1-1-m-r1i1p1_rcp45"
[5] "ACCESS1-0-r1i1p1_rcp85"    "ACCESS1-3-r1i1p1_rcp85"    "bcc-csm1-1-r1i1p1_rcp85"   "bcc-csm1-1-m-r1i1p1_rcp85"

Upvotes: 2

Related Questions