2012-06-06 23 views
0

可能重複:
Change the index number of a dataframe重新定義行數(指數)

我做各種操作與數據幀和排除的行數。 正如您在我的示例中看到的那樣,現在數據框以366開頭。 我想重新定義此行號爲1,當然還有以下索引號。

-> head(new_pred) 
pred_mean_temp pred_precipitation pred_visibility pred_wind 
366  -0.4707149   156.00677  260.24943 12.006212 
367  3.3950894   85.07009  28.66573 12.618096 
368  0.9394914   276.67157  12.39165 8.249188 
369  -2.9786171   147.03749  10.21351 7.432625 
370  -3.5502385   24.66432  16.59086 13.495728 
371  -4.2262573   37.21946  17.51434 9.309708 

所以它看起來就像這樣:

-> head(new_pred) 
pred_mean_temp pred_precipitation pred_visibility pred_wind 
1  -0.4707149   156.00677  260.24943 12.006212 
2  3.3950894   85.07009  28.66573 12.618096 
etc. 

最好的感謝!

回答

0

解決方法很簡單:

dimnames(new_pred)[[1]]<-seq_len(nrow(new_pred)) 
0

rownames(new_pred) <- seq(nrow(new_pred))比較簡單,而且rownames(x) <- NULL是簡單一些。