jeudi 27 septembre 2018

Base R ifelse test for a span of temperature values

I am aware that this question has been asked for other cases before, but none of the answers matched my case well. I have been trying hard but didn´t get it working for my code. I believe that there is a simple solution and appreciate your help.

My Data looks like that:

start <- as.POSIXct("2018-05-18 00:00")
tseq <- seq(from = start, length.out = 1440, by = "10 mins")
Measurings <- data.frame(
  Time = tseq,
  Temp = sample(10:37,1440, replace = TRUE, set.seed(seed = 10)),
  Variable1 = sample(1:200,1440, replace = TRUE, set.seed(seed = 187)),
  Variable2 = sample(300:800,1440, replace = TRUE, set.seed(seed = 333))
)

Measurings$heat25 <- ifelse(Measurings$Temp >= 25 ,"summer", "normal")
Measurings$heat30 <- ifelse(Measurings$Temp > 30 ,"heat", "normal")

This works, and I need the Columns for choosing my data based on temperature values. Now I need a new column indicating wether the temperature is between 25 °C and 30° C. I expected to be able to combine test arguments like that:

Measurings$summer <- ifelse(Measurings$Temp >= 25 && < 30, "summer", "rest"))

But I get an error.

How can I simply add a new column indicating if Temp is between 25°C and 30°C?

Thanks for helping!

Aucun commentaire:

Enregistrer un commentaire