Block randomization issue!

Hello, everyone.

Please, I need help. I'm very new to R and don't know almost anything.

I have an Excel table with 180 lines, each one is a volunteer with an ID 22XXX (5 characters), therefore, I need to ranzomize this table and divide it into 12 groups of 14 volunteers and a last one with 12 volunteers. But I couldn't manage how to do that.

I ran the following script:

      install.package(readxl)
      library(readrxl)

# Create an object (table containing the data to be randomized):

      random_samples<- read_excel("C:\\XXX\\XXX\\XXX\\P4\\amostrasrandomizacao1.xlsx")

# Randomize the table created: 
      randomizado<- sample(random_samples$IDS)

# Export the file:
      write.csv(randomizado,"C:\\XXX\\XXX\\XXX\\P4\\randomfinal.csv",row.names = FALSE)

I was planing to perform this blocks construction manually in Excel, but I'd like to learn how to do that on RStudio. I went through many tutorials and videos but none of them addressed this issue.

Could you guys help me out in this issue?

Thank you in advance.

Thalles

Hi! Welcome to this community!

First of all, it seems to me that you're confusing between R and RStudio. Please take a look here.

Second, I don't follow why are you including ... in each of the code snippets.

Third, and the main point, since we do not have a minimal reproducible example, I can't provide you a direct solution. So, let me give you an idea to do this.

If I understand your problem correctly, you have 180 individuals, which you want to divide in 13 groups randomly. 12 of these groups will have 14 people, and the last group will have the remaining 12 people. What you can do is that you can generate 180 random numbers from 1 to 13 with the constraint that 1 to 12 occurs 14 times and 13 occurs 12 times. Then, if you assign these numbers as labels to your volunteers, you'll be getting the desired 13 groups.

One way to do this is to create the following sequence, and then permute it randomly:

\underbrace{1, 1, ..., 1}_{14\ times}, \underbrace{2, 2, ..., 2}_{14\ times}, \dots, \underbrace{12, 12, ..., 12}_{14\ times}, \underbrace{13, 13, ..., 13}_{12\ times}

Here's one way to do it in R:

set.seed(seed = 39863) # for reproducibility
labels <- rep.int(x = 1:13, times = c(rep.int(x = 14, times = 12), 12)) # generating the sequence
permuted_labels <- sample(x = labels) # permuting the sequence
permuted_labels # printing permuted labels

Hope this helps.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.