如何在r中为不同类别分配相同的虚拟变量?

如何在r中为不同类别分配相同的虚拟变量?,r,regression,data-manipulation,dummy-variable,R,Regression,Data Manipulation,Dummy Variable,我使用的数据集如下所示: ClusterID URL Text_Body 0 www.text.com texttexttexttexttext..... 1 www.text1.com texttexttexttexttext..... 2 www.text2.com texttexttexttexttext..... 3

我使用的数据集如下所示:

  ClusterID      URL               Text_Body
   0            www.text.com       texttexttexttexttext.....
   1            www.text1.com      texttexttexttexttext.....
   2            www.text2.com      texttexttexttexttext.....
   3            www.text3.com      texttexttexttexttext.....
   4            www.text4.com      texttexttexttexttext.....
   5            www.text5.com      texttexttexttexttext.....
   6            www.text6.com      texttexttexttexttext.....
   7            www.text7.com      texttexttexttexttext.....
   8            www.text8.com      texttexttexttexttext.....

我们将此数据集称为“onlinearticles”。ClusterID是文章出现在其中的集群,url是每个文章的不同url,文本体是实际的文章。我需要构建一个额外的列,该列将值1分配给属于clusterID 0、4、6和7的任何行。任何其他clusterID的值都应为0。为了建立回归树,我需要建立这个专栏。我怎样才能着手建造这根柱子呢

ifelse(onlinearticles$ClusterID%in%c(0,4,6,7),1,0)
as.integer(onlinearticles$ClusterID%in%c(0,4,6,7))
如果我这样写的话:onlinearticles2@Vindication09几乎!您只需将结果分配给
onlinearticles
中的一个变量。类似于:
onlinearticles$Cluster\u Dummy