Reputation: 6874
I have a list as follows:
structure(list(x = "Male ", x = "Female ", x = "Unknown ",
x = "Indeterminate"), .Names = c("x", "x", "x", "x"))
I also have created a dataframe
OGDProcedure<-data.frame(nrow=10)
I would like to sample from the list to add to a new column in the dataframe
I tried:
OGDProcedureType$Gender<-replicate(10,paste("Gender: ",sample(GeneralGenderType,1)))
but I get the error:
Error in `$<-.data.frame`(`*tmp*`, Gender, value = c("Gender: Male ", : replacement has 10 rows, data has 1
Do I have to loop this?
Upvotes: 0
Views: 61
Reputation: 8374
OGDProcedure <- data.frame(matrix(NA, nrow = 10, ncol = 1))
OGDProcedureType$Gender<-replicate(10,paste("Gender: ",sample(GeneralGenderType,1)))
Upvotes: 1