How to randomize (or permute) a dataframe rowwise and columnwise?

前端 未结 8 1004
Happy的楠姐
Happy的楠姐 2020-11-28 22:50

I have a dataframe (df1) like this.

     f1   f2   f3   f4   f5
d1   1    0    1    1    1  
d2   1    0    0    1    0
d3   0    0    0    1    1
d4   0             


        
8条回答
  •  野性不改
    2020-11-28 23:31

    You can also "sample" the same number of items in your data frame with something like this:

    nr<-dim(M)[1]
    random_M = M[sample.int(nr),]
    

提交回复
热议问题