Re: [R] (no subject)

From: Johannes Huesing <johannes_at_huesing.name>
Date: Tue, 18 Nov 2008 22:55:27 +0100

Salas, Andria Kay <aks2515_at_uncw.edu> [Tue, Nov 18, 2008 at 04:10:06PM CET]:
> I need help with another problem I am having that deals with the generation of vectors that I asked about yesterday. I now need to have each value in the vector (all values either 1 or -1) have a probability p that it will switch signs (so, say, each value has a 50% chance of switching from -1 to 1 or visa versa). What would be the best way to go about doing this? Thank-you!!

Say you have a vector v, you can generate another vector randomly by

w <- sample(c(-1, 1), length(v), replace=TRUE)

and multiply v with w.

-- 
Johannes Hüsing               There is something fascinating about science. 
                              One gets such wholesale returns of conjecture 
mailto:johannes_at_huesing.name  from such a trifling investment of fact.                
http://derwisch.wikidot.com         (Mark Twain, "Life on the Mississippi")

______________________________________________
R-help_at_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.
Received on Tue 18 Nov 2008 - 21:59:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 18 Nov 2008 - 22:30:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive