Thank You, it worked! But I noticed you used brackets instead of parenthesis for dat2 <- dat1[Solar.R > 150 & Wind > 10] Is there any particular reason why?
The general data.table syntax is as follows: DT[i, j, by, ...] which means: “Take DT, subset rows using i , then calculate j , grouped by by ” with possible extra options ... . It allows to combine several operations in a very concise and consistent expression.
The syntax of dplyr is based on key verbs corresponding to the most common operations: filter() , arrange() , select() , mutate() , summarise() , … These functions can be combine with group_by() to aggregate data ‘by group’ and with a bunch of helper functions. It is a ‘do one thing at a time’ approach, chaining together functions dedicated to a specific task.
So the basic answer for the brackets is that this in how R identifies what dataset and what subsets of data are to be used. You can think of it as somewhat the equivalent of
airquality %>%
in the tidyverse.
And so
airquality %>%
filter(Solar.R > 150, Wind > 10)
is the equivalent of
dat1[Solar.R > 150 & Wind > 10]
The really nice thing is that we can use most or all base and tidyverse commands within data.table so we get the best of both worlds.