I have got a list of numbers, with attribute names
. It is a stock ticker dataset where in each numeric value reflects how many times the ticker occurs in my dataset. So given that
data <- c(0, 12, 15, 6)
names(data) <- c("SZC", "MSFT", "AAPL", "GOOG")
such that
data[["AAPL"]]
15
I want to get the attribute name
as another variable in my dataframe rather than an attribute.
I have tried
data %>%
(mutate(names = names(data)))
which gives me an error saying Error in UseMethod("mutate") :
no applicable method for 'mutate' applied to an object of class "character"
How do I separate name attributes from a vector and get it as a variable in my dataframe?