I dont know the proper way of describing this so please bear with me. Basically, I have a function in R that reads through a data frame and pastes the contents in a specific order--its used to write a tex file for LaTeX so I can make hundreds of labels very quickly.
Ive attached a simplified version with just the for loop. What I am hoping to do is have the code loop through four rows of the data, do something different for the fifth, then return to the next four rows of data. In the example below, it would be pasting one phrase for most of the rows and on the fifth it would paste something else--each based on the data frame.
For my actual code I want to flip the label horizontally to use up the most amount of paper possible. See attached photo., But in reality it all comes down to the for loop I think.
data <- data.frame(title = c("big Cactus", "little cactus", "bad cactus", "skinny cactus",
"round cactus", "spiny cactus", "twisty cactus", "bizarre cactus"),
name = c("Franklin", "Stephanie", "Megan", "Mark",
"Patricia", "KD", "Claude", "Audrey"),
needs = c("nothing", "some love", "too much", "some water",
"some sunlight", "new soil", "transplanted", "a friend"))
for (this.label in 1:dim(data)[1]) {
#main function I want for every label
line <- paste0(data$name[this.label], " the ", data$title[this.label], " needs ", data$needs[this.label])
print(line)
}
example of alternate function for every fourth row of the data frame:
line <- paste0(data$name[this.label], " is feeling left out!")