Thursday, July 11, 2013

R snippets of Week

This week i came across some interesting snippets to get me around and i'll back them up here.

Subset by condition:
resultDF <- result[ result$actingUserProfileId %in% c(1, 2, 3, 4, 5), ]


Subset by dates:
subset(resultsDF, as.Date(Date) >= '20013-06-01' & as.Date(Date) <= '2013-06-30')

Subset Regex:
weekly_ke <- weekly_regs[grep("+254", weekly_regs$dialCode),] 


Convert to R dates:
posDate <- as.POSIXct (d, tz = 'EAT', format = "% a% b% d% H:% M:%S +0000 %Y")


Bugged!! but working. Timestamp to R dates e.g How would you convert this to readable R dates "Mon Jan 20 10:12:59 EAT 2013" 
as.Date(createdAt,format="%a %b %d %H:%M:%S")


No comments:

Post a Comment

Add any comments if it helped :)