kintela
kintela

Reputation: 1323

arrange delete the data frame row names

I have this dataframe data frame

When I try to arrange it to create a ranking variable

df_tablaCruzada<-df_tablaCruzada%>%
arrange(desc(Total)) %>%
mutate(Ranking=1:nrow(df_tablaCruzada))

I get the data frame arranged and the ranking variable is fine but I have lost the original row names arrange

Any idea, please?

regards

Upvotes: 0

Views: 195

Answers (1)

Bruno
Bruno

Reputation: 4151

Dplyr does't support row.names you may want to use tibble::rownames_to_column()

Example

mtcars %>% 
  tibble::rownames_to_column()

In your case this should work

df_tablaCruzada<-df_tablaCruzada%>%
  tibble::rownames_to_column() %>% 
  arrange(desc(Total)) %>%
  mutate(Ranking=1:nrow(df_tablaCruzada))

you can also use the add_row function of dplyr to replace the mutate in this case

Upvotes: 1

Related Questions