Using R, how do I make a column of a dataframe the dataframe\'s index? Lets assume I read in my data from a .csv file. One of the columns is called \'Date\' and I want to ma
The tidyverse solution:
library(tidyverse)
df %>% column_to_rownames(., var = "Date")
I assume that by "Index" you mean row names. You can assign to the row names vector:
rownames(df) <- df$Date
The index can be set while reading the data, in both pandas and R.
In pandas:
import pandas as pd
df = pd.read_csv('/mydata.csv', index_col="Date")
In R:
df <- read.csv("/mydata.csv", header=TRUE, row.names="Date")