Re: [R] a simple reshape

2020-04-04 Thread Yuan Chun Ding
To: Yuan Chun Ding Cc: r-help mailing list Subject: Re: [R] a simple reshape Hi, [For a non-tidyverse solution:] Your problem is ambiguous without a 'time' variable; e.g., why should the answer not be test2 <- data.frame(vntr1=c("v1","v2"),

Re: [R] a simple reshape

2020-04-04 Thread Deepayan Sarkar
Hi, [For a non-tidyverse solution:] Your problem is ambiguous without a 'time' variable; e.g., why should the answer not be test2 <- data.frame(vntr1=c("v1","v2"), a1 =c(NA, 0.5693), a2 = c(0.02, 0.12), a3 =c(NA, 0.11),

Re: [R] a simple reshape

2020-04-03 Thread Jim Lemon
Hi Ding, If you are still having trouble, perhaps: library(prettyR) stretch_df(test1,"vntr1","val") Jim On Sat, Apr 4, 2020 at 5:58 AM Yuan Chun Ding wrote: > > Hi R users, > > I want to do a data reshape from long to wide, I thought it was easy using > tidyverse spread function, but it did

Re: [R] a simple reshape

2020-04-03 Thread Rui Barradas
08 PM To: Yuan Chun Ding; r-help mailing list Subject: Re: [R] a simple reshape Hello, It's a bit more complicated than you have coded it. I will use pivot_wider, it's now the natural way of doing it. test1 %>% group_by(vntr1) %>% mutate(group = row_number()) %>% ung

Re: [R] a simple reshape

2020-04-03 Thread Jeff Newmiller
quot;vntr1", names_from = "group", >names_prefix = "a", : > could not find function "pivot_wider" > >From: Rui Barradas [ruipbarra...@sapo.pt] >Sent: Friday, April 3, 2020 12:08 PM >To: Yuan Chun Ding; r-help mai

Re: [R] a simple reshape

2020-04-03 Thread Yuan Chun Ding
Rui Barradas [ruipbarra...@sapo.pt] Sent: Friday, April 3, 2020 12:08 PM To: Yuan Chun Ding; r-help mailing list Subject: Re: [R] a simple reshape Hello, It's a bit more complicated than you have coded it. I will use pivot_wider, it's now the natural way of doing it. test1 %>% group

Re: [R] a simple reshape

2020-04-03 Thread Rui Barradas
Hello, It's a bit more complicated than you have coded it. I will use pivot_wider, it's now the natural way of doing it. test1 %>% group_by(vntr1) %>% mutate(group = row_number()) %>% ungroup() %>% pivot_wider( id_cols ="vntr1", names_from = "group", names_prefix = "a",

[R] a simple reshape

2020-04-03 Thread Yuan Chun Ding
Hi R users, I want to do a data reshape from long to wide, I thought it was easy using tidyverse spread function, but it did not work well. Can you help me? Thank you, Ding test1 data frame is long file and test2 is the wide file I want to get test1 <- data.frame (vntr1=c("v1","v1",