jeudi 18 avril 2019

Generate random numbers in each row between 1 and a particular value in a column in R

I am stuck for quite a while now and really interested in how to achieve this. so I a have a dataframe and I want to add another column with random numbers between 1 and the number that is in that row under the column 'Amount'. How can i do this? this is what i have now:

dataframe$newColumn <- sample(1:30, nrow(dataframe), replace = T)

but i dont want it to go from 1 to 30, but rather have the number in 'Amount' column as the max.

Any help would be appreciated!




Aucun commentaire:

Enregistrer un commentaire