Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Trace back - find if a string value occurs before another specific string value - dplyr/R

$
0
0

I have a general problem in R. I wonder if there's a way to identify if a specific string value occurs after another specific string value within a group. The dataset is a time series. Each Group consist of 10 years.

I want something like the below, but instead of lag I wish to look at every year before " stringvalue1" within the group.

mutate(new_var = if_else(stringvar = "stringvalue1"& lag(stringvar) %in% c("stringvalue2", "stringvalue3"), "Match", "Not match"))

Help would be much appreciated!


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>