dplyr returning NA in new column and not following conditions

I have one data frame about animal sightings (more than 300), with species of whales, dolphins, pinipedes and penguins.

And I want to create a new column reino, which would be misticeto for whales, odontoceto for dolphins, pinipede for pinipedes and penguin for penguins.

But when I do that, one specific whale (Ballena franca austral (Eubalaena australis)) result in NA value at reino column.

library(data.table)
library(dplyr)
> packageVersion("dplyr")
[1] ‘1.1.4’


dt = data.table(especie= c('Ballena franca austral (Eubalaena australis)','Ballena barbada no identificada (Parvorden Mysticeti)', 'Ballena jorobada (Megaptera novaeangliae)', 'Ballena rorcual no identificada (Balaenoptera sp.)', 'Ballena sei (Balaenoptera borealis)', 'Ballena fin (Balaenoptera physalus)', 'Ballena barbada no identificada(Parvorden Mysticeti)','Delfín austral (Lagenorhynchus australis)', 'Delfín no identificado (Familia Delphinidae)', 'Tonina overa (Cephalorhynchus commersonii)', 'Delfín oscuro (Lagenorhynchus obscurus)','Lobo marino de dos pelos no identificado (Arctocephalus sp.)', 'Lobo marino no identificado (Familia Otariidae)', 'Lobo marino de dos pelos sudamericano (Arctocephalus australis)', 'Lobo marino de un pelo sudamericano (Otaria flavescens)', 'Lobo marino de dos pelos antártico (Arctocephalus gazella)','Lobo marino de dos pelos sudamericano (Arctocephalusaustralis)','Pingüino patagónico (Spheniscus magellanicus)', 'Pingüino no identificado (Familia Spheniscidae)', 'Cormorán Imperial (Phalacrocorax albiventer)', 'Pingüino penacho amarillo austral (Eudyptes chrysocome)', 'Pingüino rey (Aptenodytes patagonicus)'))

as.character(dt$especie)

I want do do this:

dt$reino[dt$especie %in% c('Ballena franca austral (Eubalaena australis)','Ballena barbada no identificada (Parvorden Mysticeti)', 'Ballena jorobada (Megaptera novaeangliae)', 'Ballena rorcual no identificada (Balaenoptera sp.)', 'Ballena sei (Balaenoptera borealis)', 'Ballena fin (Balaenoptera physalus)', 'Ballena barbada no identificada(Parvorden Mysticeti)')] <- 'misticeto'

dt$reino[dt$especie %in% c('Delfín austral (Lagenorhynchus australis)', 'Delfín no identificado (Familia Delphinidae)', 'Tonina overa (Cephalorhynchus commersonii)', 'Delfín oscuro (Lagenorhynchus obscurus)')] <- 'odontoceto'

dt$reino[dt$especie %in% c('Lobo marino de dos pelos no identificado (Arctocephalus sp.)', 'Lobo marino no identificado (Familia Otariidae)', 'Lobo marino de dos pelos sudamericano (Arctocephalus australis)', 'Lobo marino de un pelo sudamericano (Otaria flavescens)', 'Lobo marino de dos pelos antártico (Arctocephalus gazella)','Lobo marino de dos pelos sudamericano (Arctocephalusaustralis)')] <- 'pinipede'

dt$reino[dt$especie %in% c('Pingüino patagónico (Spheniscus magellanicus)', 'Pingüino no identificado (Familia Spheniscidae)', 'Cormorán Imperial (Phalacrocorax albiventer)', 'Pingüino penacho amarillo austral (Eudyptes chrysocome)', 'Pingüino rey (Aptenodytes patagonicus)')] <- 'penguin'

When I run the code for the first time came this warning:

Warning message: Unknown or uninitialised column: reino.

Then, I continue running the code, and the new column reino came with NA value only for Ballena franca austral (Eubalaena australis).

I tried to do these things, but didn’t work:

dt %>% left_join(data.frame(especie = c('Ballena franca austral (Eubalaena australis)', reino = c('misticeto'))))

and

mutate(reino = case_match(especie, 'Ballena franca austral (Eubalaena australis)' ~ 'misticeto'))

The second problem is that:

  • I noticed that one dolphin and one penguin came to the misticeto (whale) condition.
misticeto<-filter(dt, reino == "misticeto");misticeto

> table(misticeto$especie)

Ballena barbada no identificada (Parvorden Mysticeti)  Ballena barbada no identificada(Parvorden Mysticeti) 
                                                   23                                                     1 
                  Ballena fin (Balaenoptera physalus)          Ballena franca austral (Eubalaena australis) 
                                                    4                                                    33 
            Ballena jorobada (Megaptera novaeangliae)    Ballena rorcual no identificada (Balaenoptera sp.) 
                                                   13                                                     9 
                  Ballena sei (Balaenoptera borealis)               Delfín oscuro (Lagenorhynchus obscurus) 
                                                    8                                                     1 
               Pingüino rey (Aptenodytes patagonicus) 
                                                    1 

#The Delfín oscuro (Lagenorhynchus obscurus) and Pingüino rey (Aptenodytes patagonicus)  shouldn't be there.
  • And also, not all dolphins are going to the reino column, one is missing (who came to misticeto condition).
odontocetos<-filter(dt, reino == "odontoceto");odontocetos
> table(odontocetos$especie)

   Delfín austral (Lagenorhynchus australis) Delfín no identificado (Familia Delphinidae) 
                                          25                                           12 
  Tonina overa (Cephalorhynchus commersonii) 
                                           8 

#The dolphin that came to misticeto condition is missing here, 'Delfín oscuro (Lagenorhynchus obscurus)'

Someone can help me, please? I don’t understand what is happening.

Thanks!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật