I need to display name of the car which has max acceleration
# READING THE AUTO FILE
myfile=read.csv("Auto.csv")
#creating the matrix
mpg =c(myfile$mpg)
cylinders=c(myfile$cylinders)
displacement=c(myfile$displacement)
horsepower=c(myfile$horsepower)
weight=c(myfile$weight)
acceleration=c(myfile$acceleration)
year=c(myfile$year)
origin=c(myfile$origin)
name=c(myfile$name)
matrixAuto=matrix(c(mpg,cylinders,displacement,horsepower,weight,acceleration,year,origin),20,8)
rownames(matrixAuto)=c("chevrolet chevelle malibu","buick skylark 320","plymouth satellite","amc rebel sst",
"ford torino","ford galaxie 500","chevrolet impala","plymouth fury iii","pontiac catalina",
"amc ambassador dpl","dodge challenger se","plymouth 'cuda 340","chevrolet monte carlo",
"buick estate wagon (sw)","toyota corona mark ii","plymouth duster","amc hornet",
"ford maverick","datsun pl510","volkswagen 1131 deluxe sedan")
matrixAuto
colnames(matrixAuto)=c("mpg","cylinders","displacement","horsepower","weight","accelaration","year","origin")
#calculating max cylinders
maxCylinders=max(cylinders)==cylinders
rownames(matrixAuto[maxCylinders,])
But then I tried the same thing for calculating maximum acceleration and only a single value was returned using max function and when I tried using
maxAccelaration=max(acceleration)==acceleration
rownames(matrixAuto[maxAccelaration,])
NULL
value was returned. Can you explain me why do I get correct answers for mutliple max values whereas null value for a single max value using my code? Also How do i get the row name of the max acceleration? I am trying to get row name for max acceleration car which is the volkswagen 1131 deluxe sedan
Any help is appreciated.
my file using the dput() function is
structure(list(mpg = c(18L, 15L, 18L, 16L, 17L, 15L, 14L, 14L,
14L, 15L, 15L, 14L, 15L, 14L, 24L, 22L, 18L, 21L, 27L, 26L),
cylinders = c(8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 4L, 6L, 6L, 6L, 4L, 4L), displacement = c(307L,
350L, 318L, 304L, 302L, 429L, 454L, 440L, 455L, 390L, 383L,
340L, 400L, 455L, 113L, 198L, 199L, 200L, 97L, 97L), horsepower = c(130L,
165L, 150L, 150L, 140L, 198L, 220L, 215L, 225L, 190L, 170L,
160L, 150L, 225L, 95L, 95L, 97L, 85L, 88L, 46L), weight = c(3504L,
3693L, 3436L, 3433L, 3449L, 4341L, 4354L, 4312L, 4425L, 3850L,
3563L, 3609L, 3761L, 3086L, 2372L, 2833L, 2774L, 2587L, 2130L,
1835L), acceleration = c(12, 11.5, 11, 12, 10.5, 10, 9, 70.5,
10, 8.5, 10, 8, 9.5, 10, 15, 15.5, 15.5, 16, 14.5, 70.5),
year = c(70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L,
70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L, 70L), origin = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L,
1L, 1L, 3L, 2L), name = c("chevrolet chevelle malibu", "buick skylark 320",
"plymouth satellite", "amc rebel sst", "ford torino", "ford galaxie 500",
"chevrolet impala", "plymouth fury iii", "pontiac catalina",
"amc ambassador dpl", "dodge challenger se", "plymouth 'cuda 340",
"chevrolet monte carlo", "buick estate wagon (sw)", "toyota corona mark ii",
"plymouth duster", "amc hornet", "ford maverick", "datsun pl510",
"volkswagen 1131 deluxe sedan")), row.names = c(NA, 20L), class = "data.frame")