我想得到一周中每一天的所有小时的列表,按天和小时排序。
我可以通过创建一个工作日列表和一个小时列表来获得这个列表,然后通过索引工作日列表将小时添加到一周中的每一天。我知道有更好的办法。我尝试了一个for循环,但它没有产生相同的结果。请告诉我一条更好的路。
weekdays <- c("Mon","Tue","Wed","Thu","Fri","Sat","Sun")
hours <- c("12am","1am","2am","3am","4am", "5am","6am","7am","8am","9am","10am",
"11am","12pm","1pm","2pm","3pm","4pm","5pm","6pm","7pm","8pm","9pm",
"10pm","11pm")
monhours <- paste(weekdays[1], hours)
tuehours <- paste(weekdays[2], hours)
wedhours <- paste(weekdays[3], hours)
thuhours <- paste(weekdays[4], hours)
frihours <- paste(weekdays[5], hours)
sathours <- paste(weekdays[6], hours)
sunhours <- paste(weekdays[7], hours)
weekdaysandhours <- c(monhours, tuehours, wedhours, thuhours, frihours, sathours, sunhours)
这就是我想要的结果:“Mon 12am”“Mon 1am”“Mon 2am”“Mon 3am”“Mon 4am”“Mon 5am”“Mon 6am”“Mon 7am”“Mon 8am”“Mon 9am”“Mon 10am”“Mon 11am”“Mon 12pm”“Mon 1pm”“Mon 2pm”“Mon 3pm”“Mon 4pm”“Mon 5pm”“Mon 6pm”“Mon 7pm”“Mon 8pm”“Mon 9pm”“Mon 10pm”“Mon 11pm”“星期二上午12点”“星期二上午1点”“星期二上午2点”“星期二上午3点”“星期二上午4点”“星期二上午5点”“星期二上午6点”“星期二上午7点”“星期二上午8点”“星期二上午9点”“星期二上午10点”“星期二上午11点”等等。
2条答案
按热度按时间jfewjypa1#
使用
expand.grid
,您可以:7gcisfzg2#
使用
outer
方法。