BLUF:
How would the following be emulated using dplyr?
- Using the
ChickWeight dataset to practice.
- Primarily use
data.table
- Linear plots suggest 'missing' chicks.
- Wanted to create NA values in dataset to easily pull missing chicks.
library(data.table)
dt <- data.table(ChickWeight)
# Personal preference and not at all necessary; format variable names to lowercase
dt <- dt[, .(weight, time = Time, chick = Chick, diet = Diet)]
# Reshaping data to include NAs
dt_1 <- melt(
dcast(dt,
chick ~ time,
value.var = c("weight", "diet")),
id.vars = "chick",
measure.vars = patterns("^weight", "^diet"),
variable.name = "time",
value.name = c("weight", "diet")
)
# NA results
dt_1[is.na(weight)][order(chick, time)]
This was a fun little project and I'd love to learn more.