且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用R根据其他列创建新变量

更新时间:2023-12-01 11:36:16

尝试一下:

ped <- transform(ped, gender = ifelse(person %in% father,
                                      'M',
                                      ifelse(person %in% mother, 'F', NA)
                                     ))

而不是循环遍历各个值行,这使用矢量化。

Instead of looping over the individual values across the rows, this uses vectorization.