@@ -677,25 +677,44 @@ setMethod("unique",
677677# ' collect(sample(df, TRUE, 0.5))
678678# '}
679679setMethod ("sample ",
680- # TODO : Figure out how to send integer as java.lang.Long to JVM so
681- # we can send seed as an argument through callJMethod
682680 signature(x = " DataFrame" , withReplacement = " logical" ,
683- fraction = " numeric" ),
684- function (x , withReplacement , fraction ) {
681+ fraction = " numeric" , seed = " missing " ),
682+ function (x , withReplacement , fraction , seed ) {
685683 if (fraction < 0.0 ) stop(cat(" Negative fraction value:" , fraction ))
686684 sdf <- callJMethod(x @ sdf , " sample" , withReplacement , fraction )
687685 dataFrame(sdf )
688686 })
689687
688+ # ' @rdname sample
689+ # ' @name sample
690+ setMethod ("sample ",
691+ # we can send seed as an argument through callJMethod
692+ signature(x = " DataFrame" , withReplacement = " logical" ,
693+ fraction = " numeric" , seed = " numeric" ),
694+ function (x , withReplacement , fraction , seed ) {
695+ if (fraction < 0.0 ) stop(cat(" Negative fraction value:" , fraction ))
696+ sdf <- callJMethod(x @ sdf , " sample" , withReplacement , fraction , as.integer(seed ))
697+ dataFrame(sdf )
698+ })
699+
690700# ' @rdname sample
691701# ' @name sample_frac
692702setMethod ("sample_frac ",
693703 signature(x = " DataFrame" , withReplacement = " logical" ,
694- fraction = " numeric" ),
695- function (x , withReplacement , fraction ) {
704+ fraction = " numeric" , seed = " missing " ),
705+ function (x , withReplacement , fraction , seed ) {
696706 sample(x , withReplacement , fraction )
697707 })
698708
709+ # ' @rdname sample
710+ # ' @name sample_frac
711+ setMethod ("sample_frac ",
712+ signature(x = " DataFrame" , withReplacement = " logical" ,
713+ fraction = " numeric" , seed = " numeric" ),
714+ function (x , withReplacement , fraction , seed ) {
715+ sample(x , withReplacement , fraction , as.integer(seed ))
716+ })
717+
699718# ' nrow
700719# '
701720# ' Returns the number of rows in a DataFrame
0 commit comments