'R function to limit characters of list element name?
I have a list of elements. I want to export this list as an excel file with each element exporting as an individual sheet within the same excel file. Excel has a 31 character limit for sheet names. Thus the below export will not work.
Is there a way to limit the characters of a list using a function? For example, cut off all element names at 30 characters?
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(21000, 23400, 26800)
startdate <- as.Date(c('2010-11-1','2008-3-25','2007-3-14'))
test1 <- list(employee, salary, startdate)
names(test1)[1] <- "employee of the month 2021 to 2022"
names(test1)[2] <- "salary of the best employees of test company"
names(test1)[3] <- "startdate"
write.xlsx(test1, file = "testlist.xlsx")
TIA
Solution 1:[1]
Function substr will work.
> substr("salary of the best employees of test company", start = 1, stop = 30)
[1] "salary of the best employees o"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Roman Luštrik |
