I have a dataframe with one column containing factors in a sequence of variable lengths and other columns containing values. How can I extract just the last row values for each factor?
df <- data.frame(x=c("a","a","a","a","b","b","c","c","c","c","c","d","d","d","e","f","f","f","f","g","g"),y=c(diffinv(rnorm(20))),z=c(diffinv(rnorm(20)))) df
Thank you for your help.
有很多选择.这不是最有效的,但它不需要包:
aggregate(. ~ x, df, tail, n = 1)