[R] Transforming data

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Thu May 6 22:48:55 CEST 2021


Posting HTML email is a good way to reduce your chances of getting a response.

On May 6, 2021 1:13:16 PM PDT, Jeff Reichman <reichmanj using sbcglobal.net> wrote:
>R-help
>
>Never mind I figured out a working solution
>
>- remove duplicate
>- mutate a new column  == 1
>- spread the data from long  to wide
>- replace NA with 0's
>
>Not sure it’s the most elegant but gets the gob done
>
>
>-----Original Message-----
>From: R-help <r-help-bounces using r-project.org> On Behalf Of Jeff Reichman
>Sent: Thursday, May 6, 2021 2:37 PM
>To: R-help using r-project.org
>Subject: [R] Transforming data
>
>R Help Forum
>
>I am attempting to transform the data frame in Table 1 to the form
>shown in Table 2. Any suggestions. I ve started by removing duplicate
>rows 
>
> 
>
>Jeff
>
> 
>
> 
>
>Table 1
>
>
>Taxon
>
>Importer
>
>
>Guarouba guarouba
>
>AE
>
>
>Acipenser gueldenstaedtii
>
>AE
>
>
>Caiman crocodilus fuscus
>
>AE
>
>
>Caiman crocodilus fuscus
>
>AE
>
>
>Caiman crocodilus fuscus
>
>AE
>
>
>Ara ararauna
>
>AG
>
>
>Ara chloropterus
>
>AG
>
>
>Python reticulatus
>
>AE
>
>
>Strombus gigas
>
>AE
>
>
>Strombus gigas
>
>AE
>
>
>Strombus gigas
>
>AE
>
>
>Strombus gigas
>
>AE
>
>
>Strombus gigas
>
>AE
>
>
>Varanus niloticus
>
>AE
>
>
>Varanus niloticus
>
>AE
>
>
>Caiman crocodilus fuscus
>
>AE
>
> 
>
> 
>
>Table 2
>
>
>Country 
>
>Guarouba guarouba
>
>Acipenser gueldenstaedtii
>
>Caiman crocodilus fuscus
>
>Python reticulatus
>
>Strombus gigas
>
>Varanus niloticus
>
>Caiman crocodilus fuscus
>
>Ara ararauna
>
>Caiman crocodilus fuscus
>
>
>AE
>
>1
>
>1
>
>1
>
>1
>
>1
>
>1
>
>1
>
>0
>
>0
>
>
>AG
>
>0
>
>0
>
>0
>
>0
>
>0
>
>0
>
>0
>
>1
>
>1
>
> 
>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list