pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

financialpython private pastebin - collaborative debugging tool What's a private pastebin?


Posted by DK on Tue 3 Nov 02:24
report abuse | download | new post

  1. baby <- read.table("data.txt", sep = "\t", header = T)
  2. baby$action_time <- as.POSIXct(strptime(baby$action_time,
  3.   "%Y-%m-%d %H:%M:%s"))
  4. sleep <- subset(baby, action_name %in% c("gnight", "gmorning"))
  5.  
  6. # Trick to label each sleep period
  7. sleep$period <- cumsum(sleep$action_name == "gnight")
  8.  
  9. # Now can easily use plyr
  10. library(plyr)
  11.  
  12. # Remove cases that don't have exactly two observations
  13. sleep <- ddply(sleep, "period", function(df) {
  14.   if (nrow(df) == 2) {
  15.     df
  16.   }
  17. })
  18.  
  19. # This is the data format that's most useful for plotting.  However, rather
  20. # than going through the gymnastics to get it into this format, I'd suggest
  21. # having a separate data frame for interval events where you record the
  22. # start and end of each event - i.e. just like this format
  23. asleep <- ddply(sleep, "period", summarise,
  24.   start = action_time[action_name == "gnight"],
  25.   end =   action_time[action_name == "gmorning"]
  26. )
  27. asleep$length <- with(asleep, as.numeric(difftime(start, end,
  28.   units = "mins")))
  29.  
  30. library(ggplot2)
  31.  
  32. print(qplot(start, length, data = asleep, geom = "line"))
  33. print(qplot(start, length / 60, data = asleep, ylab = "hours"))
  34.  
  35. asleep$hour <- as.POSIXlt(asleep$start)$hour + 1
  36. qplot(hour, length / 60, data = asleep, geom = "boxplot", group = hour)
  37. ggsave(file = "ggplot2test.png")
  38.  
  39. qplot(hour, length/60, data=asleep, alpha=I(1/10))

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post