[R] R newbie - loop questions
Karl Schelhammer
karl.schelhammer at gmail.com
Thu Nov 7 20:20:21 CET 2013
Yep, that solves the problem and is much cleaner than what I was trying to do.
KWS
On Nov 7, 2013, at 10:01 AM, arun <smartpink111 at yahoo.com> wrote:
> Hi,
>
> May be this is what you wanted:
> mat1 <- matrix(1:4,2,2)
> results.norm <- mat1/rowSums(mat1)
>
> A.K.
>
>
>
>
> On Thursday, November 7, 2013 12:27 PM, Karl Schelhammer <karl.schelhammer at gmail.com> wrote:
> Sorry for the confusion. results is a 2 x 2 matrix containing real positive values. The goal is to divide each element of the matrix by the sum of the elements in a row and store the result in results.norm. However, the loop returns an error that I don't understand. Any thoughts?
>
> KWS
>
> On Nov 7, 2013, at 8:42 AM, smartpink111 at yahoo.com wrote:
>
>>
>> This is not clear.
>> For example,
>> v1 <- 24 #value
>> r1 <- c(2,3) # vector with 2 elements
>> my.function(v1,r1)
>> #[1] 4.8
>>
>> There is no reference to "results". If it is the output of my.function(), then there is only one element. Anyway, please show a reproducible example.
>>
>>
>>
>> <quote author='Sledge'>
>> Greetings all, I am attempting to run the following code:
>>
>>
>> I recieve the following error:
>>
>> The function runs fine when I explicitly enter the subscripts in results and
>> pass to my.function. Can someone else see what is wrong with this approach?
>> </quote>
>> Quoted from:
>> http://r.789695.n4.nabble.com/R-newbie-loop-questions-tp4679975.html
>>
>>
>> _____________________________________
>> Sent from http://r.789695.n4.nabble.com
>>
More information about the R-help
mailing list