0

I want to move the rows of the first column to the columns and the values of the second column to the rows

###### CREATE THE DATA FRAME ######

Hypothesis <- c("Hyp_1", "Hyp_2", "Hyp_3")
Estimates <- c(0.34, 0.01, 0.22)

df <- as.data.frame(cbind(Hypothesis, Estimates))

df

  Hypothesis Estimates
      Hyp_1      0.34
      Hyp_2      0.01
      Hyp_3      0.22

What I want is the next format

Hyp_1 Hyp_2  Hyp_3
0.34   0.01   0.22

I tried with the next code without success

dcast(df, Estimates~Hypothesis)

Thank you!!!!

  • What do you mean by that being without success? This seems like a pretty straightforward long-to-wide reshaping question, so if there's some reason previous solutions won't work, you should make that clear – camille Apr 14 '23 at 14:29
  • Wow! Look at those manners :). I mean what the sentence means. I use that code and it does not work for what I want to do. What of that is not clear? And please stop removing the thank you. Thank you! – Kevin López Reyes Apr 24 '23 at 20:52
  • You should make it evident from the question what happened for it to be "without success". Since there are a lot of other similar questions, without knowing what _exactly_ went wrong, it's hard to know how to help or why previous posts don't work for you. And "thank you", etc is [considered clutter](https://meta.stackoverflow.com/q/328379/5325862), so it's pretty standard practice to remove it – camille Apr 24 '23 at 21:08

1 Answers1

0

Try this:

library(tidyverse)
pivot_wider(df, names_from = Hypothesis, values_from = Estimates)

Lucas
  • 302
  • 8