У меня проблемы с соединением таблиц с dplyr::left_join
. Я создал следующий data.frame:
conservation <- structure(list(conservation1 = c("EX ", "EW ", "CR ", "EN ",
"VU ", "NT ", "LC ", "DD ", "NE ", "PE ", "PEW "), description = c(" Extinct",
" Extinct em the wild", " Critically Endangered", " Endangered",
" Vulnerable", " Near Threatened", " Least Concern", " Data deficient",
" Not evaluated", " Probably extinct (informal)", " Probably extinct em the wild (informal)"
)), class = "data.frame", row.names = c(NA, -11L))
Я хочу добавить его в сохранение msleep из ggplot2, чтобы получить сохранение msleep с описанием.
Переменные msleep, которые я рассматриваю, следующие:
msleep <- structure(list(name = c("Cheetah", "Owl monkey", "Mountain beaver",
"Greater short-tailed shrew", "Cow", "Three-toed sloth", "Northern fur seal",
"Vesper mouse", "Dog", "Roe deer", "Goat", "Guinea pig", "Grivet",
"Chinchilla", "Star-nosed mole", "African giant pouched rat",
"Lesser short-tailed shrew", "Long-nosed armadillo", "Tree hyrax",
"North American Opossum", "Asian elephant", "Big brown bat",
"Horse", "Donkey", "European hedgehog", "Patas monkey", "Western american chipmunk",
"Domestic cat", "Galago", "Giraffe", "Pilot whale", "Gray seal",
"Gray hyrax", "Human", "Mongoose lemur", "African elephant",
"Thick-tailed opposum", "Macaque", "Mongolian gerbil", "Golden hamster",
"Vole ", "House mouse", "Little brown bat", "Round-tailed muskrat",
"Slow loris", "Degu", "Northern grasshopper mouse", "Rabbit",
"Sheep", "Chimpanzee", "Tiger", "Jaguar", "Lion", "Baboon", "Desert hedgehog",
"Potto", "Deer mouse", "Phalanger", "Caspian seal", "Common porpoise",
"Potoroo", "Giant armadillo", "Rock hyrax", "Laboratory rat",
"African striped mouse", "Squirrel monkey", "Eastern american mole",
"Cotton rat", "Mole rat", "Arctic ground squirrel", "Thirteen-lined ground squirrel",
"Golden-mantled ground squirrel", "Musk shrew", "Pig", "Short-nosed echidna",
"Eastern american chipmunk", "Brazilian tapir", "Tenrec", "Tree shrew",
"Bottle-nosed dolphin", "Genet", "Arctic fox", "Red fox"), conservation = c("lc",
NA, "nt", "lc", "domesticated", NA, "vu", NA, "domesticated",
"lc", "lc", "domesticated", "lc", "domesticated", "lc", NA, "lc",
"lc", "lc", "lc", "en", "lc", "domesticated", "domesticated",
"lc", "lc", NA, "domesticated", NA, "cd", "cd", "lc", "lc", NA,
"vu", "vu", "lc", NA, "lc", "en", NA, "nt", NA, "nt", NA, "lc",
"lc", "domesticated", "domesticated", NA, "en", "nt", "vu", NA,
"lc", "lc", NA, NA, "vu", "vu", NA, "en", "lc", "lc", NA, NA,
"lc", NA, NA, "lc", "lc", "lc", NA, "domesticated", NA, NA, "vu",
NA, NA, NA, NA, NA, NA)), row.names = c(NA, -83L), class = c("tbl_df",
"tbl", "data.frame"))
Для достижения цели я применяю:
msleep %>%
select(name, conservation) %>%
mutate(conservation = toupper(conservation)) %>%
left_join(conservation1, by = c('conservation'='conservation1'))
Моя интуиция подсказывает, что это может сработать, однако , результаты для столбца описания дают мне недостающие значения. Кто-нибудь может мне помочь ? Я новый пользователь dplyr. Я очень ценю любую помощь.