gpt4 book ai didi

r - 使用 R 中的 "diversity"函数的 blau 索引的下标错误

转载 作者:行者123 更新时间:2023-12-02 02:49:23 25 4
gpt4 key购买 nike

我正在尝试使用 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

最佳答案

来自diverse的文档:

The argument "data", also accepts a dataframe with three columns in the following order: entity, category and value.

因此,当给定一个数据框时,它需要三列并且只有三列。通过放置 data1999[,2:5] 你选择了四列,这个函数根本不能很好地处理它们(在这种情况下更有意义的错误会很好......)

试试 diversity(data1999[,2:4], type="blau")diversity(data1999[,3:5], type="blau") 然后你会得到你想要的(我希望,我无法解释其中的任何内容)。

关于r - 使用 R 中的 "diversity"函数的 blau 索引的下标错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52919913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com