Re: [R] Programing and writing function help

2008-10-16 Thread Stephen Cole
Thank- you all for you suggestions and help.  I have now resolved my
issue.   This help forum is one of the things that makes R a great platform
for statistics.

Stephen Cole
Marine Ecology Lab
Saint Francis Xavier University

On Wed, Oct 8, 2008 at 8:07 AM, Erin Hodgess [EMAIL PROTECTED]wrote:

 Actually, you will have duplicates with 400 pairs.

 Here you will have 13^2 pairs with replacement and 13*12 pairs without
 replacement and with regard to order.
 How about this:
  z - unique(x)
  y - expand.grid(z[1:13],z[1:13])
  xx - y[,1] != y[,2]
  y[xx,]

 Just another thought.

 Erin


 On Wed, Oct 8, 2008 at 5:55 AM, Erin Hodgess [EMAIL PROTECTED]
 wrote:
  For all possible pairs, you'll have 20^2 pairs.
  This is a way to do it:
 
  expand.grid(x[1:20],x[1:20])
 
  HTH,
  Erin
 
 
  On Wed, Oct 8, 2008 at 4:43 AM, Jim Lemon [EMAIL PROTECTED] wrote:
  Stephen Cole wrote:
 
  ...
  I have a vector of 20 values
 
  x - c(20,18, 45, 16, 47, 47, 15, 26,
 14,14,12,16,35,27,18,94,16,26,26,30)
 
  1.
  I  want to select random pairs from this data set but do it without
  replacement exhaustively
 
 
  matrix(x[sample(1:20,20)],nrow=2)
 
  then step through the columns of the resulting matrix
 
  I know i can select random pairs without replacement using
 
  sample(N,n,replace=F)
  However i am wondering if there is any way to get 10 random pairs from
  this
  data set without repeating any of the data points
  that is to say if i got a (20, 94) for one pair, i would like to get 9
  other
  pairs from the data without again getting 20 or 94?
 
  2.
  The second thing i would like to do is be able to select all possible
  pairs
  of numbers and calculate each pairs variance.
 
  I think you want to use the combn function, but you are going to get a
 lot
  of pairs...
 
  Jim
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
  --
  Erin Hodgess
  Associate Professor
  Department of Computer and Mathematical Sciences
  University of Houston - Downtown
  mailto: [EMAIL PROTECTED]
 



 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: [EMAIL PROTECTED]


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Programing and writing function help

2008-10-08 Thread Jim Lemon

Stephen Cole wrote:

...
I have a vector of 20 values

x - c(20,18, 45, 16, 47, 47, 15, 26, 14,14,12,16,35,27,18,94,16,26,26,30)

1.
I  want to select random pairs from this data set but do it without
replacement exhaustively
  

matrix(x[sample(1:20,20)],nrow=2)

then step through the columns of the resulting matrix

I know i can select random pairs without replacement using

sample(N,n,replace=F)
However i am wondering if there is any way to get 10 random pairs from this
data set without repeating any of the data points
that is to say if i got a (20, 94) for one pair, i would like to get 9 other
pairs from the data without again getting 20 or 94?

2.
The second thing i would like to do is be able to select all possible pairs
of numbers and calculate each pairs variance.
I think you want to use the combn function, but you are going to get a 
lot of pairs...


Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Programing and writing function help

2008-10-08 Thread Erin Hodgess
Actually, you will have duplicates with 400 pairs.

Here you will have 13^2 pairs with replacement and 13*12 pairs without
replacement and with regard to order.
How about this:
 z - unique(x)
 y - expand.grid(z[1:13],z[1:13])
 xx - y[,1] != y[,2]
 y[xx,]

Just another thought.

Erin


On Wed, Oct 8, 2008 at 5:55 AM, Erin Hodgess [EMAIL PROTECTED] wrote:
 For all possible pairs, you'll have 20^2 pairs.
 This is a way to do it:

 expand.grid(x[1:20],x[1:20])

 HTH,
 Erin


 On Wed, Oct 8, 2008 at 4:43 AM, Jim Lemon [EMAIL PROTECTED] wrote:
 Stephen Cole wrote:

 ...
 I have a vector of 20 values

 x - c(20,18, 45, 16, 47, 47, 15, 26, 14,14,12,16,35,27,18,94,16,26,26,30)

 1.
 I  want to select random pairs from this data set but do it without
 replacement exhaustively


 matrix(x[sample(1:20,20)],nrow=2)

 then step through the columns of the resulting matrix

 I know i can select random pairs without replacement using

 sample(N,n,replace=F)
 However i am wondering if there is any way to get 10 random pairs from
 this
 data set without repeating any of the data points
 that is to say if i got a (20, 94) for one pair, i would like to get 9
 other
 pairs from the data without again getting 20 or 94?

 2.
 The second thing i would like to do is be able to select all possible
 pairs
 of numbers and calculate each pairs variance.

 I think you want to use the combn function, but you are going to get a lot
 of pairs...

 Jim

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: [EMAIL PROTECTED]




