vec1<- c(0,1,1,1,2,2,2,3,3)
length(unique(vec1[vec1!=0]))
#[1] 3
vec2<- c(0,2,2,3)
length(unique(vec2[vec2!=0]))
#[1] 2
A.K.
>Hi. I have a new question.
>I need count the different numbers in a vector,but different of zero.
>I mean,if I have c(0,2,2,3) the result is 2. If the
>vector is c(
mns to count
> (val1 and val2)?
>
>
> Betreff: Re: [R] Count values in a dataframe with respect to groups
>
> Try this:
>
> aggregate(val ~ grp, dta, length)
>
> On Fri, Oct 8, 2010 at 11:28 AM, Marcus Drescher wrote:
> Dear all,
>
> I am looking for a fun
alifornia, USA
- Original Message
> From: Marcus Drescher
> To: "r-help@r-project.org"
> Sent: Fri, October 8, 2010 8:04:40 AM
> Subject: Re: [R] Count values in a dataframe with respect to groups
>
> Thanks! It works great.
>
> One more question: how would I have
spronkelijk bericht-
> Van: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] Namens Marcus Drescher
> Verzonden: vrijdag 8 oktober 2010 16:29
> Aan: r-help@r-project.org
> Onderwerp: [R] Count values in a dataframe with respect to groups
>
> Dear all,
>
I am sorry for the typo, it is about counting two columns an skipping the NAs.
How would I have to set the formula if I would have two columns to count (val1
and val2)?
Betreff: Re: [R] Count values in a dataframe with respect to groups
Try this:
aggregate(val ~ grp, dta, length)
On Fri
Thanks! It works great.
One more question: how would I have to set the formula if I would have the
columns to count (val1 and val2)?
Betreff: Re: [R] Count values in a dataframe with respect to groups
Try this:
aggregate(val ~ grp, dta, length)
On Fri, Oct 8, 2010 at 11:28 AM, Marcus
Try this:
aggregate(val ~ grp, dta, length)
On Fri, Oct 8, 2010 at 11:28 AM, Marcus Drescher wrote:
> Dear all,
>
> I am looking for a function to count values belonging to a class within a
> dataframe (and ignore NAs).
>
> grp = c(1,1,1, 1,2, 2,2)
> val = c(2,1,5,NA,3,NA,1)
>
> dta = data.fra
Dear all,
I am looking for a function to count values belonging to a class within a
dataframe (and ignore NAs).
grp = c(1,1,1, 1,2, 2,2)
val = c(2,1,5,NA,3,NA,1)
dta = data.frame(grp=grp, val=val)
The result should look like:
grp count
13
22
At the moment, I am trying to find a fun
8 matches
Mail list logo