0

I have two matrix: One is no_training_205 and the other is pred_expr:

dput(no_training_205[1:3,1:4])
structure(list(samples = c("GTEX-1117F", "GTEX-111FC", "GTEX-1128S"
), yr = c(-0.0814098051060948, 0.206379671030366, 0.321031350919992
), yp = c(NA, NA, NA), y_1 = c(0.0874511551, 0.7758032222, 0.3595051697
)), row.names = c(NA, 3L), class = "data.frame")



dput(pred_expr[1:3,])
c(0.0874511551, 0.7758032222, 0.3595051697)

I want to add pred_Expr values to this no_training_205$y_1 columns. I am trying to do this:

k<- 1
pred_expr <- as.data.frame(t(pred_expr))
a <- paste0("y_",k)  ##generate y_1
no_training_205$a <- pred_expr$ENSG00000130943.6

I am using paste0 since I have many pred_Expr[1:128] and wants to add its corresponding values to no_training dataframe[4:131] And what to do it using for loop. rather than manually adding. Is there any way to convert the paste0 value to the variable name or colname to add the values.

rheabedi1
  • 65
  • 7
  • 2
    Use `no_training_205[[a]] <- pred_expr$ENSG00000130943.6`. You cannot use `$` with a variable on the right, but you can use the `[[]]` function – MrFlick May 02 '23 at 16:25

0 Answers0