Here is my code:
for (x in col_names){
time_series <- ts(df3$x, frequency=1, start = df3$index[1])
}
When I run this I get the following error:
Error in ts(df3$x, frequency = 1, start = df3$index[1]): 'ts' object must have one or more observations
Traceback:
1. ts(df3$x, frequency = 1, start = df3$index[1])
2. stop("'ts' object must have one or more observations")
I believe this is because R cannot read the df3$x. How do I loop through a vector and use an element of that vector as a column name of my dataframe?