It is unclear whether you have your list of factors already or not. If you donโt have it and you take it from a data set, you can capture it in several ways:
Then, to calculate the totals for the coefficient, you can do the following
Totals <- colSums(sapply(myFactors, function(fctr) # calculate totals per fctr as.integer(Data$peso) * rowSums(fctr == subset(Data, select= -peso)) )) names(Totals) <- myFactors
What gives
Totals
Next: Iโm not sure that after that you will want to compare with the sum of the pesos or the sum of the totals. Here are both options, broken down into stages:
Selection Note for Peso
You took the sample 0:3.5 , however the sequence x:y gives only integers. If you want fractions, you can use seq() , or you can make a larger sequence and then split accordingly:
option1 <- (0:7) / 2 option2 <- seq(from=0, to=3.5, by=0.5)
If you want integers from 0: 3, as well as a value of 3.5, use c ()
option3 <- c(0:3, 3.5)
source share