[R] Caculate first difference from a dataframe; write a simulation

David Winsemius dwinsemius at comcast.net
Wed Aug 5 15:06:16 CEST 2009


On Aug 4, 2009, at 2:12 PM, Meenu Sahi wrote:

> Dear R Users
>
> I'm writing my first simulation in R.
> I've put across my problems with a smaller example in the attachment  
> along
> with the questions.
>
> Please help.

See Simpson reply to Q1

##Question2: How can I easily identify which out of the 9 states does  
ad fall into with Level =5.04 and spread=0.25?
##OUTPUT
ad
          X6
Level  5.04
spread 0.25
state  state8

But spread for state7 was -0.34?????

Had it been 0.24, then this should work (some of the time.)
 > subset(mydat4, Level == 5.4 & spread==0.25)
[1] Level  spread change State
<0 rows> (or 0-length row.names)

Perhaps you meant to specify an "or" condition?

 > subset(mydat4, Level == 5.4 | spread==0.24)
    Level spread change  State
10  5.40  -0.34    BrF State7
11  4.89   0.24    BlF State8


>
> Best regards
> Meenu
> <Example.txt>______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list