小编Sri*_*hna的帖子

R中分类变量内的随机采样

假设我有一个数据框,其中包含 n 个类别的分类变量和一个数值变量。我需要随机化每个类别内的数值变量。例如,考虑下表:

Col_1           Col_2      
   A               2        
   A               5           
   A               4           
   A               8        
   B               1   
   B               4        
   B               9          
   B               7       
Run Code Online (Sandbox Code Playgroud)

当我尝试sample()R 中的函数时,它给出了考虑到这两个类别的结果。有什么函数可以得到这种输出吗?(无论有没有更换,都没关系)

Col_1           Col_2      
 A               8        
 A               4           
 A               2           
 A               5        
 B               9  
 B               7       
 B               4          
 B               1
Run Code Online (Sandbox Code Playgroud)

r permutation sampling

0
推荐指数
1
解决办法
914
查看次数

标签 统计

permutation ×1

r ×1

sampling ×1