0

Can anyone tell what is the right code for 'grade analysis' problem in R. Please point out the mistake I've made in mine, thanks

input <- readLines('stdin') x <- as.integer(input[1]) data <- data.frame( "id" = c(1:10), "grade" = c(75, 26, 54, 90, 86, 93, 48, 71, 66, 99) ) print(length(data[data$grade>x, ]))

11th Sep 2021, 8:09 AM
Pradnya Meshram
Pradnya Meshram - avatar
5 ответов
+ 2
Pradnya Meshram first store data[data$grade > x, ] in a variable like y then get length of grade like print (length(y$grade))
11th Sep 2021, 8:17 AM
A͢J
A͢J - avatar
+ 2
You could just use nrow() instead if length() nrow() is for the number of rows in a dataframe length() is for the number of elements in a vector
11th Sep 2021, 8:40 AM
Lisa
Lisa - avatar
+ 1
Pradnya Meshram Because we want number of rows length not columns. You were getting columns length which is 2. Just print filtered data not length and see the test cases result. You will know why.
11th Sep 2021, 8:23 AM
A͢J
A͢J - avatar
+ 1
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Thanks, understood it 👍
11th Sep 2021, 8:25 AM
Pradnya Meshram
Pradnya Meshram - avatar
0
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ I tried that but didn't include $grade in the print statement. Can you explain why that's needed?
11th Sep 2021, 8:19 AM
Pradnya Meshram
Pradnya Meshram - avatar