Skip to content

help with vector operation

2 messages · eesteves@ualg.pt, Uwe Ligges

#
Dear All,

I'm trying to calculate the following:

g.rate<-(SL-int)/NO

where SL and NO are individual length and counts for the same subject, and the
int value is a day-specific value i.e. for each DAY=88, 101..., 172 I'd like to
use a different values of int=9.32, 8.43, ..., 9.81. All variables are compiled
in a larger data.frame of the form:

CODE  SL    NO  DAY (...)
123   12.5  14  88
124   11.4  13  88
125   10.8  11  101
(...)
234   16.9  19  172 (...)

I've been trying apply() but with little (NONE) success!
Thanks, Eduardo Esteves
#
eesteves at ualg.pt wrote:

            
Select the rows of the data.frame and just calculate what you already 
have written:
For the lines you cited this means, e.g.:

   X <- data.frame(CODE = c(123:125, 234),
                   SL = c(12.5, 11.4, 10.8, 16.9),
                   NO = c(14, 13, 11, 19),
                   DAY = c(88, 88, 101, 172))
   int <- c(9.32, 8.43, NA, 9.81)
   g.rate <- with(X, (SL - int) / NO)


That's it!

Uwe Ligges