[R] Iterations of random sampling

2009-03-11 Thread René Pineda

I have a univariate binary (1,0) 230,000 records, I need to make 20,000 
iterations of random sampling of a fixed size. Where I put the result of the 
sum of selected records for each repetition
 
 
Thank's
 
 
_

of your life

[[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] Iterations of random sampling

2009-03-11 Thread Chuck Cleland
On 3/11/2009 3:15 PM, René Pineda wrote:
 I have a univariate binary (1,0) 230,000 records, I need to make 20,000 
 iterations of random sampling of a fixed size. Where I put the result of the 
 sum of selected records for each repetition

X - rbinom(23, 1, .5)

sample.sums - replicate(2, sum(sample(X, 10)))

 Thank's
  
 _
 
 of your life
 
   [[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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
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] Iterations

2008-07-15 Thread rkevinburton
I have a command that reads in some data:

x - read.csv(Sales2007.dat, header=TRUE)

Then I try to organize the data:

sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)

Then I want to iterate through the data. I was able to get the following to run 
on the R console:

for(i in 1:length(sc))
{
sum(sc[[i]]$Quantity)
}

But notiing is primted on the console. I find that:

for(i in 1:100)
{
i
}

Also does't output anything? I am probably making a wrong assumption here. Why 
desn't the loop seem to output anyything?

Thank you.

Kevin

__
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] Iterations

2008-07-15 Thread Stephan Kolassa

Kevin,

By default, many functions only *return* a result, they don't explicitly 
*print* it. There is no difference in interactive mode, but there is in 
batch mode (e.g., in loops). Use print() or cat() for explicit printing 
to console.


for(i in 1:100)
{
cat(i,\n)
}

HTH,
Stephan


[EMAIL PROTECTED] schrieb:

I have a command that reads in some data:

x - read.csv(Sales2007.dat, header=TRUE)

Then I try to organize the data:

sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)

Then I want to iterate through the data. I was able to get the following to run 
on the R console:

for(i in 1:length(sc))
{
sum(sc[[i]]$Quantity)
}

But notiing is primted on the console. I find that:

for(i in 1:100)
{
i
}

Also does't output anything? I am probably making a wrong assumption here. Why 
desn't the loop seem to output anyything?

Thank you.

Kevin

__
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-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] Iterations

2008-07-15 Thread Jeff Newmiller

[EMAIL PROTECTED] wrote:

I have a command that reads in some data:

x - read.csv(Sales2007.dat, header=TRUE)

Then I try to organize the data:

sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)

Then I want to iterate through the data. I was able to get the following to run 
on the R console:

for(i in 1:length(sc))
{
sum(sc[[i]]$Quantity)
}

But notiing is primted on the console. I find that:

for(i in 1:100)
{
i
}

Also does't output anything? I am probably making a wrong assumption here. Why 
desn't the loop seem to output anyything?

Thank you.


Entering an expression interactively behaves differently than entering
one in the context of another statement or function.

See the FAQ:

http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html#Why-is-the-output-not-printed-when-I-source_0028_0029-a-file_003f

--
---
Jeff NewmillerThe .   .  Go Live...
DCN:[EMAIL PROTECTED]Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k

__
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] Iterations

2008-07-15 Thread Michael Rennie
for(1 in 1:10)
 {
 print(i)
 }

Mike

On Tue, Jul 15, 2008 at 1:11 PM,  [EMAIL PROTECTED] wrote:
 I have a command that reads in some data:

 x - read.csv(Sales2007.dat, header=TRUE)

 Then I try to organize the data:

 sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)

 Then I want to iterate through the data. I was able to get the following to 
 run on the R console:

 for(i in 1:length(sc))
 {
sum(sc[[i]]$Quantity)
 }

 But notiing is primted on the console. I find that:

 for(i in 1:100)
 {
i
 }

 Also does't output anything? I am probably making a wrong assumption here. 
 Why desn't the loop seem to output anyything?

 Thank you.

 Kevin

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




-- 
--
Michael D. Rennie
Ph.D. Candidate
University of Toronto at Mississauga
3359 Missisagua Rd. N.
Mississauga, ON L5L 1C6
Ph: 905-828-5452 Fax: 905-828-3792
www.utm.utoronto.ca/~w3rennie

