I am rather a beginner with R and currently facing the following challenge where the search didn't provide me an answer.
I have a data frame that has a group assignment in the first column and now I want to create conditional random variables based on the group. E.g. everyone in group A should get a normally distributed random variable with mean 50 and stddev 10. The result of this random variable would then be added as additional column.
Example:
group_assigned <- c("A","A","B","C","A","C")
dframe <- data.frame(group_assigned)
groups <-c("A","B","C")
group_mean <- c(50,40,30)
group_stddev <- c(10,5,5)
group_properties <- data.frame(groups,group_mean, group_stddev)
Can you guide me to a solution? Thank you for your help!
Aucun commentaire:
Enregistrer un commentaire