0

I want to calculate mean of a column in R. The column is written in a csv file, namely datafile, as follows.

X
12
14
10
...

I read the data as follows.

myData <- read.csv("datafile.csv")

When I want to calculate the mean as mean(myData), I get the following message:

[1] NA Warning message: In mean.default(myData) : argument is not numeric or logical: returning NA
ankh-morpork
  • 1,732
  • 1
  • 19
  • 28
M. Mohebbi
  • 27
  • 4

1 Answers1

0

Welcome to SO.

A good place to start is to read the documentation, for mean with ?mean.

That said, you are probably looking for the colMeans function:

colMeans(myData,na.rm=T)

The na.rm=T doesn't take into account NA entries, which is what's likely causing the error.

PavoDive
  • 6,322
  • 2
  • 29
  • 55