gpt4 book ai didi

r - 'row.names' 长度无效

转载 作者:行者123 更新时间:2023-12-05 00:32:16 25 4
gpt4 key购买 nike

我正在尝试使用 TraMineR(版本 1.8.4)seqdef-funciton 来定义序列对象,但我总是收到此错误消息,这对我来说毫无意义:row.names<-.data.frame 中的错误( *tmp* ,值 = 值):
无效的“row.names”长度

我的代码输入是:

sample.sts <- seqdef(sample, var=c("jan2005", "feb2005", "mar2005", "apr2005", "may2005", 
"jun2005", "jul2005", "aug2005", "sep2005", "oct2005", "nov2005", "dec2005"),
alphabet=c("Employee (full-time)", "Employee (part-time)",
"Self-employed (full-time)", "Self-employed (part-time)", "unemployed", "Retired",
"Student", "Other inactive", "Compulsory military service"),
states=c("EF", "EP", "SF", "SP", "UE", "RE", "ST", "IA", "MS"), id="pidc")

数据框“样本”如下所示:
    pidc           jan2005   feb2005    ...    dec2005   sex   edufirst   age05   
--------------------------------------------------------------------------
1. 150163920001 . . ... . 1 5 62
2. 211518110003 . . ... . 2 2 17
3. 170295160002 . . ... . 2 1 47
4. 240386550002 2 2 ... 2 2 2 50
5. 320099920001 . . ... . 1 3 38
--------------------------------------------------------------------------
6. 200167850001 . . ... . 1 5 39
7. 340401190002 6 6 ... 6 1 3 61
8. 180501260002 . . ... . 1 3 29
9. 230083560001 . . ... . 1 3 61
10. 240335270002 3 3 ... 3 2 3 30

整个输出说:

[!] found '-' character in states codes, not recommended
[>] found missing values ('NA') in sequence data
[>] preparing 3266 sequences
[>] coding void elements with '%' and missing values with '*'
[!] sequence with index: 1,2,3,...
[>] state coding:
[alphabet] [label] [long label]
1 Employee (full-time) EF EF
2 Employee (part-time) EP EP
3 Self-employed (full-time) SF SF
4 Self-employed (part-time) SP SP
5 unemployed UE UE
6 Retired RE RE
7 Student ST ST
8 Other inactive IA IA
9 Compulsory military service MS MS
[>] 3266 sequences in the data set
[>] min/max sequence length: 12/12
Fehler in row.names<-.data.frame(*tmp*, value = value) :
invalid 'row.names' length



我在没有“-”的情况下重新标记状态后重试,这不会影响错误。也许,有人可以帮助我并知道导致此错误的原因?

最佳答案

seqdef 的“id”参数应该是一个向量,每个序列包含一个条目(即 id 向量的长度应该等于序列的数量)。尝试使用 id=as.character(sample$pid)。你也可以试试 id=sample$pid (不带 as.character)

sample.sts <- seqdef(sample, var=c("jan2005", "feb2005", "mar2005", "apr2005", "may2005", "jun2005", "jul2005", "aug2005", "sep2005", "oct2005", "nov2005", "dec2005", "jan2006", "feb2006", "mar2006", "apr2006", "may2006",  "jun2006", "jul2006", "aug2006", "sep2006", "oct2006", "nov2006", "dec2006",  "jan2007", "feb2007", "mar2007", "apr2007", "may2007",  "jun2007", "jul2007", "aug2007", "sep2007", "oct2007", "nov2007", "dec2007", "jan2008", "feb2008", "mar2008", "apr2008", "may2008", "jun2008", "jul2008", "aug2008", "sep2008", "oct2008", "nov2008", "dec2008"),  alphabet=c("Employee (full-time)", "Employee (part-time)", "Self-employed (full-time)", "Self-employed (part-time)", "unemployed", "Retired", "Student", "Other inactive", "Compulsory military service"), states=c("EF", "EP", "SF", "SP", "UE", "RE", "ST", "IA", "MS"), d=as.character(sample$pid))

由于“-”被“.”替换,数据中的状态和字母表参数之间存在一些不匹配。您可能应该更改字母参数(尝试使用 seqstatl 函数找出数据中存在哪些状态标签)。

关于r - 'row.names' 长度无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13739666/

25 4 0