Month == JAN
is looking for two objects: Month
(found within tuPeru1naomit
) and JAN
(does not exist). I believe you intend to be looking for the value/string "JAN"
, so Month == "JAN"
.
The third argument to subset(..)
is select=
, a non-standard-eval column selector. In your call, though, it appears that you are using it for a second subsetting condition. You need to combine your conditionals with &
(logical AND) or |
(logical OR), I'll assume the first.
subset(tuPeru1naomit, Month == "JAN" & YEAR == 1980)
# Month YEAR LONG LAT Temp
# 1 JAN 1980 -39.9 -89.5 17.5498
# 2 JAN 1980 -39.5 -89.5 17.8718
# 3 JAN 1980 -39.2 -89.5 18.1983
# 4 JAN 1980 -38.9 -89.5 18.5264
# 5 JAN 1980 -38.5 -89.5 18.8529
# 6 JAN 1980 -38.2 -89.5 19.1596
If you're curious about the use of the select=
argument, all of the following are feasible options:
# range of columns
subset(tuPeru1naomit, Month == "JAN" & YEAR == 1980, select = LONG:Temp)
# individual columns, using non-standard-evaluation
subset(tuPeru1naomit, Month == "JAN" & YEAR == 1980, select = c(Month, LONG))
# same, using standard-evaluation (strings)
subset(tuPeru1naomit, Month == "JAN" & YEAR == 1980, select = c("Month", "LONG"))
# all except the specified columns
subset(tuPeru1naomit, Month == "JAN" & YEAR == 1980, select = -c(LONG))