xts coding error

Hello to R language Professionals.
I am new to this language. a part of my paper needs this language. i wanted to run Hamilton Filter but softwares ignore to run the codes and stress on changing the data type to xts one!
actually i calculated my data on Excel for a panel of 25 countries and saved on my drive as a csv file.
time period for each country is: 1960 to 2018.
how should i treat with this code below:

df <- read.csv("E:/PhD Essay/Papers from my essay/Mofid/codes/Business cycle filter/Hamilton Filter/R Code/RGDP.csv", header=TRUE, sep=",")
library(xts)
RGDP <- 100*log(xts::to.quarterly(df1["1960/2018-6"], OHLC = FALSE))

the error is below:

Error in [.data.frame(df, "1960/2018-6") : undefined columns selected

please help me to fix the problem

1 Like

You can turn a dataframe into an xts using as.xts(df).
The rownames of the data frame must be the times of the data.

library(tidyverse)
df <- df %>%
   column_to_rownames("time")  
myxts <- as.xts(df)
1 Like

Hello.
thank you for your attention.
Is it possible for you to see my data and make a Proportional code for me?

I can not undrestand the xts function.

please help me if you can.

the data is uploaded in csv file below.

I run the code and get the error below: :disappointed: :disappointed: :sob:

library(tidyverse)

df <- df %>%

  • column_to_rownames("year")  
    

Error in .rowNamesDF<-(x, value = value) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘1960’, ‘1961’, ‘1962’, ‘1963’, ‘1964’, ‘1965’, ‘1966’, ‘1967’, ‘1968’, ‘1969’, ‘1970’, ‘1971’, ‘1972’, ‘1973’, ‘1974’, ‘1975’, ‘1976’, ‘1977’, ‘1978’, ‘1979’, ‘1980’, ‘1981’, ‘1982’, ‘1983’, ‘1984’, ‘1985’, ‘1986’, ‘1987’, ‘1988’, ‘1989’, ‘1990’, ‘1991’, ‘1992’, ‘1993’, ‘1994’, ‘1995’, ‘1996’, ‘1997’, ‘1998’, ‘1999’, ‘2000’, ‘2001’, ‘2002’, ‘2003’, ‘2004’, ‘2005’, ‘2006’, ‘2007’, ‘2008’, ‘2009’, ‘2010’, ‘2011’, ‘2012’, ‘2013’, ‘2014’, ‘2015’, ‘2016’, ‘2017’, ‘2018’

myxts <- as.xts(df)
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format

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