all. I’ve trying to perform correlation, grouping by two variables, as ideally the data would be present in the same data and be of the same type.
Let’s say I have the following dataframe:
df <- data.frame(
ID = c(1,1,1,2,2,2,3,3),
type = c(1,1,1,1,1,1,2,2),
date = as.Date('2023-01-01', '2023-02-01', '2023-03-01','2023-02-01', '2023-03-01','2023-04-01',
'2023-01-01', '2023-02-01', format = '%Y-%m-%d'),
revenue = c(1,3,2,4,5,1,2,3)
)
Is there any way to get the correlation between the ID’s and revenues grouping by Type/Date?
I tried to use pivot_wider(names_from = ID, values_from = revenue
and then use summarise, but it didn’t work out.
Ideally, I would have some table with every ID in the row and column, and the correlation coefficient in the cell.
Thanks in advance!
annyeong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.