Help with Rcode! (University work)


We had been assigned to do laboratory work with R studio at University.

I need help. I had imported data to my R studio.

First exercise is to choose 3 variables from many. I did this with:
choose3variables<-select(name, Variable1:Variable2:Variable3) .

The second task is to class these variables. I did it with Variable1<-class(Variable1) and for the others too

The third task is to count mean, median, max, min, var, sd. Now these functions does not work and here are errors:

When I write mean(Variable1) it shows the:

[1] NA
Warning message:
In mean.default(Variable1) :
argument is not numeric or logical: returning NA

When I write median(Variable1) it shows: [1] "numeric"
When I write max/min(Variable1) it shows: [1] "numeric"
When I write var(Variable1) it shows:

Warning message:
In var(Kintamasis1) : NAs introduced by coercion

When I write sd(Variable1) it shows:
[1] NA
Warning message:
In var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm) :
NAs introduced by coercion

What should I do?

Please help me,
Thank you so much

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.


If you've never heard of a reprex before, you might want to start by reading the help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "")

For pointers specific to the community site, check out the reprex FAQ.


Hi Iskrax,

A few things I see in your code you might want to check.

When you did this line Variable1 <- class(Variable1) I think you accidentally turned your variable into a short string of the class, like this:

> var1 <- select(mtcars, cyl) 
> var1 <- class(var1)
> var1 #oops!
[1] "data.frame"

> mean(var1)
[1] NA
Warning message:
In mean.default(var1) : argument is not numeric or logical: returning NA

#try this
mean(choose3variables$Variable1, na.rm = TRUE)


1 Like