[R] Sample without replacement

2004-09-22 Thread Mark G Orr
Hello, I have a simple problem (checked the archives and the appropriate 
help pages, to no avail).  I want to creat a vector that is length(2000). 
The vector is to consist of two strings( std and dev) with 1760 stds 
and 240 devs.  Furthermore, for each element of the vector, i want the 
selection of one of the strings to be approx. random.  The end result will 
be a vector with the following proportions:  .12 dev and .88 std. 
My solution, below, almost works, but i don't get the exact desired 
proportions:

sample.from.vector - c(rep(std,1760),rep(dev,240))
make.vector - rep(99,2000)
for (i in 1:2000){
  make.vector[i] - sample(sample.from.vector,1,replace=F)
}
As I understand the above code (which is not very well, obviously), each 
iteration assigns one element from the sample.from.vector  to the current 
make.vector element;  the element choosen from sample.from.vector is 
tagged so that i is not selected again.  However, after the loop, 
make.vector contains, for example, 1758 stds  and 242 devs.  Each 
iteration results in a different proportion of stds and devs (although 
close to the desired, not right on).

Any help would be greatly apprecitated.
-Mark Orr



Mark G. Orr
Postdoctoral Research Fellow
Dept. of Neuroscience
RM 825 Kennedy Center
Albert Einstein College of Medicine
Bronx, NY  10461
718-430-2610
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] THanks, random/repl. prob. SOLVED.

2004-09-22 Thread Mark G Orr
Thanks for the help, it worked.



Mark G. Orr
Postdoctoral Research Fellow
Dept. of Neuroscience
RM 825 Kennedy Center
Albert Einstein College of Medicine
Bronx, NY  10461
718-430-2610
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] SORTING Arrays by index value

2003-02-04 Thread Mark G Orr
Hello, I'm somewhat new to R.  I've searched the archive for the last year
and tried to consult the manual pages for the following problem, but did
not find an answer.

I want to sort an array by the index values.  Here is the array

acc.gp.bl.wtmn
Gp17   Gp4
1  0.5703125 0.6406250
10 0.7812500 0.7109375
11 0.8046875 0.7343750
12 0.8359375 0.7890625
13 0.8515625 0.7109375
14 0.8281250 0.7343750
15 0.8671875 0.7812500
16 0.8125000 0.7578125
17 0.7734375 0.750
18 0.800 0.780
19 0.870 0.730
2  0.8046875 0.7265625
20 0.830 0.740
21 0.750 0.800
22 0.770 0.760
23 0.820 0.780
24 0.760 0.740
25 0.810 0.800
3  0.7578125 0.7812500
4  0.8203125 0.7890625
5  0.7890625 0.7421875
6  0.7265625 0.7812500
7  0.8125000 0.7421875
8  0.8515625 0.7265625
9  0.8203125 0.6953125

My question is:  How do I sort by the first index (the values are 1:25)
without losing the associated values per index value for the two
columns(Gp17 and Gp4).  I want ascending order (1:25) of the index values.

Thank you in advance.

-Mark Orr



Postdoctoral Fellow
Psychology Dept.
Carnegie Mellon Univ.
Pittsburgh, PA 15213

__
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help