【发布时间】:2015-09-04 09:54:58
【问题描述】:
我有一个包含两个嵌套因子的实验。例如,性别(1,2)和条件(1,2),比如:
factor A factor B
male cond.1
male cond.2
female cond.1
female cond.2
不幸的是,我用来导出因变量值的程序结合了标题中的因子水平,例如
male_cond.1, male_cond.2, female_cond.1, female_cond.2
456 , 5654 , 566 , 456
... ... ... ...
这很不方便,因为当我将数据框融合为 ANOVA 适当的长格式时,我无法再根据因子的不同级别分离数据。它看起来像这样:
1st column, 2nd column (DV)
male_cond.1, 454
male_cond.2, 5654
female_cond.1, 566
female_cond.2, 456
那么,如何插入两个新列,它们的长度与数据框的长度一样长,重复我的因子值?这两列应如下所示:
1st column (gender), 2nd column (condition),
male, cond.1
male, cond.2
femal, cond.1
female, cond.2
... ...
我自己的数据框有四个因素:电极(63) x soa(2) x stimulstype(3) x itemtype(2)。这是我原来的数据框的样子:
File Fp1.PD_ShortSOA_FAM Fp1.PD_LongSOA_FAM Fp1.PD_ShortSOA_SEMplus_REAL Fp1.PD_ShortSOA_SEMplus_FICT
sub0001 0,446222 2,524,804 0,272959 1,281,349
sub0002 1,032,688 2,671,048 1,033,278 1,217,817
然后这就是转置的样子:
row.names V1 V2
File sub0001 sub0002
Fp1.PD_ShortSOA_FAM 0,446222 1,032,688
Fp1.PD_LongSOA_FAM 2,524,804 2,671,048
Fp1.PD_ShortSOA_SEMplus_REAL 0,272959 1,033,278
Fp1.PD_ShortSOA_SEMplus_FICT 1,281,349 1,217,817
Fp1.PD_ShortSOA_SEMminus_REAL 0,142739 1,405,100
Fp1.PD_ShortSOA_SEMminus_FICT 1,515,577 -1,990,458
我希望我的因子列显示为:
electrode, SOA, stimulustype, itemtype
Fp1. ShortSOA FAM
Fp1. LongSOA FAM
Fp1. ShortSOA SEMplus REAL
... ... ... ...
我尝试使用this post 中的“strsplit”,但没有成功。
【问题讨论】: