s-news
[Top] [All Lists]

Replacing Values with average if possible

To: "'S-News'" <s-news@lists.biostat.wustl.edu>
Subject: Replacing Values with average if possible
From: "Bert Jacobs" <b.jacobs@pandora.be>
Date: Thu, 16 Mar 2006 18:33:40 +0100
In-reply-to: AAAAAOXvfE/tUWVMujI1J0cWacuEeCIA
Thread-index: AcZJHCepwR/LfQrWTGuwaK08p4N/OwAAqwUg
Hi,

I have a dataframe that looks like this

Col A   Col B           Col C
1               200             F
2               300             T       
3               250             F
4               600             T
5               300             F       
6               500             T

Now I would like to have the following result
Col A   Col B           Col C           Col D
1               200             F               200
2               300             T               225 (average of 200 and 250)
3               250             F               250
4               600             T               275 (average of 250 and 300)

5               300             F               300
6               500             T               300 (last value with F)

OR

Col A   Col B           Col C
1               200             T
2               300             F       
3               250             F
4               600             T
5               300             T       
6               500             F

Now I would like to have the following result
Col A   Col B           Col C           Col D
1               200             T               300 (first value with F in
Col C)
2               300             F               225 
3               250             F               250
4               600             T               375 (average of 250 and 500)

5               300             T               375 (average of 250 and 500)
6               500             F               500 

Is this possible with an easy command?

Thx for your suggestions,
Bert


<Prev in Thread] Current Thread [Next in Thread>
  • Replacing Values with average if possible, Bert Jacobs <=