How to change row index into a column

I have a data set with one column as movie_views and having row index as movie_name. Please refer the image.
image

So I want to convert the row index into a column how can I do that?

or It is possible to get name of the movie with max views without converting row index to a column?

You can use tibble::rownames_to_column().

library(tibble)

movie_data <- data.frame(Movie_views = c(1, 1, 1, 2, 29),
                         row.names = c("Movie1", "Movie2", "Movie3", "Movie4", "Movie5"))


rownames_to_column(movie_data)
#>   rowname Movie_views
#> 1  Movie1           1
#> 2  Movie2           1
#> 3  Movie3           1
#> 4  Movie4           2
#> 5  Movie5          29

Created on 2020-05-29 by the reprex package (v0.3.0)

2 Likes

Thank You.. Its working..

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.