Reputation: 11
Is there any alternative solution for the question?
Create a Data Table using the R built-in dataset mtcars
Find the average-weight(wt
) & average horse-power(hp
) of all cars with a mileage above 15 mpg, grouped by number of cylinders(cyl
) and carburettors(carb
).
s<-data.table(mtcars)
s[mpg>15,.(mean(wt),mean(hp)),by=.(cyl,carb)]
Upvotes: 0
Views: 1231
Reputation: 11
#If is for Fresco you need to add the library
library(data.table)
s<-data.table(mtcars)
s[mpg>15,.(mean(wt),mean(hp)),by=.(cyl,carb)]
Upvotes: 1
Reputation: 1471
A dpylr
solution would be:
require(dplyr)
as_data_frame(mtcars) %>%
filter(mpg > 15) %>%
group_by(cyl, carb) %>%
summarise(mean_wt = mean(wt),
mean_hb = mean(hp))
Upvotes: 0