I have a dataframe that looks like this and I try to generate the last column Searched
tibble::tribble( ~Group, ~Element, ~Searched,
"A", "aaa", NA,
"A", "bbb", NA,
"A", "ccc", NA,
"B", "aaa", TRUE,
"B", "bbb", TRUE,
"B", "ddd", FALSE,
"C", "aaa", TRUE,
"C", "bbb", TRUE,
"C", "ccc", FALSE )
I suppose I can find something with a combination of group_by
and lead/lag
but not sure how.
question from:
https://stackoverflow.com/questions/65952391/identify-elements-from-previous-group-in-r 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…