Rcheologist
Rcheologist

Reputation: 303

Column created not recognised in R

I am working on a dataset that has included temperature and three environmental conditions. Those conditions are based on the device ID which was placed in that environmental condition to measure data. Using R, I created the new column EnvCond using mutate and it does appear in the new dataset, as in the code below:

IoT_telemetry_data <- mutate(IoT_telemetry_data, 
    EnvCond = ifelse(device=="00:0f:00:70:91:0a", "Stable Cooler Humid", 
              ifelse(device=="1c:bf:ce:15:ec:4d", "Variable Temperature Humid", 
                    "Stable Warm Dry")))

The screenshot below shows the column added into the same table: enter image description here However, I am trying to use this new column to create three different variables; each one of them should contain the temperature measured for each of the three conditions. I tried using select to create one of those variables, as in the code below:

#Table that has only the temperature for Stable Cooler Humid environment:
TempSCH <- select(IoT_telemetry_data, temp, where(EnvCond == "Stable Cooler Humid")) 

I get an error that EnvCond isn't found. I tried using the pipe operator %>% from the ggplot library to attach that variable to the data, and I am using attach(data) in my code as well, but I still get the error. Is the condition inside select written incorrectly?

Upvotes: 0

Views: 209

Answers (1)

stevec
stevec

Reputation: 52658

Try filtering like this instead

library(tidyverse)

IoT_telemetry_data %>% 
  filter(EnvCond == "Stable Cooler Humid")

e.g. this should give you what you're after

IoT_telemetry_data %>% 
  select(temp, EnvCond) %>% 
  filter(EnvCond == "Stable Cooler Humid")

Upvotes: 1

Related Questions