0

What's my wrong

I solved code project of section 3 but it seems doesn't work properly? 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) ) x <- (subset(data, grade> input)) print(length(x[,1]))

3rd Nov 2021, 8:45 PM
Mohammad Gheisari
Mohammad Gheisari - avatar
4 Respostas
+ 1
Greater than x NOT input x <- (subset(data, grade > x))
3rd Nov 2021, 9:58 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg but why not "input"? Works with "input" too.
3rd Nov 2021, 10:11 PM
Solo
Solo - avatar
+ 1
Vasiliy Both the value of 'grade' and 'x' are of type integer. This way works without implicit type conversion. At least I believe that is what the issue may be. IDK for sure yet, haven't fully tested.
3rd Nov 2021, 10:26 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Absolutely right! "input" is a string variable, so we convert it to an integer by assigning it to the variable x: x <- as.integer (input [1]) If you don't do this, then comparing a number with a string we will not get exactly what we expect.
4th Nov 2021, 1:56 AM
Solo
Solo - avatar