this is my first post on this website so - sorry for any mistakes.
Given a data frame
xyz <- data.frame(GEO=c("Belgium", "Belgium", "Belgium", "Germany", "Germany", "Germany", "Italy", "Italy", "Italy"),
year=c(2008, 2009, 2010, 2008, 2009, 2010, 2008, 2009, 2010),
median=c(10.3, 45.2, 34.2, 67.8, 68.7, 69.9, 53.2, 43.2, 33.3),
imigration=c(10.2, 45.2, 47.4, 33.3, 44.4, 55.5, 21.5, 76.5, 78.4))
All I want to do is to count avg index of change for median and imigration.
index=(x[n]/x[1])^(1/(n-1))
I tried a lot of solutions but I couldn't find the good one. This is my code - maybe you will use this to help me.
First:
groupColumns = c("GEO","year")
dataColumns = c("median", "imigration")
index_median = ddply(mediana2, groupColumns, function(x) x[c((nrow(x)/x[1])^(1/nrow(x)-1)), ])
head(index_median)
Second:
xyz_index <- aggregate(xyz$median, xyz$imigration by=list(Category=xyz$"GEO/TIME"), FUN=median$index_median[nrow(median)]/median[1])^(1/(nrow(median)-1))
I want to get avg index of change for median and imigration (index_median, index_imigration) for every country (Belgium, Germany, Italy). Something like that (numbers are fake):
GEO index_median index_imigration
1 Germany 2.3 1.3
2 Italy 1.6 1.6
3 Belgium 1.2 2.0
Thank you very much!