user2938738 user2938738 - 5 months ago 13
R Question

R Beginner: argument is not numeric or logical: returning NA

I am an R beginner and having a hard time doing anything in it. I have a data set that originated from an excel file but is now a

file with two columns, one being incomplete. For some reason, whenever I try to run basic stat operation on the data, I get this message:

In mean.default(results) : argument is not numeric or logical: returning NA

Results being my set. Any advice on getting around this problem?


From R 3.0.0 onwards mean(<data.frame>) is defunct (and passing a data.frame to mean will give the error you state)

A data frame is a list of variables of the same number of rows with unique row names, given class "data.frame".

In your case, result has two variables (if your description is correct) . You could obtain the column means by using any of the following

lapply(results, mean, na.rm = TRUE)
sapply(results, mean, na.rm = TRUE)
colMeans(results, na.rm = TRUE)