0

Anybody fix the code?

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) ) 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
17 Antworten
+ 9
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) ) student <- 0 for ( i in data$grade){ if ( i > x ){ student <- 1 + student } } print(student)
17th Sep 2021, 10:52 AM
Simba
Simba - avatar
+ 3
#try this for ( i in data$grade){ if ( i > x ){ student <- 1 + student } } print(student)
17th Sep 2021, 8:35 AM
Simba
Simba - avatar
+ 2
I've just filtered the data and used length: print(length(data$grade[data$grade>x]))
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[1]) 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
Govinda Ghimeray - avatar
+ 1
You are using student as an integer. student needs to be a vector.
17th Sep 2021, 3:49 AM
Josiah Mathieu
Josiah Mathieu - avatar
+ 1
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) ) 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: [1] 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
Lisa - avatar
0
No, its not correct
17th Sep 2021, 10:57 AM
Amala Yakin
0
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) ) student <- 0 for ( i in data$grade){ if ( i > x ){ student <- 1 + student } } print(student)
15th Dec 2021, 1:52 PM
Marvin Manaog
Marvin Manaog - avatar
0
Please don't post 'answer-only' comments with ready-made code and without any explanation.
15th Dec 2021, 2:14 PM
Lisa
Lisa - avatar
0
lra <- subset(data, grade>x) print(length(lra$grade))
22nd Dec 2021, 9:12 PM
SULAIMAN L R A
SULAIMAN L R A - avatar
0
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(nrow(data[data$grade>x,]))
28th Feb 2022, 11:11 PM
karthik v
karthik v - avatar
0
i done like this 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) ) pass<-factor(c(data$grade[data$grade>x])) print(length(pass))
12th Jun 2022, 9:49 PM
M M U Lahiru Maduranga
M M U Lahiru Maduranga - avatar
0
#try this 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) ) bigger <- data$grade[x<data$grade] print(length(bigger))
14th May 2023, 1:37 AM
Phirun Chhay
- 1
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) ) student <- 0 for ( i in data$grade){ if ( i > x ){ student <- 1 + student } } print(student)
16th Dec 2021, 3:20 PM
Mirmahmud Ilyosov
Mirmahmud Ilyosov - avatar