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-boun...@r-project.org> On Behalf Of Jeff Reichman
Sent: Thursday, May 6, 2021 2:37 PM
To: R-help@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@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.

Reply via email to