Search code examples
rvectorstandardsdeviation

Mean and standard deviation of triplicated vector data


I have an experiment where I measured a bit less than 200 variables in triplicate. In other words, I have three vectors of ~ 200 values.

I want a quick way to determine if I should use mean or median for my calculations. I can do the mean easily ((v1 + v2 + v3) / 3), but how do I calculate the SD to have it in a vector of ~ 200 SDs? And what about the median? After having these values, I need to do growth curves (measurements were taken over certain period of time).


Solution

  • Here is a dplyr solution:

    require(dplyr)
    
    d <- data.frame(
      x1 = rnorm(10),
      x2 = rnorm(10),
      x3 = rnorm(10)
      )
    
    d %>%
      rowwise() %>%
      mutate(
        mean = mean(c(x1, x2, x3)),
        median = median(c(x1, x2, x3)),
        sd = sd(c(x1, x2, x3))
        )
    

    It sounds like you also have a substantive question about longitudinal data. If so, crossvalidated would be a good platform for this question.