, 7 May, 2008 7:14:28 PM
Subject: Re: [R] help with the unique function
Another way to produce the data frame is
subset(as.data.frame(table(x)),Freq0)
- Phil Spector
Statistical Computing Facility
Department
Ravi,
if you have a large data.frame you might want to have a look at the count.rows
function I collected from older threads and put into the wiki
(http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:count_and_extract_unique_rows)
WIth table I run into memory trouble - just as with
Hi,
The unique function is easy to understand and use. Beyond that, I want to get
also the frequency of repetition of each individual row in a data frame
Let me explain with an example :
x-data.frame(a=c(1,2,3,1,2),b=c(2,3,4,2,3),c=c(10,20,30,10,20))
xu-unique(x)
We have,
x
a b c
1 1 2 10
2 2
Hi Ravi,
Try this:
x-data.frame(a=c(1,2,3,1,2),b=c(2,3,4,2,3),c=c(10,20,30,10,20))
cbind(unique(x),lapply(x,table)$c)[,-4]
a b c Freq
1 1 2 102
2 2 3 202
3 3 4 301
HTH,
Jorge
On Wed, May 7, 2008 at 12:11 PM, ravi [EMAIL PROTECTED] wrote:
Hi,
The unique function is easy to
ravi -
This may get you started
count.reps - function(df) {
hash - do.call(paste, c(df, sep = \r))
cbind(unique(df), Freq = unclass(table(hash)))
}
test - data.frame(a = rep(1:10, 2), b = rep(1:10, 2))
count.reps(test)
Best,
Erik Iverson
ravi wrote:
Hi,
The unique function is easy to
ravi wrote:
Hi,
The unique function is easy to understand and use. Beyond that, I want to get
also the frequency of repetition of each individual row in a data frame
Let me explain with an example :
x-data.frame(a=c(1,2,3,1,2),b=c(2,3,4,2,3),c=c(10,20,30,10,20))
xu-unique(x)
We have,
x
a b
On 07-May-08 16:31:23, Erik Iverson wrote:
ravi -
This may get you started
count.reps - function(df) {
hash - do.call(paste, c(df, sep = \r))
cbind(unique(df), Freq = unclass(table(hash)))
}
test - data.frame(a = rep(1:10, 2), b = rep(1:10, 2))
count.reps(test)
That doesn't
Another way to produce the data frame is
subset(as.data.frame(table(x)),Freq0)
- Phil Spector
Statistical Computing Facility
Department of Statistics
8 matches
Mail list logo