如何使用copy()填充数据框

时间:2018-06-28 10:22:13

标签: r

我的列表如下:

Suppose I have following information,
#PAN#       #Product#
AAAAAAAAAA  Product1
AAAAAAAAAA  Product2
AAAAAAAAAA  Product3
AAAAAAAAAA  **Product4**
AAAAAAAAAA  Product5
BBBBBBBBBB  Product1
BBBBBBBBBB  Product2
BBBBBBBBBB  Product3
BBBBBBBBBB  **Product4**
BBBBBBBBBB  Product5
CCCCCCCCCC  Product1
DDDDDDDDDD  Product2

我还创建了一个数据框

structure(list(x = "Male          ", x = "Female        ", x = "Unknown       ", 
    x = "Indeterminate"), .Names = c("x", "x", "x", "x"))

我想从列表中采样以添加到数据框中的新列

我尝试过:

OGDProcedure<-data.frame(nrow=10)

但是我得到了错误:

OGDProcedureType$Gender<-replicate(10,paste("Gender: ",sample(GeneralGenderType,1)))

我必须循环吗?

1 个答案:

答案 0 :(得分:1)

OGDProcedure <- data.frame(matrix(NA, nrow = 10, ncol = 1))
OGDProcedureType$Gender<-replicate(10,paste("Gender: ",sample(GeneralGenderType,1)))