 Anybody fix the code? | Sololearn: Learn to code for FREE!

-1

# 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)) } }

+2

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?

+1

You are using student as an integer. student needs to be a vector.

+1

#try this for ( i in data\$grade){ if ( i > x ){ student <- 1 + student } } print(student)

+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) ) student <- 0 for ( i in data\$grade){ if ( i > x ){ student <- 1 + student } } print(student)

+1

0

You tells like this type Student<- c()

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.

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

0