我创建两个子集(data.frames),如下所示:
sms_raw_train <- sms_raw[1:4169, ]
sms_raw_test <- sms_raw[4170:5559, ]
第一个 sms_raw_train
如下所示:
type text
1 ham Hope you are having a good week. Just checking in
2 ham K..give back my thanks.
3 ham Am also doing in cbe only. But have to pay.
第二个,sms_raw_test
,看起来像这样:
row.names type text
1 4170 ham I'm coming home 4 dinner.
2 4171 ham Come by our room at some point so we can iron out the plan for this weekend
3 4172 ham Its sunny in california. The weather's just cool
如您所见,它添加了一个 row.names
列。但是,如果我这样做:
> str(sms_raw_test[1:3, ])
'data.frame': 3 obs. of 2 variables:
$ type: Factor w/ 2 levels "ham","spam": 1 1 1
$ text: chr "I'm coming home 4 dinner." "Come by our room at some point so we can iron out the plan for this weekend" "Its sunny in california. The weather's just cool"
该列实际上并不存在。
本专栏的目的是什么?为什么将其添加到 View(sms_raw_train)
中?
最佳答案
View
正在添加该列以进行显示。正如您所看到的,它实际上并不存在于子集中。
来自帮助(查看)
:
If there are row names on the data frame that are not 1:nrow, they are displayed in a separate first column called row.names.
sms_raw_data
的行名称(大概是)4170:5559
。
sms_raw_train
的行名称是 1:nrow
,因此这种行为在那里并不明显。
关于r - 将 View 与 data.frame 子集结合使用会添加 row.names 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23566691/