I have a following dataframe:
brand <- as_factor(“ford”, “audi”, “ford”, “audi”)
int1 <- c(2, 3, 4, 1)
int2 <- c(5, 6, 7, 1)
int3 <- c(1, 0, 7, 8)
df <- data.frame(brand, int1, int2, int3)
I want to receive a table per factor and sum for each numeric value as this:
For the moment I know how to do 3 separate tables:
bybrand <- tapply(df$int1, df$brand, FUN=sum)
bybrand <- tapply(df$int2, df$brand, FUN=sum)
bybrand <- tapply(df$int3, df$brand, FUN=sum)