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, ]))
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))
+ 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
+ 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.
+ 1
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟
Thanks, understood it 👍
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?