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.

3rd May 2022, 9:28 AM
Paneer Selvam
4 Respostas
+ 5
Paneer Selvam can you post your coding attempt?
3rd May 2022, 2:08 PM
Paul K Sadler
Paul K Sadler - avatar
+ 2
Yes, it's work.. Thank you. x <- mtcars[mtcars$am == 0, ] tapply(x$hp, x$cyl, max)
6th Jul 2022, 11:26 AM
Monika Raut
Monika Raut - avatar
+ 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 😊
18th Jun 2022, 8:20 PM
Paul K Sadler
Paul K Sadler - avatar
0
x <- mtcars[mtcars$am == 0, ] tapply(x[mtcars$cyl], mtcars$hp, max) What's wrong?
18th Jun 2022, 12:03 PM
Ikhwananda
Ikhwananda - avatar