Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Example - Date


  • Use funtion

 > d1 <- date()  
 > class(d1)  
 [1] "character"  
 > d1  
 [1] "Tue Dec 23 17:46:34 2014"  
 > d2 <- Sys.Date()  
 > class(d2)  
 [1] "Date"  
 > d2  
 [1] "2014-12-23"  
 > format(d2,"%a %b %d")  
 [1] "Tue Dec 23"  
 > d3 <- "1jan2014"  
 > d4 <- as.Date(d3,"%d%b%Y")  
 > d4  
 [1] "2014-01-01"  
 > d2 - d4  
 Time difference of 356 days  
 > as.numeric(d2-d4)  
 [1] 356  
 > weekdays(d2)  
 [1] "Tuesday"  
 > months(d2)  
 [1] "December"  
 > julian(d2)  # days from origin date (1970-01-01)
 [1] 16427  
 attr(,"origin")  
 [1] "1970-01-01"  

  • Use library

 > library(lubridate)  
 > ymd("20140108")  
 [1] "2014-01-08 UTC"  
 > ymd_hms("2014-01-01 10:10:10")  
 [1] "2014-01-01 10:10:10 UTC"  
 > ymd_hms("2014-01-01 10:10:10", tz = "Pacific/Auckland")  
 [1] "2014-01-01 10:10:10 NZDT"  
 > wday( ymd("20140108"))  
 [1] 4  
 > wday( ymd("20140108"), label = TRUE)  
 [1] Wed  
 Levels: Sun < Mon < Tues < Wed < Thurs < Fri < Sat  

JavaScript - Object property for creating contact list

1:  var friends = new Object();  
2:  friends.steve = {  
3:    firstName : 'Steve',  
4:    lastName : 'Shock',  
5:    number : 13533334444,  
6:    address : ['20','Rahoon']  
7:  };  
8:  friends.bill = {  
9:    firstName : 'Bill',  
10:    lastName : 'Guangyuan',  
11:    number : 13514437556,  
12:    address : ['26','Angues House']  
13:  };  
14:  function list(friends){  
15:    for (var p in friends) {  
16:      console.log(p);    
17:    }  
18:  };  
19:  var search = function (name){  
20:    for(var p in friends){  
21:      console.log(friends[p].firstName);  
22:      if(friends[p].firstName === name){  
23:        console.log(p);  
24:        return friends[p];  
25:      }  
26:    }    
27:  };  
28:  list(friends);  
29:  search('Steve');