CI_95_outcomes_male
我想你忘了把 colnames 放在 CI_95_outcomes_male 左右 . 但是's another problem here. I'假设 mean_outcomes_male 是一个向量,在这种情况下 colnames(mean_outcomes_male) 是 NULL .
data.frame(mean_outcomes_male,CI_95_outcomes_male)
即使 CI_95_outcomes_male 是正确的,上面的命令也会产生一个4x5数据帧,第一列是 mean_outcomes_male 向量,第二列是第一个变量的 CI_95_outcomes_male 值(每行重复一次),......和第五列column是第四个变量的 CI_95_outcomes_male 值(每行重复一次) .
你需要做这样的事情:
set.seed(42)
# Generate a random dataset for outcomes_male_dt with 4 variables and n rows
n
outcomes_male_dt
# I'm assuming you want the 95th percentile of each variable in outcomes_male_dt and store them in CI_95_outcomes_male
ptl
CI_95_outcomes_male
# I'm going to assume that mean_outcomes_male is a vector of means for all the variables in outcomes_male_dt
mean_outcomes_male
# You want to end up with a 2x4 matrix - I'm assuming you meant row 1 will be the means, and row 2 will be the 95th percentiles, and the columns will be the variables
want
colnames(want)
row.names(want)
want # Resulting matrix