-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: [EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Programing and writing function help

2008-10-08 Thread Erin Hodgess
For all possible pairs, you'll have 20^2 pairs.
This is a way to do it:

expand.grid(x[1:20],x[1:20])

HTH,
Erin


On Wed, Oct 8, 2008 at 4:43 AM, Jim Lemon [EMAIL PROTECTED] wrote:
 Stephen Cole wrote:

 ...
 I have a vector of 20 values

 x - c(20,18, 45, 16, 47, 47, 15, 26, 14,14,12,16,35,27,18,94,16,26,26,30)

 1.
 I  want to select random pairs from this data set but do it without
 replacement exhaustively


 matrix(x[sample(1:20,20)],nrow=2)

 then step through the columns of the resulting matrix

 I know i can select random pairs without replacement using

 sample(N,n,replace=F)
 However i am wondering if there is any way to get 10 random pairs from
 this
 data set without repeating any of the data points
 that is to say if i got a (20, 94) for one pair, i would like to get 9
 other
 pairs from the data without again getting 20 or 94?

 2.
 The second thing i would like to do is be able to select all possible
 pairs
 of numbers and calculate each pairs variance.

 I think you want to use the combn function, but you are going to get a lot
 of pairs...

 Jim

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: [EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Programing and writing function help

2008-10-07 Thread Stephen Cole
Hello R users

My goal is to use R to write functions for and automate a series of analyses
i would like to do on a large data set.  The calculations are not very
difficult in themselves, however they will be very time consuming (Plus I
think R will be extremely useful and this is another excuse to learn how to
program).

I have a vector of 20 values

x - c(20,18, 45, 16, 47, 47, 15, 26, 14,14,12,16,35,27,18,94,16,26,26,30)

1.
I  want to select random pairs from this data set but do it without
replacement exhaustively

I know i can select random pairs without replacement using

sample(N,n,replace=F)
However i am wondering if there is any way to get 10 random pairs from this
data set without repeating any of the data points
that is to say if i got a (20, 94) for one pair, i would like to get 9 other
pairs from the data without again getting 20 or 94?

2.
The second thing i would like to do is be able to select all possible pairs
of numbers and calculate each pairs variance.  I think i will need a for
loop here but I am unsure of how to do the programing.  I am reading two
books on S and s-plus now and hope they are some help.  I thought i would
also post on this list and get some expert advice for the more experienced R
users

Thank-you very much

Stephen Cole
Marine Ecology Lab
Saint Francis Xavier University

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Programing and writing function help

2008-10-07 Thread jim holtman
Here is one way that might work for you:

 x - c(20,18, 45, 16, 47, 47, 15, 26, 14,14,12,16,35,27,18,94,16,26,26,30)
 # create a matrix of pairs
 matrix(sample(x), ncol=2)
  [,1] [,2]
 [1,]   14   16
 [2,]   27   20
 [3,]   26   16
 [4,]   47   15
 [5,]   35   47
 [6,]   16   18
 [7,]   14   12
 [8,]   18   26
 [9,]   45   26
[10,]   94   30
 # all possible pairs
 # create a matrix of the dimensions x*x and the the indices of the lower 
 triangle
 ind - which(lower.tri(matrix(1,length(x), length(x))), arr.ind=TRUE)
 # create the pairs
 x.pairs - cbind(x[ind[,1]], x[ind[,2]])
 str(x.pairs)
 num [1:190, 1:2] 18 45 16 47 47 15 26 14 14 12 ...
 head(x.pairs)
 [,1] [,2]
[1,]   18   20
[2,]   45   20
[3,]   16   20
[4,]   47   20
[5,]   47   20
[6,]   15   20


On Tue, Oct 7, 2008 at 1:50 PM, Stephen Cole [EMAIL PROTECTED] wrote:
 Hello R users

 My goal is to use R to write functions for and automate a series of analyses
 i would like to do on a large data set.  The calculations are not very
 difficult in themselves, however they will be very time consuming (Plus I
 think R will be extremely useful and this is another excuse to learn how to
 program).

 I have a vector of 20 values

 x - c(20,18, 45, 16, 47, 47, 15, 26, 14,14,12,16,35,27,18,94,16,26,26,30)

 1.
 I  want to select random pairs from this data set but do it without
 replacement exhaustively

 I know i can select random pairs without replacement using

 sample(N,n,replace=F)
 However i am wondering if there is any way to get 10 random pairs from this
 data set without repeating any of the data points
 that is to say if i got a (20, 94) for one pair, i would like to get 9 other
 pairs from the data without again getting 20 or 94?

 2.
 The second thing i would like to do is be able to select all possible pairs
 of numbers and calculate each pairs variance.  I think i will need a for
 loop here but I am unsure of how to do the programing.  I am reading two
 books on S and s-plus now and hope they are some help.  I thought i would
 also post on this list and get some expert advice for the more experienced R
 users

 Thank-you very much

 Stephen Cole
 Marine Ecology Lab
 Saint Francis Xavier University

[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.