使用R,我该如何创建一个数据帧的列作为数据框的索引?让我们假设我从.csv文件中读取数据。其中一列称为“日期”,我想将该列作为我的数据框的索引。设置一个数据帧列作为R data.frame对象的索引
例如在Python中,NumPy,Pandas;我会做以下几点:
df = pd.read_csv('/mydata.csv')
d = df.set_index('Date')
现在我该怎么做在R?
我试着在R:
df <- read.csv("/mydata.csv")
d <- data.frame(V1=df['Date'])
# or
d <- data.frame(Index=df['Date'])
# but these just make a new dataframe with one 'Date' column.
#The Index is still 0,1,2,3... and not my Dates.
你可能想使用'data.table'? http://cran.r-project.org/web/packages/data.table/index.html –
你所说的'index'可能是'row.names',所以'row.names(d)< - df ['Date']' – Ananta