I have a simple problem but I just don't know how to fix it. I have a dataframe like this:
structure(list(ID = c(1006332, 1010660,
1012960, 1013515, 1014490), ave_ocean = c(1, 0, 0, 0, 0), ave_price_per_sqft = c(1419.69,
912.18, 600.74, 673.8725, 439.46), ave_year = c(2005, 2009, 1986.4,
2006.25, 1983), ave_DOM = c(7, 10, 36.1, 10.5, 104), total_num_sold = c(1L,
1L, 10L, 4L, 1L)), row.names = c(NA, -5L), class = c("tbl_df",
"tbl", "data.frame"))
ID ave_ocean ave_price_per_sqft ave_year ave_DOM total_num_sold
<dbl> <dbl> <dbl> <dbl> <dbl> <int>
1 1006332 1 1420. 2005 7 1
2 1010660 0 912. 2009 10 1
3 1012960 0 601. 1986. 36.1 10
4 1013515 0 674. 2006. 10.5 4
5 1014490 0 439. 1983 104 1
I want to set column ID as row name and then remove it. I use the code below:
row.names(data) <- data$ID
data <-data[,-c(1)]
when I run this it first changes the row name and replaces it with ID but once I run the second line to remove "ID" column it changes row name to the normal row name! Any idea? Any alternative solution?