I have code to compute this for one data set
quant0 = c(0.5)
Median = apply(data1[2:1000], 2, median, probs = quant0, na.rm = TRUE )
quant1 = c(0.25)
firstQuartiles = apply( data1[2:1000] , 2 , quantile , probs = quant1 , na.rm = TRUE )
quant2 = c(0.75)
thirdQuartiles = apply( data1[2:1000] , 2 , quantile , probs = quant2 , na.rm = TRUE )
I have multiple datasets in the same format of the one I used for the code above. This is what all the data frames look like:
Type x1 x2 x3 ...
1: type1 1.54 1.48 1.88
2: type2 1.46 1.99 1.48
3: type1 2.01 1.02 1.03
...
I am a novice at writing functions. The other data sets I need to apply this function to are in the exact same format as I have shown above. The only thing that will change is the number of columns. Edit: I did not explain correctly, I want to use a function to compute the median, First quartile and third quartile for each column, for each type.
This is the code I used to do what I specified in the Edit above:
library(dplyr)
FactorMedians = data1 %>%
group_by(Type) %>%
summarise(across(starts_with('x'), median, probs = quant0, na.rm = TRUE))
I need to change this into a function I can use with other similar datasets