Re: [R] non-standard reshape from long to wide

2021-01-08 Thread PIKAL Petr
essage- > From: R-help On Behalf Of Yuan Chun Ding > Sent: Thursday, January 7, 2021 7:40 PM > To: r-help@r-project.org > Subject: [R] non-standard reshape from long to wide > > Dear R user, > > I want to reshape a long data frame to wide format, I made the following >

Re: [R] non-standard reshape from long to wide

2021-01-07 Thread Yuan Chun Ding
-standard reshape from long to wide Hello, Here is a dplyr solution. The main trick is to create a column of 1's, then pipe to pivot_wider. library(dplyr) library(tidyr) df.long %>% mutate(values = 1) %>% pivot_wider( id_cols = sample, names_from = marker, values_fr

Re: [R] non-standard reshape from long to wide

2021-01-07 Thread Rui Barradas
Hello, Here is a dplyr solution. The main trick is to create a column of 1's, then pipe to pivot_wider. library(dplyr) library(tidyr) df.long %>% mutate(values = 1) %>% pivot_wider( id_cols = sample, names_from = marker, values_from = values, values_fill = NA ) Note:

Re: [R] non-standard reshape from long to wide

2021-01-07 Thread Bert Gunter
mevar, ... : > > *From:* Bert Gunter [mailto:bgunter.4...@gmail.com] > *Sent:* Thursday, January 7, 2021 10:52 AM > *To:* Yuan Chun Ding > *Cc:* r-help@r-project.org > *Subject:* Re: [R] non-standard reshape from long to wide > > > > Is this homework? There is a no-h

Re: [R] non-standard reshape from long to wide

2021-01-07 Thread Yuan Chun Ding
com] Sent: Thursday, January 7, 2021 10:52 AM To: Yuan Chun Ding Cc: r-help@r-project.org Subject: Re: [R] non-standard reshape from long to wide Is this homework? There is a no-homework policy on this list. If not, note that you are usually asked to show what you tried and the error messages you rec

Re: [R] non-standard reshape from long to wide

2021-01-07 Thread Bert Gunter
Is this homework? There is a no-homework policy on this list. If not, note that you are usually asked to show what you tried and the error messages you received. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley

[R] non-standard reshape from long to wide

2021-01-07 Thread Yuan Chun Ding
Dear R user, I want to reshape a long data frame to wide format, I made the following example files. Can you help me? Thank you, Yuan Chun Ding sample <-c("xr" , "xr" , "fh" , "fh" , "fh" , "uy" , "uy" , "uy" , "uy"); marker <-c("x" , "y" , "g" , "x" , "k" , "y" , "x" , "u" , "j"); df.long <-