[R-SIG-Finance] for loop help

Brian G. Peterson brian at braverock.com
Fri Sep 10 17:29:04 CEST 2010


Please direct this inquiry to r-help, not the finance list, per the 
footer of every email to this list.

On 09/10/2010 10:12 AM, alfredo wrote:
> I have a 2-dim data.matrix(e.g., table1) in which row1 specifies a range of
> values. row2 - rown specify the number of times I want to replicate each
> corresponding value in row1. I can do this with the following function:
>
> rep(c(table1[1,]),c(table1[X,])) #where X would go from 2 - n.
>
> Now, I can do this manually by changing the values of X and save each
> resulting array/vector in an object, or write a for loop that will iterate
> through the rows and output a new data.matrix in which row1 - rown will
> correspond to the vectors generated by replicating the values of row1 "row2
> - rown" independent times from the original data.matrix with the rep
> function shown above. So far I have been unable to get the for loop right.
>
> Any help will be most appreciated! Thanks beforehand for your help.

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list