I have another question regarding ddply. In my actual data.frame, I have many
other column variables corresponding to the type of the trial. I'm wondering
if I can have ddply include those in firstfixtime as well.
I tried messing with the line df$FixTime[which.min(df$FixInx)] changing it
to
I tried messing with the line df$FixTime[which.min(df$FixInx)] changing it
to df[which.min(df$FixInx)] or adding new lines with the additional columns
that I want to include, but nothing seemed to work. I'll admit I only have a
mild understanding of what is going on with the function .fun. :-)
On Wed, Apr 1, 2009 at 11:00 AM, hadley wickham h.wick...@gmail.com wrote:
I tried messing with the line df$FixTime[which.min(df$FixInx)] changing it
to df[which.min(df$FixInx)] or adding new lines with the additional columns
that I want to include, but nothing seemed to work. I'll admit I only
pmatch() facilitates a very simple solution:
#Data
IA - factor(c(1,2,2,3,3,4,3,5,5))
FixTime - c(200,350,500,600,700,850,1200,1350,1500)
#First occurrence of each level
first. - pmatch(levels(IA),IA)
#Use first occurrence to subscript a vector or data frame
FixTime[first.]
A simple way to
Thanks! That did it. I should have seen that I needed the comma!
hadley wrote:
I tried messing with the line df$FixTime[which.min(df$FixInx)] changing
it
to df[which.min(df$FixInx)] or adding new lines with the additional
columns
that I want to include, but nothing seemed to work. I'll
I'm having difficulty finding a solution to my problem that without using a
for loop. For the amount of data I (will) have, the for loop will probably
be too slow. I tried searching around before posting and couldn't find
anything, hopefully it's not embarrassingly easy.
Consider the
one way is:
ind - ave(Data$IA, Data$Sub, Data$Tr, FUN = function (x) !duplicated(x))
Data[as.logical(ind), ]
I hope it helps.
Best,
Dimitris
jwg20 wrote:
I'm having difficulty finding a solution to my problem that without using a
for loop. For the amount of data I (will) have, the for loop
Thank you Mike and Dimitris for your replies.
I was able to get Mike's command to work and it does what I want (and fast
too!) I hadn't looked into the plyr package at all, but I have seen it load
when loading the reshape package. (Another useful package for manipulating
data frames!)
Thanks
On Mon, Mar 30, 2009 at 2:58 PM, Mike Lawrence mike.lawre...@dal.ca wrote:
I discovered Hadley Wickham's plyr package last week and have found
it very useful in circumstances like this:
library(plyr)
firstfixtime = ddply(
.data = data
, .variables = c('Sub','Tr','IA')
,
9 matches
Mail list logo