I am very new to this, and most guides either don't return the desired result or go right over my head. group_by followed by summarise allows me to compute mean / median from these rows, but the returning table does not have a reduced number of rows.
Sample of my data attached.
structure(list(S = c("Balaclava", "Balaclava", "Carnegie", "Carnegie"), Rn = c(3, 2, 2, 2), T = c("h", "u", "t", "u" ), P = c(1690000, 540000, 795000, 6e+05), M = c("S", "VB", "S", "SP"), D = c(6.6, 6.6, 11.4, 11.4), BR = c(3, 2, 2, 2), BT = c(2, 1, 2, 1), C = c(2, 1, 1, 1), L = c(339, 483, 133, 73), BA = c(159, 51, 104, 61), YB = c(1890, 1970, 2009, 1970)), row.names = c(NA, -4L), class = c("tbl_df", "tbl", "data.frame"))
data2 <- data1 %>%
group_by(S) %>%
summarize(MRn = median(Rn),
APA = mean(P),
AAA = mean(BA),
AAL = mean(L), YB) %>%
arrange(desc(MRn))
data2
I want to group rows which have column S in common, and generate mean / median values for columns to the right of S, into one row per S entry. The resulting "groups" need to be used towards plotting.