writing to a dataframe from a for-loop in R

Posted by CCID on Stack Overflow See other posts from Stack Overflow or by CCID
Published on 2010-04-01T21:30:44Z Indexed on 2010/04/01 21:33 UTC
Read the original article Hit count: 274

Filed under:
|
|

I'm trying to write from a loop to a data frame in R, for example a loop like this>

for (i in 1:20) {
print(c(i+i,i*i,i/1))}

and to write each line of 3 values to a data frame with three columns, so that each iteration takes on a new row. I've tried using matrix, with ncol=3 and filled by rows, but only get the last item from the loop.

Thanks.

© Stack Overflow or respective owner

Related posts about r

    Related posts about for-loop