Reputation: 117
I need to write a script in R (Rstudio) that produces a new table, with 6 rows, that aggregates the vehicle types in cars dataset. In the first field will be the type of vehicle (sports car, SUV, Wagon, Minivan, Pickup, regular), (regular, this is when everyone is zero (, and then there are the averages per value for each type of vehicle.
The table should look like this :
Type | Wheel base | Weight | HWY MPG | city MPG | HP | Cyl | Engine size | Dealer cost | Retail price |
---|---|---|---|---|---|---|---|---|---|
Regular | |||||||||
Sport car | |||||||||
... |
A photo of the file (cars dataset) is mentioned here :
Upvotes: 0
Views: 45
Reputation: 20454
It would be much easier to answer this if you posted a reproducible example.
However this should work:
library(dplyr)
cars %>%
group_by(Type) %>%
mutate(across(`Wheel base`:`Retail price`, mean))
Upvotes: 0