I am trying to write a function that will randomly select about half of the experimental units stored in a vector x, assign them to treatment1 and treatment2. The output should display the entries of the vector that are assigned to each of the two treatments.
My codes seems to "work" but I am not sure if i should be using "matrix" or if i am actually even doing this correctly. My code is below:
myfunction <- function(x) {
df.1 <- data.frame(matrix(x, nrow = length(x)/2))
names(df.1) <- gsub("X", "Treatment", names(df.1), fixed = "TRUE")
return(sample(df.1))
}