__
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] Iterations

2008-07-15 Thread Michael Rennie
Oops, typo- sorry, should be

for(i in 1:10)
 {
 print(i)
 }

Mike

On Tue, Jul 15, 2008 at 1:39 PM, Michael Rennie [EMAIL PROTECTED] wrote:
 for(1 in 1:10)
 {
 print(i)
 }

 Mike

 On Tue, Jul 15, 2008 at 1:11 PM,  [EMAIL PROTECTED] wrote:
 I have a command that reads in some data:

 x - read.csv(Sales2007.dat, header=TRUE)

 Then I try to organize the data:

 sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)

 Then I want to iterate through the data. I was able to get the following to 
 run on the R console:

 for(i in 1:length(sc))
 {
sum(sc[[i]]$Quantity)
 }

 But notiing is primted on the console. I find that:

 for(i in 1:100)
 {
i
 }

 Also does't output anything? I am probably making a wrong assumption here. 
 Why desn't the loop seem to output anyything?

 Thank you.

 Kevin

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




 --
 --
 Michael D. Rennie
 Ph.D. Candidate
 University of Toronto at Mississauga
 3359 Missisagua Rd. N.
 Mississauga, ON L5L 1C6
 Ph: 905-828-5452 Fax: 905-828-3792
 www.utm.utoronto.ca/~w3rennie




-- 
--
Michael D. Rennie
Ph.D. Candidate
University of Toronto at Mississauga
3359 Missisagua Rd. N.
Mississauga, ON L5L 1C6
Ph: 905-828-5452 Fax: 905-828-3792
www.utm.utoronto.ca/~w3rennie

__
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] Iterations

2008-07-15 Thread Erik Iverson

If you read the help page, ?for, you might have seen under Value, that

 'for', 'while' and 'repeat' return the value of the last
 expression evaluated (or 'NULL' if none was), invisibly.

So if you want to see the values, print() them.

In general, from the first part of your message, it looks like you're 
trying to run some analysis on different subgroups of your data.


You may want to try the functions tapply, by, aggregate, ave, etc., for 
this purpose rather than using 'for' loops.


Best,
Erik Iverson


[EMAIL PROTECTED] wrote:

I have a command that reads in some data:

x - read.csv(Sales2007.dat, header=TRUE)

Then I try to organize the data:

sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)

Then I want to iterate through the data. I was able to get the following to run 
on the R console:

for(i in 1:length(sc))
{
sum(sc[[i]]$Quantity)
}

But notiing is primted on the console. I find that:

for(i in 1:100)
{
i
}

Also does't output anything? I am probably making a wrong assumption here. Why 
desn't the loop seem to output anyything?

Thank you.

Kevin

__
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-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] Iterations

2008-07-15 Thread rkevinburton
Sorry I missed the print part. When nothing was output I assumed that nothing 
happened.

Thank you.

Kevin
 Erik Iverson [EMAIL PROTECTED] wrote: 
 If you read the help page, ?for, you might have seen under Value, that
 
   'for', 'while' and 'repeat' return the value of the last
   expression evaluated (or 'NULL' if none was), invisibly.
 
 So if you want to see the values, print() them.
 
 In general, from the first part of your message, it looks like you're 
 trying to run some analysis on different subgroups of your data.
 
 You may want to try the functions tapply, by, aggregate, ave, etc., for 
 this purpose rather than using 'for' loops.
 
 Best,
 Erik Iverson
 
 
 [EMAIL PROTECTED] wrote:
  I have a command that reads in some data:
  
  x - read.csv(Sales2007.dat, header=TRUE)
  
  Then I try to organize the data:
  
  sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)
  
  Then I want to iterate through the data. I was able to get the following to 
  run on the R console:
  
  for(i in 1:length(sc))
  {
  sum(sc[[i]]$Quantity)
  }
  
  But notiing is primted on the console. I find that:
  
  for(i in 1:100)
  {
  i
  }
  
  Also does't output anything? I am probably making a wrong assumption here. 
  Why desn't the loop seem to output anyything?
  
  Thank you.
  
  Kevin
  
  __
  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-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] Iterations

