R将不同长度的不同变量合并为一个以生成控制组
R combine different variables of different length to one to generate a control group
我正在使用 bootstrap 创建一个新样本,以生成一个控制年龄和性别的对照组。每个变量在 2 个值到 8 个值之间具有不同的数字长度
control_40_50_HRV_female2 <- abs(parametric_bootstrap_boot2(control_40_50_HRV_female_SDNN))
control_50_60_HRV_male2 <- abs(parametric_bootstrap_boot2(control_50_60_HRV_male_SDNN))
control_50_60_HRV_female2 <-abs(parametric_bootstrap_boot2(control_50_60_HRV_female_SDNN))
control_60_70_HRV_male2 <- abs(parametric_bootstrap_boot2(control_60_70_HRV_male_SDNN))
control_60_70_HRV_female2 <-abs(parametric_bootstrap_boot2(control_60_70_HRV_female_SDNN))
control_70_80_HRV_male2 <-abs(parametric_bootstrap_boot2(control_70_80_HRV_male_SDNN))
如何将它们全部放在一组(一个变量)中?这样我就可以开始做 t 检验了吗?我希望这是清楚的
这是变量的示例输出
> control_40_50_HRV_female2
[1] 29.08388 102.49869
> control_50_60_HRV_male2
[1] 36.81686 127.47986 13.40681
> control_50_60_HRV_female2
[1] 25.50313
> control_60_70_HRV_male2
[1] 39.93050 140.75967 13.89545 316.45988 158.91477
> control_60_70_HRV_female2
[1] 26.27908 106.40483
当我运行这个命令时
out <- stack(mget(ls(pattern = '^control_\d{2}_\d{2}_\w+_')))[2:1]
dim(out)
我明白了..这是我在脚本开头创建的所有变量的列表..
> dim(out)
[1] 96683 2
> head(out)
ind values
1 control_40_50_HRV_female_BPM 63.48
2 control_40_50_HRV_female_BPM 52.67
3 control_40_50_HRV_female_BPM 88.92
4 control_40_50_HRV_female_BPM 69.04
5 control_40_50_HRV_female_BPM 53.46
6 control_40_50_HRV_female_BPM 63.64
而我只需要这些变量的列表
control_40_50_HRV_female2, control_50_60_HRV_male2 .... control_70_80_HRV_male2
我们可以使用 mget
将 'control' 对象的值放入 list
,然后 stack
将其放入两列 data.frame
out <- stack(mget(ls(pattern = '^control_\d{2}_\d{2}_\w+_')))[2:1]
head(out)
# ind values
#1 control_40_50_HRV_female2 29.08388
#2 control_40_50_HRV_female2 102.49869
#3 control_50_60_HRV_female2 25.50313
#4 control_50_60_HRV_male2 36.81686
#5 control_50_60_HRV_male2 127.47986
#6 control_50_60_HRV_male2 13.40681
我正在使用 bootstrap 创建一个新样本,以生成一个控制年龄和性别的对照组。每个变量在 2 个值到 8 个值之间具有不同的数字长度
control_40_50_HRV_female2 <- abs(parametric_bootstrap_boot2(control_40_50_HRV_female_SDNN))
control_50_60_HRV_male2 <- abs(parametric_bootstrap_boot2(control_50_60_HRV_male_SDNN))
control_50_60_HRV_female2 <-abs(parametric_bootstrap_boot2(control_50_60_HRV_female_SDNN))
control_60_70_HRV_male2 <- abs(parametric_bootstrap_boot2(control_60_70_HRV_male_SDNN))
control_60_70_HRV_female2 <-abs(parametric_bootstrap_boot2(control_60_70_HRV_female_SDNN))
control_70_80_HRV_male2 <-abs(parametric_bootstrap_boot2(control_70_80_HRV_male_SDNN))
如何将它们全部放在一组(一个变量)中?这样我就可以开始做 t 检验了吗?我希望这是清楚的
这是变量的示例输出
> control_40_50_HRV_female2
[1] 29.08388 102.49869
> control_50_60_HRV_male2
[1] 36.81686 127.47986 13.40681
> control_50_60_HRV_female2
[1] 25.50313
> control_60_70_HRV_male2
[1] 39.93050 140.75967 13.89545 316.45988 158.91477
> control_60_70_HRV_female2
[1] 26.27908 106.40483
当我运行这个命令时
out <- stack(mget(ls(pattern = '^control_\d{2}_\d{2}_\w+_')))[2:1]
dim(out)
我明白了..这是我在脚本开头创建的所有变量的列表..
> dim(out)
[1] 96683 2
> head(out)
ind values
1 control_40_50_HRV_female_BPM 63.48
2 control_40_50_HRV_female_BPM 52.67
3 control_40_50_HRV_female_BPM 88.92
4 control_40_50_HRV_female_BPM 69.04
5 control_40_50_HRV_female_BPM 53.46
6 control_40_50_HRV_female_BPM 63.64
而我只需要这些变量的列表 control_40_50_HRV_female2, control_50_60_HRV_male2 .... control_70_80_HRV_male2
我们可以使用 mget
将 'control' 对象的值放入 list
,然后 stack
将其放入两列 data.frame
out <- stack(mget(ls(pattern = '^control_\d{2}_\d{2}_\w+_')))[2:1]
head(out)
# ind values
#1 control_40_50_HRV_female2 29.08388
#2 control_40_50_HRV_female2 102.49869
#3 control_50_60_HRV_female2 25.50313
#4 control_50_60_HRV_male2 36.81686
#5 control_50_60_HRV_male2 127.47986
#6 control_50_60_HRV_male2 13.40681