how to calculate the average of only one part of a Rstudio column

Asked

Viewed 806 times

0

I have separated only a part of a column, I cannot work with this data, I can only visualize it separately. Someone can help me?! inserir a descrição da imagem aqui

  • 1

    Try to put the sample you separated into a variable and average it

  • 2

    Welcome to the Portuguese stack overflow. To facilitate our help, it is recommended to follow the good response guide as shown here.

  • 2

    Unfortunately, your question cannot be reproduced by anyone who tries to answer it. Please, take a look at this link and see how to ask a reproducible question in R, so that people who want to help you can do this in the best possible way.

  • Use the command dput() with the data you want to take the average and post in your question, it would be much easier!

1 answer

1

There is a problem in the import, your data is not in numerical.

Setting the example:

data <- data.frame(x1 = 1:10, x2 = 11:20)

Example of non-numerical data:

data$x1 <- as.factor(data$x1)
mean.default(data$x1[8:9])

Warning message:
In mean.default(data$x3) : argument is not numeric or logical: returning NA

You can check this by the str command():

str(data)
'data.frame':   10 obs. of  2 variables:
$ x1: Factor w/ 10 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10
$ x2: int  11 12 13 14 15 16 17 18 19 20

Data storage correction if factor:

data$x1 <- as.numeric(levels(data$x1))

mean.default(data$x3[8:9])
[1] 8.5

Browser other questions tagged

You are not signed in. Login or sign up in order to post.