0 votes
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, 2022 371 views

1 answer to this question.

0 votes

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)

Unleash the power of data with our comprehensive Data Science Training.

answered Jun 24, 2022 by
• 3,040 points

0 votes
1 answer

sample function in R

It seems like you are experiencing an ...READ MORE

0 votes
0 answers

Introduction to Statistical Learning with Applications in R Figure Codes

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

0 votes
1 answer

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

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

0 votes
1 answer

Unexpected behavior for setdiff() function in R

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

0 votes
1 answer

R: Sample from a neighborhood according to scores

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

0 votes
1 answer

How to sample random rows in dataframe?

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

0 votes
1 answer

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

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

0 votes
0 answers

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

0 votes
1 answer

Creating new Functions with Linear Regression in R :

When we want to create a model ...READ MORE

0 votes
1 answer

rnorm function in R - Usage

y = rnorm(12, rep(c(1,2,1), each=4, 0.2)) I can ...READ MORE