[R] Writing out data from a list

2011-01-13 Thread Aaron Lee
Hello,

I have a list of data, such that:

[[1]]
 [1] 0.00 0.00 0.03 0.01 0.00 0.00 0.00 0.00 0.01 0.01 0.00 0.00 0.01 0.00
0.00 0.03 0.01 0.00 0.01 0.00 0.03 0.16 0.14 0.02 0.17 0.01 0.01 0.00 0.00
0.03 0.00 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00
[42] 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00 0.04 0.08 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00

[[2]]
 [1] 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.07 0.00 0.00 0.03 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00

[[3]]
 [1] 0.00 0.00 0.00 0.00 0.00 0.00 0.01 0.00 0.00 0.01 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

etc.

I would like to write to a text file with this data, but would like each
section of the file to be separated by some text. For example:

Event 1
Random Text
0
0
0.03
0.01

Event 2
Random Text
0
0
0
0
0.01

etc.

Is there some way to continually write text out using a loop and also
attaching a string before each data segment? Thank you in advance!
-Aaron

[[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] Generate random percentages and placing vectors

2010-10-28 Thread Aaron Lee
Thanks for the help!

However, for the code in #2, it seems to just randomly split up the vectors.
I would still like to keep the integrity of each vector.

For example:

if v1 = (1,2,3)
   v2 = (4,5,6)

output = (0,0,0,1,2,3,0,0,0,0,4,5,6,0,0,0,0,0,0,0,0,0,0,0,0) - which has a
specified length of 25

With v1 and v2 inserted in at random locations.

On Wed, Oct 27, 2010 at 10:25 AM, Jonathan P Daily jda...@usgs.gov wrote:


 1)
 rands - runif(5)
 rands - rands/sum(rands)*100

 2)
 # assume vectors are v1, v2, etc.
 v_all - c(v1, v2, ...)
 v_len - length(v_all)

 output - rep(0,25)
 output[sample(1:25, v_len)] - v_all

 --
 Jonathan P. Daily
 Technician - USGS Leetown Science Center
 11649 Leetown Road
 Kearneysville WV, 25430
 (304) 724-4480
 Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly


  From: Aaron Lee aaron.zl@gmail.com To: r-help@r-project.org Date: 
 10/27/2010
 11:06 AM Subject: [R] Generate random percentages and placing vectors Sent
 by: r-help-boun...@r-project.org
 --



 Hello everyone,

 I have two questions:

 1.) I would like to generate random percentages that add up to 100. For
 example, if I need 5 percentages, I would obtain something like: 20, 30,
 40,
 5, 5. Is there some way to do this in R?

 2.) I would like to insert vectors of specified length into a larger vector
 of specified length randomly, and fill the gaps with zeroes. For example,
 if
 I have 3 vectors of length 3, 2, and 2 with values and I would like to
 randomly place them into a vector of length 25 made of 0's.

 Thank you in advance!

 -Aaron

 [[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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




[[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.