0

I want to create new variables as follows:

MainModFinal$xAdAware_CA_1<-(MainModFinal$AdAware_CA_1/MainModFinal$ParticipantCount)*100
MainModFinal$xAdAware_CB_1<-(MainModFinal$AdAware_CB_1/MainModFinal$ParticipantCount)*100

So, I would like to divide the existing variable by the same Participant count and thus create a percentage variable out of it.

Can some one tell me how could it be accomplished as I need to repeat it for several more variables?

1 Answer 1

1

If you had a vector of all the variables of interest:

vars <- c("Sepal.Length", "Sepal.Width", "Petal.Length")

Then you could update them all in one shot with:

iris[,vars] <- iris[,vars] / iris$Petal.Width * 100

Here, iris is the name of your data frame (and a convenient example data frame built into R) and Petal.Width is the variable you want to normalize by.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.