Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do you find the median of 2 columns using R?

Tags:

r

median

I am trying to compute the median vector of a data set s with column A1 and B1. The median vector is the median for each observation from both columns.

I tried to do this and it did not work.

median(s[c("A1","B1")])

Is there another way to do it?

like image 816
Rbuilder Avatar asked Dec 10 '22 18:12

Rbuilder


1 Answers

The median of two observations is simply the mean. So rowMeans(s[,c("A1","B1")]). Equivalently, apply(s[,c("A1","B1")],1,median)

like image 92
Rob Hyndman Avatar answered Dec 31 '22 09:12

Rob Hyndman