df <- data.frame(
no = c(1:10),
name = c("Py", "C", "Mike","Lin", "Terry", "Amada", "Jack.P", "Robber" , "Mary", "Kate"),
score = c(1, 2, NA, 4, 5, 6, 7, 10, 5, 7),
team = c(1, 3, 2, 5, 4, 2, 3, 5, 4, 1)
)
I would like to output 5 txt file by df$team
,
team = 1 into 1.txt and team = 2 into 2.txt ... and so on,
I have not succeeded by my code. Thank you.
n = unique(df[[4]])
for (i in n) {
data <- df
name <- glue("df$team.txt", name = name)
write.table(data, file = path, sep = ",")
}