0
Can you help me solve this problem in R language
You need to understand how the number of cylinders affects the horsepower of a car. For that, you need to find the maximum hp value for each of the cyl values in the mtcars dataset, but only for the cars that have automatic transmission, meaning am is equal to 0. Use tapply to group the data and output the result.
4 Answers
+ 5
Paneer Selvam can you post your coding attempt?
+ 2
Yes, it's work.. Thank you.
x <- mtcars[mtcars$am == 0, ]
tapply(x$hp, x$cyl, max)
+ 1
Who's Me Paneer Selvam
Who's me so first issue is you load x with the filtered data, but then you use the unfiltered data in mtcars when you should use x. As in x$cyl. You are getting an error that refers to the "same length" this is because x, the filtered list, is shorter than the unfiltered mtcars.
So your first line loading x is fine. But the second line is a mix of x and mtcars. Also you have cyl and hp transposed...
tapply(x$hp, x$cyl, max)
Hope that helps š
0
x <- mtcars[mtcars$am == 0, ]
tapply(x[mtcars$cyl], mtcars$hp, max)
What's wrong?