Superseded lifecycle sample_n() and sample_frac() have been superseded in favour of slice_sample(). While they will not be deprecated in the near future, retirement means that we will only perform critical bug fixes, so we recommend moving to the newer alternative.

These functions were superseded because we realised it was more convenient to have two mutually exclusive arguments to one function, rather than two separate functions. This also made it to clean up a few other smaller design issues with sample_n()/sample_frac:

  • The connection to slice() was not obvious.

  • The name of the first argument, tbl, is inconsistent with other single table verbs which use .data.

  • The size argument uses tidy evaluation, which is surprising and undocumented.

  • It was easier to remove the deprecated .env argument.

  • ... was in a suboptimal position.

sample_n(tbl, size, replace = FALSE, weight = NULL, .env = NULL, ...)

sample_frac(tbl, size = 1, replace = FALSE, weight = NULL, .env = NULL, ...)

Arguments

tbl

A data.frame.

size

<tidy-select> For sample_n(), the number of rows to select. For sample_frac(), the fraction of rows to select. If tbl is grouped, size applies to each group.

replace

Sample with or without replacement?

weight

<tidy-select> Sampling weights. This must evaluate to a vector of non-negative numbers the same length as the input. Weights are automatically standardised to sum to 1.

.env

DEPRECATED.

...

ignored

Examples

by_cyl <- mtcars %>% group_by(cyl) # sample_n() -> slice_sample() ---------------------------------------------- sample_n(mtcars, 10)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
sample_n(mtcars, 50, replace = TRUE)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Mazda RX4 Wag...1 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Pontiac Firebird...2 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Toyota Corolla...3 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Fiat X1-9...4 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Lotus Europa...5 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 #> Merc 450SE...6 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Valiant...8 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Hornet Sportabout...9 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Dodge Challenger...10 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 #> Valiant...12 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Cadillac Fleetwood...13 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 #> Merc 450SE...15 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Mazda RX4...16 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Ferrari Dino...17 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Hornet Sportabout...19 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Dodge Challenger...20 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> Datsun 710...21 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Honda Civic...23 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Valiant...25 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 #> Honda Civic...27 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Mazda RX4...28 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Lotus Europa...29 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 #> Ferrari Dino...30 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Merc 240D...32 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Merc 240D...33 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Fiat X1-9...34 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Mazda RX4...35 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Mazda RX4 Wag...36 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Chrysler Imperial...37 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Toyota Corolla...38 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Honda Civic...39 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Valiant...40 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Datsun 710...41 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Chrysler Imperial...42 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Cadillac Fleetwood...43 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Merc 450SE...44 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 #> Pontiac Firebird...46 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Mazda RX4...47 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Merc 240D...48 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Toyota Corolla...49 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Ferrari Dino...50 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
sample_n(mtcars, 10, weight = mpg)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 #> Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2
# Changes: # * explicitly name the `n` argument, # * the `weight` argument is now `weight_by`. slice_sample(mtcars, n = 10)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 #> Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 #> Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3
slice_sample(mtcars, n = 50, replace = TRUE)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 #> Pontiac Firebird...2 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Merc 280...3 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 #> Toyota Corona...4 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Camaro Z28...5 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> AMC Javelin...6 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Pontiac Firebird...7 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Toyota Corona...8 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Lotus Europa...9 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 #> Dodge Challenger...10 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Toyota Corona...12 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Porsche 914-2...13 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> AMC Javelin...14 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Camaro Z28...15 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Lotus Europa...17 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 #> Honda Civic...18 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Dodge Challenger...19 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> Dodge Challenger...20 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Merc 450SL...22 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Merc 450SL...24 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Fiat 128...25 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Fiat 128...26 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Porsche 914-2...27 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Honda Civic...28 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Merc 450SL...29 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Merc 230...30 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 #> Merc 230...31 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 #> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Volvo 142E...33 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 #> Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 #> AMC Javelin...35 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Ford Pantera L...37 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Volvo 142E...38 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 #> Ford Pantera L...39 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> AMC Javelin...41 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Honda Civic...42 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Fiat 128...43 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Ford Pantera L...44 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Valiant...45 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Porsche 914-2...46 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Merc 280...47 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 #> Dodge Challenger...48 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> Valiant...49 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Dodge Challenger...50 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2
slice_sample(mtcars, n = 10, weight_by = mpg)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2
# Note that sample_n() would error if n was bigger than the group size # slice_sample() will just use the available rows for consistency with # the other slice helpers like slice_head() # sample_frac() -> slice_sample() ------------------------------------------- sample_frac(mtcars)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 #> Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 #> Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 #> Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 #> Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 #> Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 #> Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4
sample_frac(mtcars, replace = TRUE)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Fiat 128...1 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Mazda RX4 Wag...6 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Ford Pantera L...8 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Fiat 128...9 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Datsun 710...10 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 #> Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Ford Pantera L...15 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Porsche 914-2...16 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Mazda RX4 Wag...17 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 #> Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 #> Honda Civic...20 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Valiant...21 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Ford Pantera L...22 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Datsun 710...23 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Merc 450SE...24 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Valiant...25 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Porsche 914-2...26 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Porsche 914-2...27 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Porsche 914-2...28 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Valiant...29 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Merc 450SE...30 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Honda Civic...32 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2
# Changes: # * use prop = 1 to randomly sample all rows slice_sample(mtcars, prop = 1)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 #> Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 #> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 #> Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 #> Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 #> Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 #> AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1
slice_sample(mtcars, prop = 1, replace = TRUE)
#> mpg cyl disp hp drat wt qsec vs am gear carb #> Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 #> Cadillac Fleetwood...2 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Hornet 4 Drive...3 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Mazda RX4...4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Hornet Sportabout...5 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Hornet Sportabout...6 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> AMC Javelin...7 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Hornet Sportabout...10 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 #> Fiat X1-9...13 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 #> Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 #> Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Merc 450SE...17 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Mazda RX4...18 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 #> Toyota Corolla...21 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Cadillac Fleetwood...22 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Mazda RX4 Wag...23 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Fiat X1-9...24 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Mazda RX4 Wag...25 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Hornet 4 Drive...27 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Merc 450SE...29 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> AMC Javelin...30 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Toyota Corolla...31 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1