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
help with vector operation
2 messages · eesteves@ualg.pt, Uwe Ligges
eesteves at ualg.pt wrote:
Dear All, I'm trying to calculate the following:
Select the rows of the data.frame and just calculate what you already have written:
g.rate<-(SL-int)/NO
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
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
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html