R: Sorting data.frame by a column and conditionally deleting of rows -
i've got data.frame in r sample data looks this: dat <- data.frame(name=c("name1","name1","name1","name1","name2","name2","name2","name2") , survey_year =c(1947,1958,1978,1987,1963,1991,2004,1993), reference_year=c(1934,1947,1974,1947,1944,1987,1993,1987), value=c(10,15,13,20,-2,7,12,-19)) dat name survey_year reference_year value 1 name1 1947 1934 10 2 name1 1958 1947 15 3 name1 1978 1974 13 4 name1 1987 1947 20 5 name2 1963 1944 -2 6 name2 1991 1987 7 7 name2 2004 1993 12 8 name2 1993 1987 -19 how sort first reference_year (from lowest highest): name survey_year reference_year value 1 name1 1947 1934 10 2 name1 1958 1947 15 3 name1 1987 ...