0

My question relates to this famous question. I want to select rows from a data frame

k=3
df = data.frame(matrix(rnorm(20), nrow=10))
selected.rows = df[sample(nrow(df), k), ]

But instead of a new data.frame with k rows, I want a column vector in df indicating which rows are selected. I obviously cannot use

sample(c(0,1),nrow(df),TRUE)

Because then k cannot be specified. But something along these lines should give a solution.

Community
  • 1
  • 1
tomka
  • 2,516
  • 7
  • 31
  • 45

0 Answers0