我正在尝试创建一个与数据框匹配的新列,但我只能得到NA。
我的输入看起来像这样:
input = structure(list(V1 = c("Stan-USA", "Stan-EUR", "Mike", "Mike & Stan",
"Stan-EUR", "Mike", "Stan-EUR", "Mike", "Mike & Stan", "Mike & Stan",
"Mike & Stan", "Stan-USA"), V2 = c(8L, 86L, 32L, 14L, 12L, 37L,
36L, 22L, 49L, 93L, 52L, 44L)), class = "data.frame", row.names = c(NA,
-12L))
我正在尝试获得这样的输出:
output = structure(list(V1 = c("Stan-USA", "Stan-EUR", "Mike", "Mike & Stan",
"Stan-EUR", "Mike", "Stan-EUR", "Mike", "Mike & Stan", "Mike & Stan",
"Mike & Stan", "Stan-USA"), V2 = c(8L, 86L, 32L, 14L, 12L, 37L,
36L, 22L, 49L, 93L, 52L, 44L), V3 = c("International", "International",
"Asia", "Global", "International", "Asia", "International", "Asia",
"Global", "Global", "Global", "International")), class = "data.frame", row.names = c(NA,
-12L))
我要匹配的数据帧如下:
matches = structure(c("Mike", "Stan-EUR", "Stan-USA", "Mike & Stan", "FM",
"International", "International", "Global"), .Dim = c(4L, 2L), .Dimnames = list(NULL, c("Employee", "Area")))
我正在使用它来尝试创建其他列:
input$Area = matches[as.character(input$V1)]
但是我在新列中得到的只是NAs
有人可以看到我在做什么吗?