3

Thanks for reading this question. I have a dataset containing five participants with 10 with 8 variables. I need to export each participant/row of the dataset in a separate pdf file, and name that exported pdf file according to the participant name. Attached is an explanatory code to explain this issue.

df <- data.frame(matrix(ncol = 8, nrow = 5))
x <- c("Participants", "V1","V2", "V3",  "V4","V5", "V6","V7")
colnames(df) <- x

df$Participants= c("Elizabeth",
                   "Emily",
                   "Cristie",
                   "Orville",
                   "Janetta")
df$V1 = runif(5, min=0, max=10)
df$V2 = runif(5, min=0, max=10)
df$V3 = runif(5, min=0, max=10)
df$V4 = runif(5, min=0, max=10)
df$V5 = runif(5, min=0, max=10)
df$V6 = runif(5, min=0, max=10)
df$V7 = runif(5, min=0, max=10)

summary(df)

For example, how can I export "Elizabeth" (the first row in the dataset) scores to an "Elizabeth.pdf" file? Thanks in advance.

Identicon
  • 129
  • 9

1 Answers1

2

Based on this answer we can do the following:

library(gridExtra)
apply(df, 1, function(x){
  pdf(paste0(x[1], ".pdf"), width=10)
  grid.table(data.frame(t(x)))
  dev.off()
})
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138