Skip to content

Instantly share code, notes, and snippets.

@alexstorer
Created March 13, 2013 19:58
Show Gist options
  • Save alexstorer/5155586 to your computer and use it in GitHub Desktop.
Save alexstorer/5155586 to your computer and use it in GitHub Desktop.
fname <- 'a1.txt'
ds <- read.csv(fname,col.names = c('Date','Time','File','TimeElapsed','SongTime'),header=FALSE,stringsAsFactors=FALSE)
ds$Date <- as.Date(ds$Date)
ds$Name <- fname
timelist <- strsplit(ds$Time,split=':')
for (i in 1:length(timelist)) {
hr <- timelist[[i]][[1]]
mn <- timelist[[i]][[2]]
sc <- timelist[[i]][[3]]
timestr <- paste(as.character(ds$Date[i])," ",hr,":",mn,":",sc,sep="")
ds$Time[i] <- as.POSIXct(timestr)
}
labelSongs <- function(s) {
if (s == "http://www.people.fas.harvard.edu/~mehr/1.mp3" || s == "http://www.people.fas.harvard.edu/~mehr/2.mp3")
return("Words")
return("Without")
}
ds$SongType <- unlist(lapply(ds$File,labelSongs))
by(ds$SongTime,ds[,c("Name","SongType","Date")],sum)
xtabs(ds$SongTime,ds[,c("Name","SongType","Date")],sum)
outds <- xtabs(SongTime ~ Name + SongType + Date, ds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment