Transforming data

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Transforming data

reichmaj
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]]


______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Transforming data

reichmaj
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 <[hidden email]> On Behalf Of Jeff Reichman
Sent: Thursday, May 6, 2021 2:37 PM
To: [hidden email]
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]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Transforming data

Jeff Newmiller
CONTENTS DELETED
The author has deleted this message.