I have a dataset that looks something like this:
name = c("john", "john", "john", "alex","alex", "tim", "tim", "tim", "ralph", "ralph")
year = c(2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012, 2014, 2016)
my_data = data.frame(name, year)
name year
1 john 2010
2 john 2011
3 john 2012
4 alex 2011
5 alex 2012
6 tim 2010
7 tim 2011
8 tim 2012
9 ralph 2014
10 ralph 2016
I am trying to count the "number of rows with at least one missing (i.e. non-consecutive) year", for example:
# sample output
year count
1 2014, 2016 1
In a previous question (Counting Number of Unique Column Values Per Group), I received an answer - but when I tried to apply this answer, I got the following error:
agg <- aggregate(year ~ name, my_data, c)
agg <- agg$year[sapply(agg$year, \(y) any(diff(y) != 1))]
as.data.frame(table(sapply(agg, paste, collapse = ", ")))
Error: unexpected input .... " ... \"
I think this error might be due to the fact that I am using an older version of R.
Does anyone know if an alternate symbol can be used to replace "" in R that is supported by older versions of R?
Thanks!