I am basically working off of this answer, but want to add one more wrinkle I can't figure out. I want to multiple all columns contained in a list by the weight column, similar to the example below:
#df 1
Id = c("1", "2", "3", "4")
Persons = c(300, 400, 200, 5000)
Houses = c(20, 40, 10, 23)
Ages = c(45, 34, 50, 44)
Races = c(1, 3, 1, 2)
weight = c(0.9, 1.2, 0.8, 1.1)
estimates = data.frame(Id, Persons, Houses, Ages, Races, weight)
list <- as.list(colnames(subset(estimates, select = -c(Id, weight))))
estimates <- estimates %>% mutate_each(funs(.*weight), . %in% list)
But I keep getting the following error:
Error in
as_indices_impl()
: ! Must subset columns with a valid subscript vector. ✖ Subscript has the wrong typelogical
. ℹ It must be numeric or character.