CI_95_outcomes_male<-colnames(mean_outcomes_male)
I think you forgot to put colnames
around CI_95_outcomes_male
. But there's another problem here. I'm assuming that mean_outcomes_male
is a vector, in which case colnames(mean_outcomes_male)
is NULL
.
data.frame(mean_outcomes_male,CI_95_outcomes_male)
Even if CI_95_outcomes_male
was correct, the above command will result in a 4x5 data frame, with the first column being the mean_outcomes_male
vector, second column being the CI_95_outcomes_male
value for your first variable (repeated for each row),...,and the fifth column being the CI_95_outcomes_male
value for your fourth variable (repeated for each row).
You need to do something like this:
set.seed(42)
# Generate a random dataset for outcomes_male_dt with 4 variables and n rows
n <- 100
outcomes_male_dt <- data.frame(x1=runif(n),x2=runif(n),x3=runif(n),x4=runif(n))
# I'm assuming you want the 95th percentile of each variable in outcomes_male_dt and store them in CI_95_outcomes_male
ptl <- .95 # if you want to add other percentiles you can replace this with something like "ptl <- c(.10,.50,.90,.95)"
CI_95_outcomes_male <- apply(outcomes_male_dt,2,quantile,probs=ptl)
# 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 <- colMeans(outcomes_male_dt)
# 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 <- rbind(mean_outcomes_male, CI_95_outcomes_male)
colnames(want) <- colnames(outcomes_male_dt)
row.names(want) <- c('Mean',paste0("p",ptl*100)) # paste0("p",ptl*100) is equivalent to paste("p",ptl*100,sep="")
want # Resulting matrix