0

I am using the Wisconsin Breast Cancer dataset from UCI Machine Learning repository in r. There are total of 569 observations.

Read the Data.

df <- readxl::read_excel("./wdbc.xlsx")

create bootstrap samples.

k = 20
n = nrow(df)

bootSamples = as.data.frame(matrix(sample(df$ID, size = k*n, replace = TRUE), k, n))
colnames(bootSamples) <- paste0("Column", seq(ncol(bootSamples)))

My doubt is how to create a new data frame in r by using ID value from 1st bootstrap column and extract row corresponding to ID value from original dataframe (1st photo) to new dataframe ?

npkp
  • 1,081
  • 5
  • 18
  • 24
  • 1
    Please add a reproducible example and code snippets instead of pictures to allow for better answers, for you and future readers: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – harre Nov 21 '22 at 17:15
  • I think you don't need to use the IDs at all, just sample the row numbers, i.e. `sample(nrow(df), ...)`. And you probably don't want to use the columns of `bootSamples` but rather its rows. So in the end you would use something like `df[bootSamples[1, ], ]`. – Robert Hacken Nov 21 '22 at 17:16

0 Answers0