Calculate the mean by column

When I try the command for calculating the mean in RStudio I receive an error message.

res <- mean(recup$columnName, na.rm = TRUE)


This lead me to reading up on StackOverflow, then I tried the alternative commands.

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

I receive the same error only with 'In mean.default(X[[i]], ...) :' included in the message.

The error message says the column is not numerical or logical. What do you get when you run


What is the output of



When I run your first command I get:

[1] "NULL"

The output of the second command is:


You need to substitute the actual column name for columnName. For example, you wrote

Whatever you use as the column name in that command, use the same thing in the commands I wrote.


would be correct.

Perhaps share a reproducible example of your dataset?

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.