Can you take the percentage of the standard deviation (R)?

1

For example ..

I have a series of values (prices) related to a product on several different dates.

I need to get the percentage change of this value.

Currently, prices are giving a standard deviation of 120.00, but I wanted that result in percentage. Like, prices have varied by 20% on those specific days.

How to do this in R?

    
asked by anonymous 09.07.2018 / 20:06

1 answer

2

If you want to know the standard deviation relative to the mean, this is the coefficient of variation . To have in percentage just multiply by one hundred.

Programming the CV in R is a very easy problem to solve.

coefVar <- function(x, na.rm = FALSE){
  sd(x, na.rm = na.rm)/mean(x, na.rm = na.rm)
}

set.seed(9580)    # Torna os resultados reprodutíveis

x <- runif(100, 0, 20)

coefVar(x)
#[1] 0.621354

coefVar(x)*100    # Em porcentagem
#[1] 62.1354

Given the comment about the result of a function calculation, this is what gives me:

y <- c(772.8, 147.28, 993.72)
coefVar(y)*100
#[1] 68.82238

It seems right.

    
09.07.2018 / 22:09