I have lots of sales areas. Each one is a data.frame and I can create xts objects for each. This requires a line of code for each. I'd rather use a function to create on demand. I've tried using keyboard entry to create a character string, then strip the quotes and store the input as symbol, to be used in a function. This doesn't work!
## Function to specify unit
userinput <- scan("", what="")
userinput <- as.name(userinput[1])
## Function to create xts object
createXts=function(x) {
xts(x[1], order.by=x$StartTime, dateFormat="POSIXct")
}
## Call function
createXts(userinput)
##Result:
>> Error in x[1] : object of type 'symbol' is not subsettable
How can I use user input to specify a data.frame to be used in a function? Note: The createXts
function does work if I replace x
with a real unit's name.