2014-05-09 44 views
2

我創建兩個子集(data.frames)像這樣:使用與data.frame子View會將row.names列

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)

回答

4

View正在添加該列進行顯示。正如你所看到的,它並不在子集中。

help(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,所以這種行爲在那裏並不明顯。

+0

謝謝,但我不太明白你的答案。這兩個數據框應該是相同的,那麼爲什麼訓練數據不會顯示該列,但測試數據呢? – user1477388

+0

@ user1477388已編輯。 –

+0

@ user1477388他們沒有區別。如果您使用「視圖」,它們只會**顯示**。 – Roland

相關問題