1
我有两个向量,一个来自sqldf(),另一个来自unique()。它们应该是相同的。当我使用for循环来检查每个元素时,这两个向量是相同的,但两个向量的相同()返回FALSE。有任何想法吗?所有元素都相同,但不完全相同?
options(sqldf.driver = "SQLite")
options(gsubfn.engine = "R")
library(sqldf)
url <-"https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06pid.csv"
download.file(url, destfile = "CommunitySurvey.csv")
acs <- read.table("CommunitySurvey.csv", sep = ",", header = TRUE)
query <- as.matrix(sqldf("select distinct AGEP from acs"))
unique <- as.matrix(unique(acs$AGEP))
for (i in 1:dim(unique)[1]){
if (unique[i]!=query[i]){
print(unique[i])
print(query[i])
}
}
identical(query, unique)
谢谢,它解决了我的问题! –