Hadley and Dennis:
THANK YOU THANK YOU! This is exactly what I was looking for.
Ryan
On Wed, Jan 26, 2011 at 5:27 AM, Dennis Murphy wrote:
> > Hi:
> >
> > Here are two more candidates, using the plyr and data.table packages:
> >
> > library(plyr)
> > ddply(X, .(x, y), function(d) length(unique
On Wed, Jan 26, 2011 at 5:27 AM, Dennis Murphy wrote:
> Hi:
>
> Here are two more candidates, using the plyr and data.table packages:
>
> library(plyr)
> ddply(X, .(x, y), function(d) length(unique(d$z)))
> x y V1
> 1 1 1 2
> 2 1 2 2
> 3 2 3 2
> 4 2 4 2
> 5 3 5 2
> 6 3 6 2
>
> The function
Note that a key is not actually required, so it's even simpler syntax :
dX = as.data.table(X)
dX[,length(unique(z)),by="x,y"]
x y V1
[1,] 1 1 2
[2,] 1 2 2
[3,] 2 3 2
[4,] 2 4 2
[5,] 3 5 2
[6,] 3 6 2
or passing list() syntax to the 'by' is exactly the same :
dX[,length(unique(z)),by=l
Hi:
Here are two more candidates, using the plyr and data.table packages:
library(plyr)
ddply(X, .(x, y), function(d) length(unique(d$z)))
x y V1
1 1 1 2
2 1 2 2
3 2 3 2
4 2 4 2
5 3 5 2
6 3 6 2
The function counts the number of unique z values in each sub-data frame
with the same x and y
On Jan 25, 2011, at 2:25 PM, Ryan Utz wrote:
Hi R-users,
I'm trying to find an elegant way to count the number of rows in a
dataframe
with a unique combination of 2 values in the dataframe. My data is
specifically one column with a year, one with a month, and one with
a day.
I'm trying to
Hi Ryan,
One option would be
X$a <- paste(X$x, X$y, sep=".")
table(X$a)
Best,
Ista
On Tue, Jan 25, 2011 at 2:25 PM, Ryan Utz wrote:
> Hi R-users,
>
> I'm trying to find an elegant way to count the number of rows in a dataframe
> with a unique combination of 2 values in the dataframe. My data is
If you want count:
xtabs( ~ x + y, X)
or sum:
xtabs(z ~ x + y, X)
On Tue, Jan 25, 2011 at 5:25 PM, Ryan Utz wrote:
> Hi R-users,
>
> I'm trying to find an elegant way to count the number of rows in a
> dataframe
> with a unique combination of 2 values in the dataframe. My data is
> specifi
Hi R-users,
I'm trying to find an elegant way to count the number of rows in a dataframe
with a unique combination of 2 values in the dataframe. My data is
specifically one column with a year, one with a month, and one with a day.
I'm trying to count the number of days in each year/month combinati
8 matches
Mail list logo