1
我是R的新手,並且學習了子集數據的幾種方法。我在使用郵編設置的餐廳數據(RestData)中的下面的匹配數量上存在差異。R中的子集使用%與%返回不同的值與==運算符
> nrow(restData[restData$zipCode %in% c("21212","21213"),])
# [1] 59
> nrow(restData[restData$zipCode == c("21212","21213"),])
# [1] 26
>Warning message:
In restData$zipCode == c("21212", "21213") :
longer object length is not a multiple of shorter object length
我使用下面的數據集的情況下,要複製
fileURL <- "https://data.baltimorecity.gov/api/views/k5ry-ef3g/rows.csv?accessType=DOWNLOAD"
download.file(fileURL, destfile = "./Rdata/restaurants.csv", method = "curl")
restData <- read.csv("./Rdata/restaurants.csv")
你有沒有做過任何搜索?????????? –
你也可以做一些試驗:'x = 1:5; %(c)(1,3); x == c(1,3); x == c(3,1); x == 1; x == 3; x == 1 | X == 3; x [x%in%c(1,3)]; x [x == c(3,1)]'等 – eipi10
我明白你的意思了,謝謝 – Nico