0

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.

  • 1
    See `help("cut")`. – Roland Jan 05 '18 at 11:36
  • First, see https://stackoverflow.com/help/mcve for producing a re-producible example. Secondly, in every second comparison, you are missing `a$`, which might be causing you an issue. Lastly, in your case, you might be able to simplify it to `ifelse(a$Anyo > 2070, '80s', ifelse(a$Anyo < 2041, '20s', '50s'))`. – MrGumble Jan 05 '18 at 11:41

0 Answers0