Lists in R hold several kinds of data. Some times, user may have following needs:
For this, let us create a lit with 3 vectors:
## create a list by name test_list
$ test_list[["num"]] = 1:4
$ test_list[["nt"]] = c("A","T","G","C")
$ test_list[["count"]] = c(1,2,3,4,5,6)
## Print the list
$ test_list
## Look at the structure
$ str test_list
$ write.xlsx(unlist(test_list),"temp.xlsx")
## Since the list has 3 vectors, i used 1:3 in loop. Data sheet name would be numbers (1 to 3)
$ for (i in c(1:3)){
write.xlsx(test_list[i], file="temp.xlsx", sheetName=paste(i), append=T)
}
## This loop would create 3 files with names that end with test.
$ for (i in c(1:3)){
write.xlsx(mylist[i], file=paste(i,"test.xlsx"))
}
- Concatenate all the items in a list to a single excel file and a excel sheet
- Create multiple sheets in a single excel file, but each data frame with a single sheet with names
- Create multiple excel files, with each data frame into a single excel file.
For this, let us create a lit with 3 vectors:
## create a list by name test_list
$ test_list[["num"]] = 1:4
$ test_list[["nt"]] = c("A","T","G","C")
$ test_list[["count"]] = c(1,2,3,4,5,6)
## Print the list
$ test_list
## Look at the structure
$ str test_list
Concatenate all the items in a list to a single excel file and a excel sheet
$ library(xlsx)$ write.xlsx(unlist(test_list),"temp.xlsx")
Create multiple sheets in a single excel file, but each data frame with a single sheet with names
$ library(xlsx)## Since the list has 3 vectors, i used 1:3 in loop. Data sheet name would be numbers (1 to 3)
$ for (i in c(1:3)){
write.xlsx(test_list[i], file="temp.xlsx", sheetName=paste(i), append=T)
}
Create multiple excel files, with each data frame into a single excel file.
$ library(xlsx)## This loop would create 3 files with names that end with test.
$ for (i in c(1:3)){
write.xlsx(mylist[i], file=paste(i,"test.xlsx"))
}