作者celestialgod (攸蓝)
看板R_Language
标题Re: [问题] 比对删除栏位与逐步计算cell
时间Thu Jul 30 13:33:29 2015
code & benchmark:
http://pastebin.com/9d4m2HDc
for再改矩阵时很快,所以建议使用for
如果你是data.frame的话,还是建议转成data.table 避免不断复制data.frame的问题
apply虽然在这好用,但矩阵还是比不上回圈的速度
※ 引述《sinclairJ (SunnyGymBoy)》之铭言:
: 小弟目前原始资料表格示意如下
: 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
: 因实际资料有上百行与上百列,想请教各位前辈如何用回圈实现这两个问题,感谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 42.72.134.158
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1438234411.A.BB0.html
※ 编辑: celestialgod (1.163.14.123), 07/30/2015 21:04:24
1F:推 sinclairJ: 谢谢c大 晚点来学习 07/31 02:54