Please help me out. I have been stuck for a long time. I am an R beginner, and I want to know how to perform operations on data frame elements using multiple indices e.g. firms and time as in the below case elegantly? I want to perform some typical operations e.g year-wise mean on some other variables for each firm, and here is an example: I am want to calculate year-wise mean from daily data of variables A and F for all firms in the dataset. This is my dataset. I have used dplyr and hydroTSM packages. Following is my code:
MeanA<- df %>% select(Firm, Date, A,) %>% group_by(Firm) %>% do(daily2annual(., A, FUN=mean, na.rm = TRUE, out.fmt="%Y", dates = 2))
It returns the following error:
Error in eval(expr, envir, enclos) : argument is missing, with no default
I have also tried the data.table package with adding an additional Year column. Code:
MeanA <- df[ , A, by = "Firm" & "Year"]
Result:
Error in `[.data.frame`(df, , A, by = "Firm" & "Year") : unused argument(by = "Firm" & "Year")
Please suggest a way out (with or without dplyr). The table of means, as well as other year-wise values I would be calculating, is input for panel regression analysis using plm package. Thanks in advance.