seq_len出错

时间:2015-10-25 21:05:07

标签: r

我有以下data.frame:

> head (data)
                                                             verb_object SESSION_ID transactionID sequenceID eventID items
1:                               34D89F927092290A5DA9B108F7020C19 SELECT   36652675          2058   36652675       1   OV1
2: 15873DB37BF80750C70B68A8778B9DC01D548B6D06E3BF92CADAFF289B3FCAEE CALL   38763251            90   38763251       1   OV2
3: D6941F85A1763F1F2D27B8F032D6411C86D4A5200512D65F381052C7D42BF57F CALL   40257471            63   40257471       1   OV3
4:                               E768D36C813FD14157B06474F345EAFC SELECT   40897086         39475   40897086       1   OV4
5: 15873DB37BF80750C70B68A8778B9DC01D548B6D06E3BF92CADAFF289B3FCAEE CALL   40907760            57   40907760       1   OV2
6:                               8067DE5FF5089BE6EC9D213F42525FC3 SELECT   40928334         29697   40928334       1   OV5

当我运行以下命令时:

> data <- data[, -(1:2)]
> rownames(data) <- as.character (seq_len(nrow(data)) )
Error in seq_len(nrow(data)) : 
  argument must be coercible to non-negative integer
In addition: Warning message:
In seq_len(nrow(data)) : first element used of 'length.out' argument

为什么?不同计算机中相同数据的另一个用户没有得到它。

1 个答案:

答案 0 :(得分:6)

感谢@Richard Scriven: 使用时

> setDF(data)
> data <- data[, -(1:2)]
> rownames(data) <- as.character (seq_len(nrow(data)) )

我得到了所需的结果:

> head (data)
  transactionID sequenceID eventID items
1          2058   36652675       1   OV1
2            90   38763251       1   OV2
3            63   40257471       1   OV3
4         39475   40897086       1   OV4
5            57   40907760       1   OV2
6         29697   40928334       1   OV5