mercredi 13 juin 2018

Create vector through ifelse in R

I've got two values in my global environment one is called week and one is called rest.

Week can be any number from 01 to 52

While rest can be 2018, 2017, 2016.

I'm creating an ifelse statement that if the week is equal to 3 then the vector output needs to got to year 2017 and week 52.

This is the code I use to create the vector:

c(paste0(rest, seq(week, by = -1, length.out=3)),paste0(rest,52))

Which if we're on week 03 of 2017 will give the output:

[1] "Priority_20173"  "Priority_20172"  "Priority_20171"  "Priority_201752"

I want to add this into an ifelse statement as rest and week will change, I try and use the below code:

   ifelse((rest %in% c("Priority_2018", "Priority_2017","Priority_2016") & week ==3), c(paste0(rest, seq(week, by = -1, length.out=3)),paste0(rest,52)),0)`

But this only outputs:

[1] "Priority_20173"

Please let me know if you need any more information from me.

Aucun commentaire:

Enregistrer un commentaire