I am wondering if there is any way to a median of the rows in a data frame. I understand the function rowmeans exists, but I do not believe there is a row median function. I would like to store the results in a new column in the dataframe. Here is my example
I tried to look online. There was one mention of row medians, but I could not find the function in R.
C1<-c(3,2,4,4,5)
C2<-c(3,7,3,4,5)
C3<-c(5,4,3,6,3)
DF <- data.frame(ID=c("A","B","C","D","E"),C1=C1,C2=C2,C3=C3)
DF
# This is as far as I have gotten, but not streamlined
MA <- median(C(3, 3, 5). na.rm = T) # A
MB <- median(C(2, 7, 4). na.rm = T) # B
MC <- median(C(4, 3, 3). na.rm = T) # C
MD <- median(C(4, 4, 6). na.rm = T) # 4
ME <- median(C(5, 5, 3). na.rm = T) # E
CM <- c(MA, MB, MC, MD, ME)C1<-c(3,2,4,4,5)
ID C1 C2 C3
1 A 3 3 5
2 B 2 7 4
3 C 4 3 3
4 D 4 4 6
5 E 5 5 3
ID C1 C2 C3 CM
1 A 3 3 5
2 B 2 7 4
3 C 4 3 3
4 D 4 4 6
5 E 5 5 3
Is there anyway I can streamline the process so it would be like DF$CM <- median(...