[R] Using the R commands

Jonathan Baron baron at cattell.psych.upenn.edu
Sun Mar 30 05:48:36 CEST 2003


On 03/30/03 03:25, Marcus V. Stecklow wrote:

>I`m doing a program and it`s have a loop using the for command. inside the 
>loop i have a variable and in each step of loop she have a new value.
>
>The question is: How can i store the values and make a table?

For example:
Squares <- rep(NA,10) # make an empty vector with 10 places
for (i in 1:10) Squares[i] <- i^2 # fill it with squares
Squares # print it

Lots of other ways to do this.  For example, you can use
Squares <- {}
for the first step.
-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
R page:               http://finzi.psych.upenn.edu/



More information about the R-help mailing list