Reputation: 11
i am a begginer in R, im working with a csv archive named rere.csv so trying to get the mean of quality column with this code:
x<-read.csv("rere.csv", header = TRUE, sep = ";")
mean(x$quality)
But i get this:
Warning message: In mean.default(x$quality) : argument is not numeric or logical: returning NA
quality
5
6
2
2
4
9
41
1
5
N.A
2
23
2
9
5
62
2
Upvotes: 1
Views: 66
Reputation: 145965
It looks like your data has N.A
entries for missing values. By default, R expects NA
, but you can tell read.csv
that N.A
is missing data
x <- read.csv("rere.csv", header = TRUE, sep = ";", na.strings = "N.A")
This will allow R to read the column in as a numeric with missing values rather than a factor (categorical) variable. To get a mean of the non-missing values only, you'll have to tell mean
to leave out the NA's.
mean(x$quality, na.rm = TRUE)
Upvotes: 1
Reputation: 70296
Try this:
x<-read.csv("rere.csv", header = TRUE, sep = ";", na.strings = "N.A")
mean(x$quality, na.rm = TRUE)
You can read the help page ?read.csv
for more info on the arguments, including na.strings
.
Upvotes: 3