0
Good morning everyone, I have to do an exercise where I have to store 10 values typed repeatedly and say how many are negative and positive. I need to use the while command but don’t know how to store these values.
0
Good morning everyone, I have to do an exercise where I have to store 10 values typed repeatedly and say how many are negative and positive. I need to use the while command but don’t know how to store these values.
2
Try the following:
conta <- 0
x <- numeric(0)
while(conta < 10){
y <- scan(nmax = 1)
x <- c(x, y)
conta <- conta + 1
}
positivo <- x[x > 0]
negativo <- x[x < 0]
zero <- x[x == 0]
Now if you want to know how many are the positive, negative or zero (which is missing in the question?) just use length
.
length(positivo)
length(negativo)
length(zero)
To see them,
positivo
negativo
zero
Browser other questions tagged r
You are not signed in. Login or sign up in order to post.
you tried to solve this exercise somehow? put your code to exemplify
– Rafael Cunha