【发布时间】:2020-09-22 09:14:51
【问题描述】:
我有一个包含多列的数据集,其中每一行代表一个产品,每一列包含对相应产品的一个评论。对于每个产品,我们观察到多个 cmets,每个 cmets 都存储在自己的列中。
现在我想通过以下方式创建两个新数据集: (1) 一个只有一列的数据集,包括从多个评论列中随机抽取的 x (个) cmets 样本。 (2) 与 (1) 一样,但现在我想从每列中采样相同数量的 cmets(例如,“comment1”中的 2 个 cmets 和“comment2”中的 2 个 cmets。
Example data:
commentda = data.frame(product_id = c(1,2,3,4), comment1 = c("Very good", "Bad", "Would buy it", "Zero stars"), comment2 = c("Bad reputation", "Good seller", "Great service", "I will buy it again"))
>
> commentda
product_id comment1 comment2
1 1 Very good Bad reputation
2 2 Bad Good seller
3 3 Would buy it Great service
4 4 Zero stars I will buy it again
【问题讨论】:
-
到目前为止,您的“问题”不包含任何问题或代码来帮助您。您可能需要相应地更新您的问题。
标签: r function text dplyr sample