2008-07-15 Thread rkevinburton
Thank you.

?for just gives me a + rompt indicating that I need to supply more input. The 
same with ?while and ?repeat. Help(for) yelds:

  help(for)
Error: unexpected ')' in help(for)

But thanks for the tip.

Keivn

 Erik Iverson [EMAIL PROTECTED] wrote: 
 If you read the help page, ?for, you might have seen under Value, that
 
   'for', 'while' and 'repeat' return the value of the last
   expression evaluated (or 'NULL' if none was), invisibly.
 
 So if you want to see the values, print() them.
 
 In general, from the first part of your message, it looks like you're 
 trying to run some analysis on different subgroups of your data.
 
 You may want to try the functions tapply, by, aggregate, ave, etc., for 
 this purpose rather than using 'for' loops.
 
 Best,
 Erik Iverson
 
 
 [EMAIL PROTECTED] wrote:
  I have a command that reads in some data:
  
  x - read.csv(Sales2007.dat, header=TRUE)
  
  Then I try to organize the data:
  
  sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)
  
  Then I want to iterate through the data. I was able to get the following to 
  run on the R console:
  
  for(i in 1:length(sc))
  {
  sum(sc[[i]]$Quantity)
  }
  
  But notiing is primted on the console. I find that:
  
  for(i in 1:100)
  {
  i
  }
  
  Also does't output anything? I am probably making a wrong assumption here. 
  Why desn't the loop seem to output anyything?
  
  Thank you.
  
  Kevin
  
  __
  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-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] Iterations

2008-07-15 Thread Erik Iverson

Sorry, I'm in ESS.

Try ?Control

[EMAIL PROTECTED] wrote:

Thank you.

?for just gives me a + rompt indicating that I need to supply more input. The 
same with ?while and ?repeat. Help(for) yelds:

  help(for)
Error: unexpected ')' in help(for)

But thanks for the tip.

Keivn

 Erik Iverson [EMAIL PROTECTED] wrote: 

If you read the help page, ?for, you might have seen under Value, that

  'for', 'while' and 'repeat' return the value of the last
  expression evaluated (or 'NULL' if none was), invisibly.

So if you want to see the values, print() them.

In general, from the first part of your message, it looks like you're 
trying to run some analysis on different subgroups of your data.


You may want to try the functions tapply, by, aggregate, ave, etc., for 
this purpose rather than using 'for' loops.


Best,
Erik Iverson


[EMAIL PROTECTED] wrote:

I have a command that reads in some data:

x - read.csv(Sales2007.dat, header=TRUE)

Then I try to organize the data:

sc - split(x, list(x$Category, x$SubCategory), drop=TRUE)

Then I want to iterate through the data. I was able to get the following to run 
on the R console:

for(i in 1:length(sc))
{
sum(sc[[i]]$Quantity)
}

But notiing is primted on the console. I find that:

for(i in 1:100)
{
i
}

Also does't output anything? I am probably making a wrong assumption here. Why 
desn't the loop seem to output anyything?

Thank you.

Kevin

__
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-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] Iterations

2008-07-15 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of 
 [EMAIL PROTECTED]
 Sent: Tuesday, July 15, 2008 12:40 PM
 To: Erik Iverson
 Cc: [EMAIL PROTECTED]
 Subject: Re: [R] Iterations
 
 Thank you.
 
 ?for just gives me a + rompt indicating that I need to supply 
 more input. The same with ?while and ?repeat. Help(for) yelds:

You need to enclose R language keywords in quotes, i.e.

?'for' 
help('for')
?'while'
?'repeat'

 
   help(for)
 Error: unexpected ')' in help(for)
 
 But thanks for the tip.
 
 Keivn
 
snip

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204
 
 

__
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] Iterations

2008-07-15 Thread Rolf Turner


On 16/07/2008, at 7:40 AM, [EMAIL PROTECTED]  
[EMAIL PROTECTED] wrote:



Thank you.

?for just gives me a + rompt indicating that I need to supply more  
input. The same with ?while and ?repeat. Help(for) yelds:



help(for)

Error: unexpected ')' in help(for)

But thanks for the tip.


?help or help(help)

I.e. RTFM!!!

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

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