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)

error_message

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

class(recup$columnName)

What is the output of

head(recup$columnName)

@FJCC

When I run your first command I get:

[1] "NULL"

The output of the second command is:

NULL

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.
Maybe

class(recup$med

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.