How do I find the average of a note? In R

Asked

Viewed 128 times

2

I need to add two typed notes to find the final R average (Nota1 + 2*Nota2)/3 but I don’t know how it makes the final calculation for the script to work without error

print("Escreva seu nome") 

W<-scan(what="character",nmax=1)

print("Qual a nota1?")

X<-scan(what="character",nmax=1)

X<-as.numeric(X)

print("Qual a nota2?")

Y<-scan(what="character",nmax=1)

Y<-as.numeric(Y)

Code line I don’t know.

if (Z<6) {print("Faça a G3.")} else {print("Aprovado.")}

RGui
  • 1

    Is not Z <- (Nota1 + 2*Nota2)/3 even before instruction if?

1 answer

2

To make the arithmetic mean in R we use the function mean(c[x]) which receives a list of numbers. But in your case you would have to do something like:

// Para X = 10 e Y = 20
Z <- (X + 2*Y)/3

The result will be: > [1] 16.66667

  • Yes, I did so from the beginning and the following appeared: Error in 2*Y : non-numerical argument for binary operator

  • 2

    @Carloswinter This error seems to be because in scan is not necessary what="character". Suffice X<-scan(nmax=1), and X is immediately of class numeric. The same for Y.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.