I created a data frame in longformat which has 5 variables( company name, key item, country of origin, year and value) What I want to do is create a table with the means of the values of one key item for each year. Here is what I managed so far:
for(i in dat$Year) {
dat[dat$KeyItem == "Total Assets" & dat$Year == i, ]
FUN1 <- mean(dat$Value, na.rm = TRUE)
}
I have hardly any experience in R and I am sorry if this question is too easy.
Thank you guys in advance for your help.
As you do not share your data, it is a little hard to judge what you want exactly. Probably, you want to use
ddplyfrom theplyrpackage:If your dataset becomes really big, you might opt to teach yourself the
data.tablepackage which is blisteringly fast in these cases. For medium sized datsets,ddplymight also be slower, but is fast enough.