I'm trying to use R's sample function to split a sequence of integers into numerous equal portions for later usage, but even when I specify that I don't want replacement values, I'm still getting repeated digits.

set.seed seq(1,21,1) trials (5)
p1.trials - sample(trials, 7, replace=F) p1.trials - sample(trials, 7, replace=F) p1.trials - sample(trials, 7, replace=F) p
As a result, you'll get the following vector: 5, 14, 18, 6, 2, 12, and 8 are all numbers that can be used to make a number.

trials - tests

[-p1.trials]
sample(trials, 7, replace=F) p2.trials
p2.trials
As a result, you'll get the following vector: 19, 20, 3, 7, 9, 4, 16,

p3.trials - trials[-p2] p3.trials - trials[-p2] p3.trials .trials]
p3.trials
As a result, you'll get the following vector: 1–3, 9, 10–13, 16, 17–19, 20, 21

Can someone explain why (a) I'm receiving repeated values (e.g., "3" appears in both p2.trials and p3.trials) and (b) I'm getting repeated values (e.g., "3" appears in both p2.trials and p3.trials)? Jun 19 11 views

## 1 answer to this question.

The first time works, but after that, the value and index of each trial's member are different. The issue is caused by using -; instead, use setdiff:

trials in order (1,21,1)

set.seed(5)

sample(p1.trials, 7, replace=F)

p1.trials

setdiff - trials (trials,p1.trials) answered Jun 24 by
• 2,960 points

## Introduction to Statistical Learning with Applications in R Figure Codes

I recently bought the following book: An Introduction ...READ MORE

## How to implement Knn-algorithm without using k-nn function in r?

I created an example that demonstrates the ...READ MORE

## Unexpected behavior for setdiff() function in R

Asymmetric difference is provided by 18 setdiff. ...READ MORE

## To speed up the tapply function in R, or another function to convert data frame into a matrix

I must turn a sizable dataset into ...READ MORE

## R: Sample from a neighborhood according to scores

I would suggest you to use the truncated ...READ MORE

## How to sample random rows in dataframe?

Create data frame and then implement as ...READ MORE

## How to sample n random rows per group in a dataframe?

You can assign a random ID to ...READ MORE

## 100 samples of 20 from the dataset and drawing regression lines along with population regression line

I have a datasetwith two variables hours ...READ MORE