Access the object using get() or backticks
At some point, you might download data for an instrument that does not have a syntactically valid name. Syntactically valid names contain letters, numbers, ".", and "_", and must start with a letter or a "." followed by a non-number.
For example, the symbol for Berkshire Hathaway class A shares is "BRK-A", which is not a syntactically valid name because it contains a "-" character. Another example are Chinese stocks, which have symbols composed of numbers. The Yahoo Finance symbol for the SSE Composite Index is "000001.SS".
You can use the get
function or backticks (`
) to access objects that do not have syntactically valid names.
This exercise is part of the course
Importing and Managing Financial Data in R
Exercise instructions
- Use
getSymbols()
to load data for "BRK-A". - Use backticks (
`
) andhead()
to look at the first few rows of data. - Use
get()
to assign the data loaded bygetSymbols()
to an object namedBRK.A
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Load BRK-A data
# Use backticks (`) and head() to look at the loaded data
___(`___`)
# Use get() to assign the BRK-A data to an object named BRK.A
___ <- get("___")