R:如何使用基于另一列的某些值的值创建新列?

时间:2017-01-06 12:39:51

标签: r

我有一个包含多个变量的数据框:

Subj DashedOrQuest ItemNo TimesOrCorrect
1    dashed        243    859
1    dashed        243    648
1    dashed        243    655
1    dashed        243    389
1    question      243    1
1    dashed        244    465
1    dashed        244    844
1    dashed        244    578
1    dashed        244    713
1    question      244    0

我想要做的是创建一个新的列“Quest”,这样对于每个ItemNo,在DashedOrQuest中,TimesOrCorrect中的数字将为“question”值。换句话说,它应该看起来像这样

Subj DashedOrQuest ItemNo TimesOrCorrect Quest
1    dashed        243    859            1
1    dashed        243    648            1
1    dashed        243    655            1
1    dashed        243    389            1
1    question      243    1              1
1    dashed        244    465            0
1    dashed        244    844            0
1    dashed        244    578            0
1    dashed        244    713            0
1    question      244    0              0

如何在R中做到这一点?提前谢谢!

2 个答案:

答案 0 :(得分:1)

from django import form

q = models.Person.objects.all()
qty = range(len(q))
PersonForm = type('PersonForm',
                                (forms.Form,),
                                {'person'+'_'+str(q[i].id): forms.BooleanField(label=q[i].name,
                                        required=False) for i in qty})

答案 1 :(得分:0)

我们可以使用window.onload = function() { var getpicture = localStorage.getItem('imageData'); var image = document.createElement('img'); image.src = getpicture; };

data.table
相关问题