0

Possible Duplicate:
Change the index number of a dataframe

I did various operations with a dataframe and excluded a number of rows. As you see in my example the dataframe now starts with 366. I would like to redefine this row number back to 1 and of course the following index numbers.

 -> 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

so it will look like this:

-> 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.

best thanks!

Community
  • 1
  • 1
Fabian Stolz
  • 1,935
  • 7
  • 27
  • 30

2 Answers2

0

Solution is simple:

 dimnames(new_pred)[[1]]<-seq_len(nrow(new_pred))
Fabian Stolz
  • 1,935
  • 7
  • 27
  • 30
0

rownames(new_pred) <- seq(nrow(new_pred)) is simpler, and rownames(x) <- NULL is simpler still.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418