0

# Anybody fix the code?

input <- readLines('stdin') x <- as.integer(input) data <- data.frame( "id" = c(1:10), "grade" = c(75, 26, 54, 90, 86, 93, 48, 71, 66, 99) ) student <- 0 for ( i in data\$grade){ while( i > x ){ student <- i + student i <- i + 1 print(length(student)) } }

17th Sep 2021, 2:54 AM
Amala Yakin
+ 8
input <- readLines('stdin') x <- as.integer(input) data <- data.frame( "id" = c(1:10), "grade" = c(75, 26, 54, 90, 86, 93, 48, 71, 66, 99) ) student <- 0 for ( i in data\$grade){ if ( i > x ){ student <- 1 + student } } print(student)
17th Sep 2021, 10:52 AM
Simba + 3
#try this for ( i in data\$grade){ if ( i > x ){ student <- 1 + student } } print(student)
17th Sep 2021, 8:35 AM
Simba + 2
8th Oct 2021, 9:49 AM
ANNA MONTSERRAT PARCERISAS
+ 2
#it is easier using subset and length function input <- readLines('stdin') x <- as.integer(input) data <- data.frame( "id" = c(1:10), "grade" = c(75, 26, 54, 90, 86, 93, 48, 71, 66, 99) ) student <- subset(data, data\$grade > x) print(length(student\$grade))
27th Mar 2022, 8:47 AM
Govinda Ghimeray + 1
You are using student as an integer. student needs to be a vector.
17th Sep 2021, 3:49 AM
Josiah Mathieu + 1
input <- readLines('stdin') x <- as.integer(input) data <- data.frame( "id" = c(1:10), "grade" = c(75, 26, 54, 90, 86, 93, 48, 71, 66, 99) ) i <- 1 student <- c() #try this for ( i in data\$grade){ if ( i > x ){ student <- +i } print((student)) } Now is right?
17th Sep 2021, 9:40 AM
Amala Yakin
0
You tells like this type Student<- c()
17th Sep 2021, 4:36 AM
Amala Yakin
0
This is a question You have a dataframe that includes grades of students. Your program needs to take a number as input, and output the number of students who have a grade greater than the given input. For example, for the input 89, the output should be:  3 as 3 students have grades greater than 89.
17th Sep 2021, 9:42 AM
Amala Yakin
0
You can either count the number of students whose grades meet the condition by adding up an integer or collect them and print the length of the resulting vector. Anyways, don't print inside the loop, but rather only once after the loop. Another approach on the task is subsetting and indexing (no loop). Maybe you would like to check this approach? https://www.sololearn.com/Discuss/2883382/?ref=app
17th Sep 2021, 10:34 AM
Lisa 0
No, its not correct
17th Sep 2021, 10:57 AM
Amala Yakin
0
input <- readLines('stdin') x <- as.integer(input) data <- data.frame( "id" = c(1:10), "grade" = c(75, 26, 54, 90, 86, 93, 48, 71, 66, 99) ) student <- 0 for ( i in data\$grade){ if ( i > x ){ student <- 1 + student } } print(student)
15th Dec 2021, 1:52 PM
Marvin Manaog 0
15th Dec 2021, 2:14 PM
Lisa 0
22nd Dec 2021, 9:12 PM
SULAIMAN L R A 0
input <- readLines('stdin') x <- as.integer(input) data <- data.frame( "id" = c(1:10), "grade" = c(75, 26, 54, 90, 86, 93, 48, 71, 66, 99) ) print(nrow(data[data\$grade>x,]))
28th Feb 2022, 11:11 PM
karthik v 0
i done like this input <- readLines('stdin') x <- as.integer(input) data <- data.frame( "id" = c(1:10), "grade" = c(75, 26, 54, 90, 86, 93, 48, 71, 66, 99) ) pass<-factor(c(data\$grade[data\$grade>x])) print(length(pass))
12th Jun 2022, 9:49 PM  