0

I have created an empty data frame called "New_dataframe" and I want to fill the empty values from my other dataframe where all the values are in 1 single column.

The new data frame that is empty have 10 columns and a length of 1:n. I want to fill 10 and 10 values one in each column horizontally from the old data in the singel column. How can I do that? See the code I have done below

This is the old data frame where I have the reaction data column which I want to transfer to the new data column with a for loop.

Orginal data frame used in the for loop

This is the shape of the new data frame I created which I want to use the for loop to fill the X variabels:

The data frame I want to fill format

n <- length(sort(unique(data$Subject)
for(i in (1:n)) {
  for(j in (0:9)) {
    New_dataframe[i,j+2] <- **ANYTHING I CAN WRITE HERE TO GET THIS TO WORK?** 
  }
}
  • 2
    It's always easier, if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) or at least a sample input and your expected output. – Martin Gal May 01 '22 at 16:59
  • 1
    Perhaps you may need `v1 <- diag(old_column_data)` – akrun May 01 '22 at 17:00
  • Hi, @MartinGal I have updated with some photos and more info if you need – Delusion989 May 01 '22 at 17:22

0 Answers0