Re: [R] Creating a new by variable in a dataframe

2012-10-20 Thread arun
s Cc: R help ; ramoss Sent: Saturday, October 20, 2012 12:04 PM Subject: RE: [R] Creating a new by variable in a dataframe > d$flag<-unlist(rbind(lapply(split(d,d$date),function(x) x[3]==max(x[3] I think that line is unnecessarily complicated. lapply() returns a list and rbind applied

Re: [R] Creating a new by variable in a dataframe

2012-10-20 Thread arun
result do you want when there are several transactions at the last time in the day? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of arun > Sent: Friday

Re: [R] Creating a new by variable in a dataframe

2012-10-20 Thread William Dunlap
R help; Flavio Barros; ramoss > Subject: Re: [R] Creating a new by variable in a dataframe > > HI Bill, > > Thanks for the reply. > It was unnecessarily complicated. > d$flag<-unlist(lapply(split(d,d$date),function(x) > x[3]==max(x[3])),use.names=FALSE) > #or > d$f

Re: [R] Creating a new by variable in a dataframe

2012-10-20 Thread William Dunlap
ftware wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of arun > Sent: Friday, October 19, 2012 7:49 PM > To: Flavio Barros > Cc: R help; ramoss > Subject: Re: [R] Creating a new by

Re: [R] Creating a new by variable in a dataframe

2012-10-19 Thread arun
T10 2012-10-23 17:00:00  TRUE str(d1) #'data.frame':    10 obs. of  3 variables: # $ transaction: chr  "T01" "T02" "T03" "T04" ... # $ datetime   : POSIXct, format: "2012-10-19 08:00:00" "2012-10-19 09:00:00" ... # $ flag  

Re: [R] Creating a new by variable in a dataframe

2012-10-19 Thread arun
Hi, In addition to merge(), you can also use join() dat1<-read.table(text=" tdate  event_tim  transaction 1/10/2012   2   14 1/10/2012   4   28 1/10/2012   6   42 1/10/2012   8   14 2/10/2012   6   46 2/10/2012   9   64 2/10/2012   8   71 3/10/2012  3   85 3/10/2012   1   14 3/10/2012   4   28 9/1

Re: [R] Creating a new by variable in a dataframe

2012-10-19 Thread arun
Hi, May be this helps you: dat1<-read.table(text=" tdate  event_tim  transaction 1/10/2012   2   14 1/10/2012   4   28 1/10/2012   6   42 1/10/2012   8   14 2/10/2012   6   46 2/10/2012   9   64 2/10/2012   8   71 3/10/2012  3   85 3/10/2012   1   14 3/10/2012   4   28 9/10/2012   5   51 9/10/20

Re: [R] Creating a new by variable in a dataframe

2012-10-19 Thread Flavio Barros
I think i have a better solution *## Example data.frame* d <- data.frame(stringsAsFactors = FALSE, transaction = c("T01", "T02", "T03", "T04", "T05", "T06", "T07", "T08", "T09", "T10"),date = c("2012-10-19", "2012-10-19", "2012-10-19", "2012-10-19", "2012-10-22", "2012-10-23", "2012-10-23", "2012-

Re: [R] Creating a new by variable in a dataframe

2012-10-19 Thread ramoss
Thanks for all the help guys. This worked for me: all6 <- arrange(all6, tdate,event_tim) lt <- ddply(all6,.(tdate),tail,1) lt$last_trans <-'Y' all6 <-merge(all6,lt, by.x=c("tdate","event_tim"), by.y=c("tdate","event_tim"),all.x=TRUE) -- View this message in context: http://r.789695.n4.nabbl

Re: [R] Creating a new by variable in a dataframe

2012-10-19 Thread William Dunlap
Suppose your data frame is d <- data.frame( stringsAsFactors = FALSE, transaction = c("T01", "T02", "T03", "T04", "T05", "T06", "T07", "T08", "T09", "T10"), date = c("2012-10-19", "2012-10-19", "2012-10-19", "2012-10-19", "2012-10-22", "2012-10-23", "2012-1