2016-04-15 148 views
1

創建10000個問題的數據,我需要做每個candidate_id有100個q的答案我該如何填充1個候選人的這個數據,每個有100個問題?在數據框中填充數據

df <- data.frame(candidate_id=sample(1:100,10000,T), 
       question_id=sample(1:10000,100,T), 
       selected_answer=sample(1:4,100,T)) 

回答

0

試試這個:

#make data frame 
df <- data.frame(candidate_id = 1:100, 
       question_id = sample(1:10000, 10000, TRUE), 
       selected_answer = sample(1:4, 10000, TRUE)) 
#test 
unique(table(df$candidate_id)) 
# [1] 100