我正在尝试使用R中的“多样性”功能获取blau指数。 但是,我使用下面我认为可以的代码和数据不断出现错误。
library(reshape2)
library(MASS)
library(proxy)
library(foreign)
library(diverse)
> diversity(data1999[,2:5], type = "blau")
Error in X[cbind(data[, 5], data[, 4])] <- data[, 3] :
subscript out of bounds
在data1999中,无论是否有缺失值,我都会得到该错误。 换句话说,即使我删除了包含缺失数据的行,上面的错误也是一样。
缺少值的data1999如下:
Time ID X Gen Nationality
12/1/1999 34949256 53 M American
12/1/1999 34949256 59 M American
12/1/1999 34949256 67 M American
12/1/1999 34949256 60 M American
12/1/1999 34949256 58 M American
12/1/1999 34949256 54 M
12/1/1999 34949256 57 M American
12/1/1999 34949256 60 M
12/1/1999 34949256 46 F American
12/1/1999 34949256 57 M American
12/1/1999 34949256 65 M American
12/1/1999 34949256 66 M American
12/1/1999 394711590 60 M American
12/1/1999 394711590 48 M American
12/1/1999 394711590 70 F American
12/1/1999 394711590 68 M Canadian
12/1/1999 394711590 64 M American
12/1/1999 394711590 68 M American
12/1/1999 394711590 51 M American
12/1/1999 394711590 66 M American
12/1/1999 394711590 53 M American
12/1/1999 394711590 72 F American
12/1/1999 394711590 64 M American
12/1/1999 394711590 69 M American
12/1/1999 394711590 64 M
12/1/1999 394711590 59 M Danish
12/1/1999 401211899 61 M American
12/1/1999 401211899 67 M American
12/1/1999 401211899 61 M American
12/1/1999 401211899 44 M American
12/1/1999 401211899 74 M American
12/1/1999 401211899 61 M American
12/1/1999 401211899 54 M American
12/1/1999 401211899 42 M American
12/1/1999 401211899 79 M American
12/1/1999 401211899 60 M American
12/1/1999 401211899 77 M American
12/1/1999 401211899 66 M American
12/1/1999 401211899 64 M Canadian
12/1/1999 401211899 50 F American
12/1/1999 401211899 70 M American
12/1/1999 401211899 65 F American
12/1/1999 401211899 80 M American
12/1/1999 401211899 60 M American
12/1/1999 401211899 70 M American
12/1/1999 78638977 64 M American
12/1/1999 78638977 55 M American
12/1/1999 78638977 52 M American
12/1/1999 78638977 58 F American
12/1/1999 78638977 61 M American
12/1/1999 78638977 66 M American
12/1/1999 78638977 57 M American
12/1/1999 78638977 68 M American
12/1/1999 78638977 61 M American
12/1/1999 78638977 58 M American
12/1/1999 78638977 48 M American
12/1/1999 78638977 68 M
12/1/1999 78638977 61 F American
12/1/1999 78638977 67 M American
12/1/1999 78638977 58 M American
12/1/1999 78638977 68 M American
12/1/1999 78638977 60 F American
12/1/1999 78638977 64 M
12/1/1999 78638977 64 F American
12/1/1999 78638977 68 M American
12/1/1999 78859127 58 M American
12/1/1999 78859127 47 M American
12/1/1999 78859127 54 M American
12/1/1999 78859127 40 M American
12/1/1999 78859127 54 M American
12/1/1999 78859127 66 M American
12/1/1999 78859127 54 M American
12/1/1999 78859127 58 M American
12/1/1999 78859127 68 M American
12/1/1999 78859127 51 M American
12/1/1999 78859127 58 M American
12/1/1999 78859127 56 F American
12/1/1999 78859127 59 M American
12/1/1999 78859127 67 M American
12/1/1999 78859127 67 M American
12/1/1999 64658968 58 M American
12/1/1999 64658968 59 M
12/1/1999 64658968 53 M American
12/1/1999 64658968 54 M American
12/1/1999 64658968 58 M American
12/1/1999 64658968 49 M American
12/1/1999 64658968 46 M American
12/1/1999 64658968 65 F American
12/1/1999 64658968 60 M American
12/1/1999 64658968 56 M American
12/1/1999 64658968 64 M American
12/1/1999 64658968 66 M American
12/1/1999 64658968 50 M American
12/1/1999 677010831 51 M American
12/1/1999 677010831 62 M American
12/1/1999 677010831 58 M American
12/1/1999 677010831 64 M American
12/1/1999 677010831 59 M American
12/1/1999 677010831 59 M American
12/1/1999 677010831 59 M American
12/1/1999 677010831 49 M American
12/1/1999 677010831 56 M American
12/1/1999 677010831 64 M American
12/1/1999 677010831 50 M
12/1/1999 677010831 69 M American
12/1/1999 677010831 66 M American
12/1/1999 677010831 69 M American
12/1/1999 677010831 59 M American
12/1/1999 677010831 64 M
12/1/1999 677010831 57 F American
12/1/1999 677010831 65 M American
12/1/1999 677010831 69 M American
12/1/1999 677010831 67 M
12/1/1999 677010831 64 M American
12/1/1999 1089311274 57 M American
12/1/1999 1089311274 47 M American
12/1/1999 1089311274 65 M American
12/1/1999 1089311274 47 F American
12/1/1999 1089311274 52 M American
12/1/1999 1089311274 60 M American
12/1/1999 1089311274 58 M American
12/1/1999 1089311274 48 F American
12/1/1999 1089311274 61 M American
12/1/1999 1089311274 59 M American
12/1/1999 1089311274 56 M
12/1/1999 1089311274 64 M Swiss
12/1/1999 1089311274 69 M American
12/1/1999 1089311274 56 M American
12/1/1999 1089311274 67 M American
12/1/1999 1089311274 71 M American
12/1/1999 1109612440 61 M American
12/1/1999 1109612440 66 M American
12/1/1999 1109612440 61 M American
12/1/1999 1109612440 60 M American
12/1/1999 1109612440 54 M
12/1/1999 1109612440 60 M American
12/1/1999 1109612440 67 M American
12/1/1999 1109612440 61 M American
12/1/1999 1109612440 64 M
12/1/1999 1109612440 56 M American
12/1/1999 1109612440 51 M American
12/1/1999 1109612440 86 M American
12/1/1999 1109612440 74 M American
12/1/1999 1109612440 60 F American
12/1/1999 1109612440 70 M American
12/1/1999 1109612440 63 M American
12/1/1999 1109612440 61 M Belgian
12/1/1999 1109612440 65 M American
12/1/1999 1109612440 65 M
12/1/1999 12251873 54 M American
12/1/1999 12251873 67 M
12/1/1999 12251873 55 M American
12/1/1999 12251873 58 M
12/1/1999 12251873 66 M
12/1/1999 12251873 56 M American
12/1/1999 12251873 54 M American
12/1/1999 12251873 68 M
12/1/1999 12251873 59 M American
12/1/1999 12251873 62 M
12/1/1999 12251873 52 M American
12/1/1999 12251873 66 M
12/1/1999 12251873 60 M American
12/1/1999 12251873 60 M American
12/1/1999 12251873 55 M American
12/1/1999 12251873 52 M
12/1/1999 12251873 67 M
12/1/1999 12251873 64 M American
12/1/1999 12251873 68 M
12/1/1999 12251873 50 M American
12/1/1999 12251873 67 M American
12/1/1999 12251873 64 M
12/1/1999 12251873 59 F American
12/1/1999 12251873 65 M American
12/1/1999 175415595 54 M Brazilian
12/1/1999 175415595 54 M American
12/1/1999 175415595 57 M American
12/1/1999 175415595 60 M American
12/1/1999 175415595 63 M American
12/1/1999 175415595 61 M American
12/1/1999 175415595 52 M American
12/1/1999 175415595 53 M American
12/1/1999 175415595 68 F American
12/1/1999 175415595 59 F American
12/1/1999 175415595 52 M American
12/1/1999 175415595 44 M American
12/1/1999 175415595 47 M American
12/1/1999 175415595 60 M American
12/1/1999 175415595 57 M American
12/1/1999 175415595 47 M American
12/1/1999 175415595 65 M American
12/1/1999 175415595 61 M American
12/1/1999 175415595 56 M
12/1/1999 175415595 52 M American
12/1/1999 175415595 63 M American
12/1/1999 175415595 53 F American
12/1/1999 175415595 54 M American
12/1/1999 175415595 61 M American
12/1/1999 44384416 52 M American
12/1/1999 44384416 64 M American
12/1/1999 44384416 57 M American
12/1/1999 44384416 53 M American
12/1/1999 44384416 55 M American
12/1/1999 44384416 54 M American
12/1/1999 44384416 54 M American
12/1/1999 44384416 80 M American
12/1/1999 44384416 65 M American
12/1/1999 44384416 59 M British
12/1/1999 44384416 71 M American
12/1/1999 44384416 66 M American
12/1/1999 2673912732 48 M American
12/1/1999 2673912732 57 M American
12/1/1999 2673912732 60 M American
12/1/1999 2673912732 64 M British
12/1/1999 2673912732 59 M American
12/1/1999 2673912732 64 M
12/1/1999 2673912732 61 M American
12/1/1999 2673912732 58 M American
12/1/1999 2673912732 57 M American
12/1/1999 2673912732 64 M American
12/1/1999 2673912732 59 M British
12/1/1999 2673912732 72 M American
12/1/1999 2673912732 58 F American
12/1/1999 2673912732 64 M American
12/1/1999 2698412879 66 M American
12/1/1999 2698412879 58 M American
12/1/1999 2698412879 66 M American
12/1/1999 2698412879 60 M American
12/1/1999 2698412879 64 M American
12/1/1999 2698412879 51 M American
12/1/1999 2698412879 37 M
12/1/1999 274882235 60 M American
12/1/1999 274882235 61 M American
12/1/1999 274882235 65 F Australian
12/1/1999 274882235 67 M American
12/1/1999 274882235 65 M American
12/1/1999 274882235 66 M American
12/1/1999 274882235 68 M American
12/1/1999 274882235 70 M American
12/1/1999 274882235 58 F American
12/1/1999 274882235 67 M
12/1/1999 274882235 69 M American
12/1/1999 422076955 50 M American
12/1/1999 422076955 45 M
12/1/1999 422076955 70 M American
12/1/1999 422076955 67 M American
12/1/1999 422076955 61 M American
12/1/1999 422076955 44 M American
12/1/1999 422076955 55 M American
12/1/1999 422076955 71 M American
12/1/1999 422076955 38 F American
12/1/1999 422076955 60 M American
12/1/1999 422076955 64 M American
12/1/1999 422076955 54 F
12/1/1999 422076955 63 F American
12/1/1999 422076955 57 M American
12/1/1999 422076955 66 M American
12/1/1999 422076955 57 M American
12/1/1999 422076955 57 M American
12/1/1999 423917141 51 M American
12/1/1999 423917141 56 M American
12/1/1999 423917141 57 M American
12/1/1999 423917141 58 M American
12/1/1999 423917141 67 M American
12/1/1999 423917141 64 M American
12/1/1999 423917141 64 M
12/1/1999 423917141 55 F American
12/1/1999 423917141 68 M American
12/1/1999 423917141 61 F American
12/1/1999 423917141 58 M
12/1/1999 423917141 50 F American
12/1/1999 423917141 64 M Chinese
12/1/1999 423917141 60 M American
12/1/1999 423917141 64 M American
12/1/1999 423917141 53 F American
12/1/1999 423917141 57 M American
12/1/1999 423917141 53 F American
12/1/1999 423917141 68 M American
12/1/1999 423917141 70 M American
12/1/1999 423917141 56 M American
12/1/1999 423917141 61 M American
12/1/1999 423917141 59 M American
12/1/1999 423917141 67 M American
答案 0 :(得分:1)
摘自diverse
的文档:
参数“ data”也接受一个包含三列的数据框 顺序如下:实体,类别和值。
因此,当给定一个数据框时,它期望三个而只有三个列。通过放置data1999[,2:5]
,您将选择四列,此功能根本无法很好地处理(在这种情况下,更有意义的错误会很大……)
尝试diversity(data1999[,2:4], type="blau")
或diversity(data1999[,3:5], type="blau")
,您会得到想要的(我希望我无法解释其中的任何内容)。