-2

I'm finding mean absolute deviation in r. when I run it, the r gives me the error that you should have numeric data. furthermore, when I convert the data into numeric, then it gives me the error that your x must be atomic.

md <- mad(x, center = median(x), constant = 1.4826, na.rm = FALSE,
      low = FALSE, high = FALSE)
Error in median.default(x) : need numeric data

When I convert the data into numeric then again it gives me the error that your x must be atomic. here is the error.

md <- mad(x.num, center = median(x.num), constant = 1.4826, na.rm = FALSE,
      low = FALSE, high = FALSE)
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 
  'x' must be atomic
camille
  • 16,432
  • 18
  • 38
  • 60
  • If this is a question about data types, we'd need to have a sample of your data as you're working with it in order to do more than guess. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making a reproducible example – camille Oct 06 '19 at 18:49

1 Answers1

0

It helps if you could provide your x vector here. It works fine in the following atomic vectors and non-numeric vectors.

# numeric vector
> x <- 1:10
> mad(x, center = median(x), constant = 1.4826, na.rm = FALSE, low = FALSE, high = FALSE)
> 3.7065

# non-numeric vector
> x <- c(TRUE, FALSE, T, F)
> mad(x)
> 0.7413

# atomic vector
> x <- c(1L, 6L, 10L)
> mad(x)
> 10

# works even with NA's in the vector
> x <- c(1L, 6L, 10L, NA)
> mad(x, na.rm = TRUE)
> 5.9304
Sathish
  • 16
  • 2