s-news
[Top] [All Lists]

Re: [S] frequency of data points

To: s-news@wubios.wustl.edu
Subject: Re: [S] frequency of data points
From: Robert Kinley <KINLEY_ROBERT@lilly.com>
Date: Mon, 26 Apr 1999 16:16:51 +0100
Sender: owner-s-news@wubios.wustl.edu



Try this -

:> x_c(9,1,2,4,5,9,1,2,6,2,7)
:> y_c(9,1,2,3,5,9,1,2,4,2,8)
:> xy_cbind(x,y)
:> xy
      x y
 [1,] 9 9
 [2,] 1 1
 [3,] 2 2
 [4,] 4 3
 [5,] 5 5
 [6,] 9 9
 [7,] 1 1
 [8,] 2 2
 [9,] 6 4
[10,] 2 2
[11,] 7 8
:>
:> f<-paste(x,y);
:>
:> f<-factor(f,levels=unique(f));
:>
:> nocc<-rle(sort(f))
:> ans.col<-nocc$lengths[f]
:> ans.col
 [1] 2 2 3 1 1 2 2 3 1 3 1
:> cbind(xy,ans.col)
      x y ans.col
 [1,] 9 9       2
 [2,] 1 1       2
 [3,] 2 2       3
 [4,] 4 3       1
 [5,] 5 5       1
 [6,] 9 9       2
 [7,] 1 1       2
 [8,] 2 2       3
 [9,] 6 4       1
[10,] 2 2       3
[11,] 7 8       1

regards   :   Bob Kinley Site Statistician, Lilly, Liverpool,UK
---------------------------------------------------------------------------------------



Kin Cheung <kin_cheung@alkermes.com> on 26/04/99 15:11:50


To:   "'s-news@wubios.wustl.edu'" <s-news@wubios.wustl.edu>
cc:

Subject:  [S] frequency of data points





Dear S+ users,

     I need to create vector in a data frame indicating the
number of frequency data points. For example,

x_c(9,1,2,4,5,9,1,2,6,2,7)
y_c(9,1,2,3,5,9,1,2,4,2,8)
xy_cbind(x,y)

> xy
      x y
 [1,] 9 9
 [2,] 1 1
 [3,] 2 2
 [4,] 4 3
 [5,] 5 5
 [6,] 9 9
 [7,] 1 1
 [8,] 2 2
 [9,] 6 4
[10,] 2 2
[11,] 7 8


The output that I need would be

> xy
      x y z
 [1,] 9 9 2
 [2,] 1 1 2
 [3,] 2 2 3
 [4,] 4 3 1
 [5,] 5 5 1
 [6,] 9 9 2
 [7,] 1 1 2
 [8,] 2 2 3
 [9,] 6 4 1
[10,] 2 2 3
[11,] 7 8 1

The new vector Z is the number of occurrence of the data points X and Y.

Any help from anyone would be great appreciated.

--cheung







-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news




-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>