My data consists of frequency tables listed under each other for different models and scenario's (ie variables). I want to make selections of this database to make graphs for each subset.
Most of my variables are categorical and texts (eg weather, scenario). I couln't find a way to allow multiple values from a categorical variable (mostly %in% c()
is used for numbers). I tried the following:
ThisSelection <- subset (Hist, all_seeds==0 & weather == "normal" & scenario %in% c("intact","depauperate"))
which doesn't work and
ThisSelection <- subset (Hist, all_seeds==0 & scenario =="intact" | scenario =="depauperate")
which gives only "inatct" scenarios.
My apologies if the answer is simple here, I searched the web but couldn't find where I'm wrong, and I believe there must be an other way than turning string variable-values into numerical ones. I'm a starter in R...
Your first should work. Hesitate to suggest it but is your spelling of "depauperate" consistent (including case?):
Hist<-data.frame(all_seeds=0, weather=sample(c("normal","odd"),20,T),scenario=sample(c("intact","depauperate"),20,T))
ThisSelection <- subset (Hist, all_seeds==0 & weather == "normal" & scenario %in% c("intact","depauperate"))
ThisSelection
all_seeds weather scenario
1 0 normal intact
3 0 normal intact
4 0 normal intact
5 0 normal depauperate
6 0 normal intact
10 0 normal depauperate
14 0 normal intact
15 0 normal intact
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With