我有两个数据框架。df1:
年度渔获量 | 101 | 2500 |
---|---|
101 | 1759 |
116 | 111 |
139 | 178 |
library(dplyr)
df1 <-
structure(list(Species = c(101L, 101L, 116L, 139L), Catch.by.Year = c(2500L,
1759L, 111L, 178L)), row.names = c(NA, -4L), class = c("tbl_df",
"tbl", "data.frame"))
df2 <-
structure(list(code = c(101L, 116L, 139L, 144L), name = c("COD",
"YELLOWTAIL", "BLUE ANTIMORA", "CUSK")), row.names = c(NA, -4L
), class = c("tbl_df", "tbl", "data.frame"))
df1 %>%
inner_join(df2,by = c("Species" = "code")) %>%
select(-Species) %>%
select(Species = name,Catch.by.Year)
# A tibble: 4 x 2
Species Catch.by.Year
<chr> <int>
1 COD 2500
2 COD 1759
3 YELLOWTAIL 111
4 BLUE ANTIMORA 178