i am facing an issue in converting the data frame of the data to desired data in which dates should come in as index. My data file has two columns - Date & Price
Am executing the following code-
data<- read.csv(" file path", header=T)
I want my final format of data frame : where my dates are index side & only one column of Price is there
I can convert the data frame into this format through Python, but am not able to do so in R.
is there is a simple command to do in R, as in the case of python
Kindly show a way to do so.
If you mean that you want Date
values to be rownames, that's not usually a good idea, but it depends on what you want to do with Price
.
To make the Date
column into rownames, you can use
Data <- row.names(Data$Date)
Avoid using data
or df
as variable names because they are built-ins and some operations treat your object of those names as closures and throw an error.
Sorry, I forgot to clarify earlier. Actually, i will be doing ARIMA modelling on this dataset. It is the price of a stock on a particular day. So I want my dataset to be in a time-series format where I will have only on column as price & dates as my row index. It's because then I can plot my dataset using dates/years on x-axis. Basically i want to have my data in this format-
There is also one more thing , as of now when i am importing my data in R. The date column is "chr" type.
Thanks for the tip, i would be not using df or data from now onwards.
Kindly help me in my problem, i hope that i have explained my question.
For time series, forget about the date, column, just
myts <- ts(DF$Price, start = c(year,month), frequently = 12)
Thanks for your reply, it cleared my doubt.
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.