r - Can't mutate despite object as data.frame -
i have subset of data (as shown below). reason can't mutate data.frame in way.
i error message:
error: data_frames can contain 1d atomic vectors , lists
which should stem me not returning object class either list
or data.frame
itself, can't make mutations returns numeric
value.
data
> fvaluation.head conm firm.value isin fyear industry total.pmg exchange industry.classification list short.name feb.price current.price 1 2e group 15.2460627 se0000680902 2015f other service 0.62 sto consumer services first north premier 2e 12.75 12.95 2 a-com ab na se0000592677 2015f other service 0.62 <na> <na> <na> <na> na na 3 aak ab 423.2503370 se0001493776 2015f other production 0.31 sto consumer goods large aak 430.00 425.00 4 ab sagax na se0001629288 2015f real estate 0.56 sto financials mid saga pref na na 5 abelco ab 0.3730399 se0003617075 2015f other production 0.31 sto <na> aktietorget abe 1.69 2.00 6 academedia ab na se0007897079 2015f other service 0.62 <na> <na> <na> <na> na na > str(fvaluation.head) 'data.frame': 6 obs. of 12 variables: $ conm : chr "2e group" "a-com ab" "aak ab" "ab sagax" ... $ firm.value : num 15.246 na 423.25 na 0.373 ... $ isin : chr "se0000680902" "se0000592677" "se0001493776" "se0001629288" ... $ fyear : chr "2015f" "2015f" "2015f" "2015f" ... $ industry : factor w/ 16 levels "building , construction",..: 11 11 10 14 10 11 $ total.pmg : num 0.62 0.62 0.31 0.56 0.31 0.62 $ exchange : factor w/ 5 levels "","cph","hel",..: 5 na 5 5 5 na $ industry.classification: factor w/ 11 levels "","basic materials",..: 4 na 3 5 na na $ list : factor w/ 7 levels ""," ","aktietorget",..: 4 na 5 6 3 na $ short.name : factor w/ 1058 levels "","203","2e",..: 3 na 6 805 9 na $ feb.price : num [1:6, 1] 12.75 na 430 na 1.69 ... $ current.price : num [1:6, 1] 12.9 na 425 na 2 ... > fvaluation.summary <- fvaluation.head %>% mutate(buy.sell.signal = derivedfactor( + "na" = (is.na(firm.value) == true | is.na(feb.price) == true), + "sell" = (firm.value < feb.price), + "buy" = (firm.value > feb.price), + .method = 'first')) error: data_frames can contain 1d atomic vectors , lists > fvaluation.head %>% mutate(test = firm.value * 2) error: data_frames can contain 1d atomic vectors , lists
what wrong? , how can resolved?
> dput(droplevels(fvaluation.head)) structure(list(conm = c("2e group", "a-com ab", "aak ab", "ab sagax", "abelco ab", "academedia ab"), firm.value = c(15.2460627037116, na, 423.25033702408, na, 0.373039901083465, na), isin = c("se0000680902", "se0000592677", "se0001493776", "se0001629288", "se0003617075", "se0007897079"), fyear = c("2015f", "2015f", "2015f", "2015f", "2015f", "2015f"), industry = structure(c(2l, 2l, 1l, 3l, 1l, 2l), .label = c("other production", "other service", "real estate" ), class = "factor"), total.pmg = c(0.62, 0.62, 0.31, 0.56, 0.31, 0.62), exchange = structure(c(1l, na, 1l, 1l, 1l, na), .label = "sto", class = "factor"), industry.classification = structure(c(2l, na, 1l, 3l, na, na), .label = c("consumer goods", "consumer services", "financials" ), class = "factor"), list = structure(c(2l, na, 3l, 4l, 1l, na), .label = c("aktietorget", "first north premier", "large", "mid"), class = "factor"), short.name = structure(c(1l, na, 2l, 4l, 3l, na), .label = c("2e", "aak", "abe", "saga pref" ), class = "factor"), feb.price = structure(c(12.75, na, 430, na, 1.69, na), .dim = c(6l, 1l)), current.price = structure(c(12.95, na, 425, na, 2, na), .dim = c(6l, 1l))), .names = c("conm", "firm.value", "isin", "fyear", "industry", "total.pmg", "exchange", "industry.classification", "list", "short.name", "feb.price", "current.price"), row.names = c(na, 6l), class = "data.frame")
because last 2 columns of dataframe contain matrix, i.e. has 2 dimensions, see:
class(fvaluation.head$feb.price)
if drop (or convert numeric) last 2 columns, should work:
fvaluation.head[, 1:10] %>% mutate(test = firm.value * 2)
str(fvaluation.head$feb.price)
show has 6 rows , 1 column.
$ feb.price : num [1:6, 1]
Comments
Post a Comment