R: Function “diff” over various groups
问题 While searching for a solution to my problem I found this thread: Function "diff" over various groups in R. I've got a very similar question so I'll just work with the example there. This is what my desired output should look like: name class year diff 1 a c1 2009 NA 2 a c1 2010 67 3 b c1 2009 NA 4 b c1 2010 20 I have two variables which form subgroups - class and name. So I want to compare only the values which have the same name and class. I also want to have the differences from 2009 to