[問題] 比對刪除欄位與逐步計算cell

作者: sinclairJ (KEEP MOVING FORWARD)   2015-07-30 10:52:00
小弟目前原始資料表格示意如下
sample/col col1 col2 col3 col4 col5
sample1 5 8 6 15 2
sample2 16 8 16 25 5
sample3 5 18 8 16 12
統計量a NA 7 10 15 30
統計量b 6 9 NA 8 8
問題一、請問要如何把統計量a或統計量b為NA的那欄刪除,會變這樣:
sample/col col2 col4 col5
sample1 8 15 2
sample2 8 25 5
sample3 18 16 12
統計量a 7 15 30
統計量b 9 8 8
問題二、再逐步計算每個cell裡面的值,會變這樣:
sample/col col2 col4 col5
sample1 (8-統計量a)/統計量b (15-a)/b (2-a)/b
sample2 (8-a)/b (25-a)/b (5-a)/b
sample3 (18-a)/b (16-a)/b (12-a)/b
因實際資料有上百行與上百列,想請教各位前輩如何用迴圈實現這兩個問題,感謝
作者: celestialgod (天)   2015-07-30 12:12:00
轉成matrix 最好方法是轉置然後na.omit接兩個sweep就好了

Links booklink

Contact Us: admin [ a t ] ucptt.com