Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一列包含异常值,我想用一个代表年数(32)的特定数字对其进行加权。
我怎样才能做到这一点?
data(mtcars) mtcars$weight<-apply(mtcars[5], 1, ??, 32)
mtcars$weighted <- mtcars$drat * 32
或者,如果每次观察的权重不同
mtcars$weighted <- mtcars$drat * mtcars$cyl
无需申请,为方便起见,乘法已经矢量化;)