I have a dataframe such like the following:

ID      TIME    DV
1       0       0.880146038
1       1       0.88669051
1       3       0.610784702
1       5       0.756046666
2       0       0.456263368
2       1       0.369991537
2       3       0.508798346
2       5       0.441037014
3       0       0.854905349
3       1       0.960457553
3       3       0.609434409
3       5       0.655006334
.       .       .
.       .       .


I would like to generate another column with the normalized values of DV.
for each ID, normalize to the value at TIME 0.  
I was able to use 2 loops to do the normalization, however, as 2 loops took
a long time for the calculation, I don't know whether there's a better way
to do it. 
I have the following code with only 1 loop, but it did not work.  Can anyone
help with this? Thanks,

IDS <- unique(data.frame$ID)
for(WhichID in IDS) 
{
subset <- data.frame[,"ID"] == WhichID
DVREAL <- data.frame[subset,"DV"]
DVNORM[WhichID] <- DVREAL/DVREAL[1]
}







--
View this message in context: 
http://r.789695.n4.nabble.com/data-normalization-tp4633911.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to