If I have 128 columns (patients) and 1265 rows (genes) of data; example below. How do I calculate the average of each column (128) in R? I need to know how to write the code in R?
> exprs(ALL)
01005 01010 03002 04006 04007
1000_at 7.597323 7.479445 7.567593 7.384684 7.905312
1001_at 5.046194 4.932537 4.799294 4.922627 4.844565
1002_f_at 3.900466 4.208155 3.886169 4.206798 3.416923
1003_s_at 5.903856 6.169024 5.860459 6.116890 5.687997
1004_at 5.925260 5.912780 5.893209 6.170245 5.615210
1005_at 8.570990 10.428299 9.616713 9.937155 9.983809
1006_at 3.656143 3.853979 3.646808 3.874289 3.547361
There are many ways for calculating average of each column in R.
1.
> colMeans(x=ALL, na.rm = TRUE) # Assuming that your data stored in ALL variable and in dataframe format. IF not run this
> ### Create Data Frame
> ALL=as.data.frame(ALL)
2.
Use summarise in the dplyr package:
library(dplyr) summarise(ALL, Average = mean(col_name, na.rm = T))
3.
Get Mean of the column by column position
# Get Mean of the column by column position
> mean(ALL[,3])
Get Answers For Free
Most questions answered within 1 hours.