join from dplyr package produces NA results in the new column

When I produce left_join (left_join from package dplyr) of the below given data frames , the result (ie,)the new column after the join tends to be NA.

The columns 'V1','V1_1','V1_2','V1_3' are factors from data frames "df1" and "df2" respectively. By converting them to characters following warning message was removed which had occurred earlier.

Warning message:

In left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y) : joining character vector and factor, coercing into character vector

Yet after removing warnings and clean run of the code, new column after join produces NA. I am not able to rectify what is going wrong . Any sort of help is appreciated.

df1

  V1    V2
A415Z   1.01
A415J   0.91
B416X   0.95
B416Z   0.97
B416J   1.03
B416M   1.16
B416P  11.75
B416W   0.98
D420R   0.98
D420H   0.94
D420Z   1.01
D420J   1.01
D420F   0.90
D420L   1.00
C462H   0.93
C462P   0.83
C462W   0.73

df2

 V1_1  V1_2  V1_3
A415Z B416P D420R
A415Z B416P D420H
A415Z B416P D420Z
A415Z B416P D420J
A415Z B416P D420F
A415Z B416P D420L
A415Z B416P C462H
A415Z B416P C462P
A415Z B416P C462W
A415J B416P D420R
A415J B416P D420H
A415J B416P D420Z
A415J B416P D420J
A415J B416P D420F
A415J B416P D420L
A415J B416P C462H
A415J B416P C462P
A415J B416P C462W
B416P D420R C462H
B416P D420R C462P
B416P D420R C462W
B416P D420H C462H
B416P D420H C462P
B416P D420H C462W
B416P D420Z C462H
B416P D420Z C462P
B416P D420Z C462W
B416P D420J C462H
B416P D420J C462P
B416P D420J C462W
B416P D420F C462H
B416P D420F C462P
B416P D420F C462W
B416P D420L C462H
B416P D420L C462P
B416P D420L C462W

code:

library(dplyr)

newdf<-left_join(df2,df1,by=c("V1_1"="V1"))

output

   V1_1  V1_2  V1_3 V2
  A415Z B416P D420R NA
  A415Z B416P D420H NA
  A415Z B416P D420Z NA
  A415Z B416P D420J NA
  A415Z B416P D420F NA
  A415Z B416P D420L NA
  A415Z B416P C462H NA
  A415Z B416P C462P NA
  A415Z B416P C462W NA
  A415J B416P D420R NA
  A415J B416P D420H NA
  A415J B416P D420Z NA
  A415J B416P D420J NA
  A415J B416P D420F NA
  A415J B416P D420L NA
  A415J B416P C462H NA
  A415J B416P C462P NA
  A415J B416P C462W NA
  B416P D420R C462H NA
  B416P D420R C462P NA
  B416P D420R C462W NA
  B416P D420H C462H NA
  B416P D420H C462P NA
  B416P D420H C462W NA
  B416P D420Z C462H NA
  B416P D420Z C462P NA
  B416P D420Z C462W NA
  B416P D420J C462H NA
  B416P D420J C462P NA
  B416P D420J C462W NA
  B416P D420F C462H NA
  B416P D420F C462P NA
  B416P D420F C462W NA
  B416P D420L C462H NA
  B416P D420L C462P NA
  B416P D420L C462W NA

Desired output should contain the column V2 from "df1" values adjoined to the "df2".

链接地址: http://www.djcxy.com/p/30938.html

上一篇: 用ggplot2将多个y值绘制为单独的行的正确方法

下一篇: 来自dplyr包的连接在新列中产生NA结果