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

-1

I have separated only one part of a column, I can not work with this data, I can only see it separately. Can someone help me?!

    
asked by anonymous 03.02.2018 / 18:09

1 answer

1

There is a problem importing, your data is not numeric.

Creating the example:

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

Example of non-numeric 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 through 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 fix if factor:

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

mean.default(data$x3[8:9])
[1] 8.5
    
05.02.2018 / 16:56