I have the following data in long format:
testdf <- tibble(
name = c(rep("john", 4), rep("joe", 2)),
rep = c(1, 1, 2, 2, 1, 1),
field = rep(c("pet", "age"), 3),
value = c("dog", "young", "cat", "old", "fish", "young")
)
For each named person (John and Joe), I want to summarise EACH of their pets:
For some reason I can't seem to deal with the repeating events/pets in "John" data.
If I filter just for Joe (only has one pet), the code works.
Any help much appreciated...
testdf %>%
group_by(name, rep) %>%
# filter(name == "joe") %>% # when I filter only for Joe, the code works
summarise(
about = paste0(
"The pet is a: ", .[field == "pet", "value"], " and it is ", .[field == "age", "value"]
)
)