Error in first function: $ operator is invalid for atomic vectors [closed]


Disclaimer: This is my first time trying to create a function in R.

I have HoltWinters function that looks like this:

f <- function(x) { y <- ts(x$Million, freq = 4, start = c(2013, 1)) y.hw <- HoltWinters(y) y.pr <- forecast(y.hw, h = 3, level = c(80, 85)) y.pr plot(y.pr) }

It takes a dataframe, converts it to timeseries (ts), forecasts and plots the forecast.

I am getting thrown this error:


Error in x$Million : $ operator is invalid for atomic vectors


I know this is probably a stupid question... but I hope you'll be nice!


The structure of the dataframes I want to pass to the function:

Quarter Product Million 1 2013-Q1 AAA 4.0 2 2013-Q2 AAA 6.0 3 2013-Q3 AAA 9.0


This error appears when you're using $ on vectors or single numeric and integer values etc, but something other than a list or a data.frame. Please make sure you're providing a data.frame or a list in your function. And most definitely, make sure your data set is not a matrix.


  • Forecasts with specific VAR model lags
  • Scrape arraytodatatable with python
  • MASE Extraction Hierarchical Data ('hts' and 'forecast' packages R)
  • Turning the second timeseries in a TimeseriesChart to a barchart
  • Poco Iterating Nested JSON Objects
  • Keras: How to shape inputs for CNN and LSTM layers?
  • Find the first non repeating character in a string
  • Update embedded document in Mongodb: Performance issue?
  • Delete files that match regex
  • overlapping the predicted time series on the original series in R
  • Qt 5.1 Beta Error using std::atomic c++11 feature
  • SQL query returns empty result for Apache Ignite cache
  • Is this method of file locking acceptable?
  • How to reset AtomicInteger unique Id in Android?
  • Multiple Thread Variable Access inside a function
  • Compute EWMA over sparse/irregular TimeSeries in Pandas
  • Concurrency scenarios with INSERTs
  • How to make sure my plots share same axis while using multiplot in gnuplot?
  • Javascript - variable scope in event handler
  • Use MongoDB array as stack
  • Force ggplot legend to show all categories when no values are present [duplicate]
  • How atomic are mongoengine's operations
  • Maple: How to insert a command to force my code to choose random integer values to find my values?
  • Exclusive access established by another Thread Java smartcardio
  • UIImageJPEGRepresentation giving 2x images on retina display
  • Visual Studio not stopping on an exception being thrown
  • Excel Date field value differs from c# dateTime by 1 day while reading excel file with EEPlus
  • Transpose table then set and rename index
  • How do I add a File Type Association in a Windows Phone 8.1 app manifest?
  • Streaming screenshots over WebRTC as a video stream from iOS
  • Issue with routerLink directive
  • Azure webjobs output logs indexing taking very long
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Row to Column conversion in Talend
  • Make new pandas columns based on pipe-delimited column with possible repeats
  • xtable package: Skipping some rows in the output
  • ADO and msqli connections very slow
  • Marklogic : Query response time is very high
  • How to use remove-erase idiom for removing empty vectors in a vector?
  • How to model a transition system with SPIN