2016年6月24日金曜日

Use list as associative array.


plase also see part2.

utilize a list as associative array.

1)create a list which each element contains a pair of information.

> test_list <- list(list("Mon",1),list("Tue",2),list("Wed",3),list("Thu",4),list("Fri",5),list("Sat",6),list("Sun",7))

2)when weekday returns day of the first day of the year, numeric seq number which is associated with weekday's return will be printed.

> for(i in 1:length(test_list)){
   if(match(weekdays(as.Date(ISOdate(year(Sys.Date()),1,1)),abbreviate = TRUE),test_list[[i]][1],nomatch = FALSE))
     {print(test_list[[i]][2])}
 }
[[1]]
[1] 5

0 件のコメント: