0

我进行了联合设计调查,希望使用cjoint 包。cjoint 包中的示例数据格式如下:

head(model)
  CaseID contest_no          FeatEd             FeatJob
1      4          1     high school               Nurse
2      4          1       no formal Child care provider
3      4          2 graduate degree            Gardener
4      4          2       4th grade Construction worker
5      4          3     high school               Nurse
6      4          3  college degree Child care provider
                  FeatLang Chosen_Immigrant
1 tried English but unable              Yes
2         used interpreter               No
3           fluent English               No
4           fluent English              Yes
5           broken English              Yes
6           fluent English               No

“Case ID”代表每个受访者,“contest_no”代表每个受访者完成的个别任务。在这种情况下,每个受访者完成了 5 个任务(任务 1 到 3 可见),每个任务比较 2 个配置文件。每个配置文件都因属性“FeatEd”、“Featjob”、“FeatLang”而异。所选配置文件列为“Chosen_Immigrant”,并带有一个是或否的指示符。

我目前的数据是:

  • 被答主崩溃。同一行上的所有任务、配置文件和属性。
  • 按每行内的属性随机化。

例如:

has[1:3,12:16]
              F.1.1
1     Affordability
2 Community Support
3            Height
                                                          F.1.1.1
1 Affordable units will be built off-site, elsewhere in the city.
2                        Most people in the community support it.
3                                                       3 stories
          F.1.2                                F.1.1.2             F.1.3
1 Party Support    Local Republican Party supports it. Community Support
2       Parking All residents will park on the street.     Affordability
3      Location                   In your neighborhood     Affordability

F.1.1 代表任务 1 的属性标题。F.1.1.1 是配置文件 1 的任务 1 的属性值。F.1.2.1(未显示)是配置文件 2 的任务 1 的属性值。 1.2. 是任务 1 的标题,属性 2。F.1.1.2 是配置文件 1 的任务 2 的属性值。依此类推...

据我了解,要将我的数据框与 cjoint 示例的数据框匹配,我需要:

  1. 按属性的定义顺序对每一行进行排序。例如,c(“负担能力”,“党的支持”,...)
  2. 使用每个属性在行中的位置,获取为每个配置文件提供的相关级别。对于 F.1.1。“负担能力”,抢对比F.1.1.1和F.1.2.1。按行将它们彼此相邻分组。
  3. 将我的数据框从宽改成长,以便响应者和任务运行行 ID,列名是属性,单元格代表属性级别。

我想我可以用 reshape2 或 tidyr 找出第 3 步。但是,对于在给定单元格值的行内按列排序和抓取行内相关的其他单元格的任何帮助将不胜感激。

4

0 回答 0