[R] CORRECTION - Storing results in a loop

Benilton Carvalho beniltoncarvalho at gmail.com
Mon Feb 15 13:29:05 CET 2010


sorry, meant to type:

B = ONS^2

cheers,
benilton

On Mon, Feb 15, 2010 at 12:28 PM, Benilton Carvalho
<beniltoncarvalho at gmail.com> wrote:
> maybe you just want
>
> Y = ONS^2
>
> ?
>
> b
>
> On Mon, Feb 15, 2010 at 12:22 PM, Madhavi Bhave <madhavi_bhave at yahoo.com> wrote:
>> Dear R Helpers
>>
>> (There is a small correction in my earlier mail. In the 'instrument.csv' file, I had mentioned only three columns. Actually there are 7 columns. I regret the error. Rest contents remains the same. Thanks)
>>
>> I have an 'instrument.csv' file with 7 instrument names and 5 rates each i.e. it has 7 columns and 6 rows (including row names).
>>
>> 'instrument.csv'
>>
>> instrument1      instrument2   ........     instrument7
>> 12                         5                              14
>> 11                         7                                7
>> 14                       11                                3
>>   8                       21                              10
>> 11                         3                                5
>>
>>
>> Following is my R code.
>>
>> ONS = read.csv('Instrument.csv')
>> n = length(ONS)
>>
>> Y = NULL
>> B = NULL
>>
>> for (i in 1 : n)
>>
>>  {
>>
>>  Y[i] = ONS[i]
>>
>>   for (j in 1 : length(Y[[i]]))
>>    {
>>    B[j] = (Y[[i]][j])^2
>>    }
>>
>>  }
>>
>> Problem is when I type B, I get the processed result only for the last column i.e. Y[7]. It doesn't store results for Y[1] to Y[7].
>>
>> I need B[1], B[2].......upto B[7].
>>
>> Please guide me how do I store individual column processed results?
>>
>> Thanking you all in advance
>>
>> Regards
>>
>> Madhavi
>>
>>
>>
>>
>>      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
>>        [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>> R-help at 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.
>>
>>
>



More information about the R-help mailing list