0

I am currently working on the Boston data. So I downloaded the library(MASS) data(Boston). As I found on numerous websites there is a famous assignment on this based on this regression model (OLS) medv = β0 + b1crim + b2chas + ε. I now want to draw a random sample of X observations e.g. 30 and save the subsample as object ZZ. How can I do this?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453

2 Answers2

1

Using package dplyr:

library(dplyr)
ZZ <- Boston |> sample_n(30)
Claudio
  • 1,229
  • 6
  • 11
0

You probably want

data("Boston", package = "MASS")
keep_rows <- sample(nrow(Boston), size = 30, replace = FALSE)
ZZ <- Boston[keep_rows, ]
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453