1

I have a dataset that has ID number, primary info, secondary info in R language using loops only. I need to create two new columns that takes values from primary info and secondary info. For example from this table(data) I have to get the second one:

  • Initial data:

enter image description here

  • What I need:

enter image description here

lovalery
  • 4,524
  • 3
  • 14
  • 28
  • Hi there! If I understand your problem correctly, you want to transform a data frame from wide into long format. There are many questions on that on stackoverflow already, here a [link to some good answers](https://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format). – Em Laskey Feb 24 '22 at 08:23
  • Hi user18296782, Welcome to SO! First, please avoid screenshots. To increase your chances of being helped, please provide your data by copy-pasting the result of `dput(my_dataframe)` into your post. That said, here is a possible solution to get what you are looking for. If your `dataframe` is called `df` you could do: `df <- cbind(df[1], stack(df[-1])); df <- df[order(df$ID),]`. Cheers – lovalery Feb 24 '22 at 10:45
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 24 '22 at 10:53

0 Answers0