R은 인수를 정수로 저장합니다. 따라서 동일한 기능을 사용할 때 서로 다른 레벨을 가진 두 요소가 같은 이름 인 경우이를 찾을 수 없습니다. 우리가 물체를 보면 FALSE
함수의 동작이 "일치"인 경우
는하지만, 그들은
y[1,]
portfolio_date security
10414 2000-10-31 Currency Euro (Fwd)
x
portfolio_date security
10414 2000-10-31 Currency Euro (Fwd)
가 궁극적으로 내가 할 수 있기를 원하는 사용자에게 동일하게 표시
y <- structure(list(portfolio_date = structure(c(1L, 1L, 1L, 2L, 2L,
2L), .Label = c("2000-10-31", "2001-04-30"), class = "factor"),
security = structure(c(2L, 2L, 1L, 3L, 2L, 4L), .Label = c("Currency Australia (Fwd)",
"Currency Euro (Fwd)", "Currency Japan (Fwd)", "Currency United Kingdom (Fwd)"
), class = "factor")), .Names = c("portfolio_date", "security"
), row.names = c(10414L, 10417L, 10424L, 21770L, 21771L, 21774L
), class = "data.frame")
x <- structure(list(portfolio_date = structure(1L, .Label = "2000-10-31", class = "factor"),
security = structure(1L, .Label = "Currency Euro (Fwd)", class = "factor")),
.Names = c("portfolio_date", "security"), row.names = 10414L, class = "data.frame")
identical(y[1,], x)
결과 : 여기
는 MWE입니다 다음과 같은 문자 :apply(y, 1, identical, x)
10414 10417 10424 21770 21771 21774
TRUE TRUE FALSE FALSE FALSE FALSE
which(apply(y, 1, identical, x))
1 2
어떻게해야합니까? 감사.
'동일 함 (물방울 (y [1,]), 물방울 (x))'아니면 아마도 all.equal (y [1,], x, check.attributes = F)' – user20650
사용해 주셔서 감사합니다. 동일하지 않은 물방울은 여전히 FALSE를 반환합니다. 또한, apply (y, 1, function (z) all.equal (z, x, check.attributes = F))에는 이상한 결과가 있습니다. – lilster
열을 문자로 변환해야합니다. 여기에 한 줄에 밑줄을 붙인 해결책이 있습니다 : apply (apply (y, 2, as.character), 1, 동일, apply (x, 2, as.character)) – Dave2e