vendredi 5 janvier 2018

creating a new variable, base on multi-criteria

I am new in R, I am using Rstudio. I have a data set of mothly data from 2011-2100, which has 8 columns (year, month, sta1p, sta2t, sta1p,sta2t) where sta is the station number, and p and t are experiments.

I would like to get a box plot, base on the 3 periods: 20s(2011-2040),50s(2041-2070, 80s(2071-2100). Initially, I tried to create a new column (period). However, the new column just shows the first condition (20s).

a$period<-ifelse(a$Anyo>=2011 & Anyo<=2040,c("20s"),ifelse(a$Anyo>=2041 & Anyo<=2070,c("50s"),c("80s")))

How can I create a new column using 3 different criteria?

Thanking in advance.

Aucun commentaire:

Enregistrer un commentaire