[From nobody Thu Oct 23 22:45:16 2008
Received: from mail191.messagelabs.com (216.82.245.131) by
	155M-CAHT.goldbox.com (192.168.89.65) with Microsoft SMTP Server id
	8.1.291.1; Thu, 23 Oct 2008 14:24:20 -0400
X-VirusChecked: Checked
X-Env-Sender: r-help-bounces@r-project.org
X-Msg-Ref: server-5.tower-191.messagelabs.com!1224786254!12694179!1
X-StarScan-Version: 5.5.12.14.2; banners=-,-,-
X-Originating-IP: [129.132.145.15]
X-SpamReason: No, hits=0.0 required=7.0 tests=
Received: (qmail 4303 invoked from network); 23 Oct 2008 18:24:15 -0000
Received: from hypatia.math.ethz.ch (HELO hypatia.math.ethz.ch)
	(129.132.145.15) by server-5.tower-191.messagelabs.com with AES256-SHA
	encrypted SMTP; 23 Oct 2008 18:24:15 -0000
Received: from hypatia.math.ethz.ch (hypatia [129.132.145.15])	by
	hypatia.math.ethz.ch (8.14.1/8.14.1) with ESMTP id m9NINdnr030364;
	Thu, 23 Oct 2008 20:23:56 +0200
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hypatia.math.ethz.ch
X-Spam-Level: 
X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 
	WHOIS_MYPRIVREG autolearn=unavailable version=3.2.5
Received: from phil3.ethz.ch (phil3.ethz.ch [129.132.202.239])	by
	hypatia.math.ethz.ch (8.14.1/8.14.1) with ESMTP id m9NHqS4D007814	for
	&lt;r-help@r-project.org&gt;; Thu, 23 Oct 2008 19:52:28 +0200
Received: from kuber.nabble.com ([216.139.236.158])	by phil3.ethz.ch with
	esmtp (Exim 4.66)	(envelope-from &lt;bounces@nabble.com&gt;) id
	1Kt4ML-0003kF-Bc
	for r-help@r-project.org; Thu, 23 Oct 2008 19:52:35 +0200
Received: from isper.nabble.com ([192.168.236.156])	by kuber.nabble.com with
	esmtp (Exim 4.63)	(envelope-from &lt;bounces@nabble.com&gt;) id
	1Kt4MD-0003ZD-Cw
	for r-help@r-project.org; Thu, 23 Oct 2008 10:52:25 -0700
Message-ID: &lt;20136308.post@talk.nabble.com&gt;
Date: Thu, 23 Oct 2008 10:52:25 -0700
From: Chris82 &lt;rubenbauar@gmx.de&gt;
To: &lt;r-help@r-project.org&gt;
In-Reply-To: &lt;644e1f320810221857n221b0089w5d34a355504c308a@mail.gmail.com&gt;
MIME-Version: 1.0
X-Nabble-From: rubenbauar@gmx.de
References: &lt;20110333.post@talk.nabble.com&gt;
	&lt;644e1f320810221857n221b0089w5d34a355504c308a@mail.gmail.com&gt;
X-USF-Tag-Only: YES
X-USF-Filter-Node: phil3.ethz.ch
X-USF-Spam-Level: --
X-USF-Spam-Status: hits=-2.6 tests=BAYES_00
X-USF-Spam-Flag: NO
X-USF: 
X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch
Subject: Re: [R] Substitute problem
X-BeenThere: r-help@r-project.org
X-Mailman-Version: 2.1.11
Precedence: list
List-Id: &quot;Main R Mailing List: Primary help&quot; &lt;r-help.r-project.org&gt;
List-Unsubscribe: &lt;https://stat.ethz.ch/mailman/options/r-help&gt;,
	&lt;mailto:r-help-request@r-project.org?subject=unsubscribe&gt;
List-Archive: &lt;https://stat.ethz.ch/pipermail/r-help&gt;
List-Post: &lt;mailto:r-help@r-project.org&gt;
List-Help: &lt;mailto:r-help-request@r-project.org?subject=help&gt;
List-Subscribe: &lt;https://stat.ethz.ch/mailman/listinfo/r-help&gt;,
	&lt;mailto:r-help-request@r-project.org?subject=subscribe&gt;
Content-Type: text/plain; charset=&quot;us-ascii&quot;
Content-Transfer-Encoding: 7bit
Sender: &lt;r-help-bounces@r-project.org&gt;
Errors-To: r-help-bounces@r-project.org
Return-Path: r-help-bounces@r-project.org
X-MS-Exchange-Organization-OriginalArrivalTime: 23 Oct 2008 18:24:20.0791 (UTC)
X-MS-Exchange-Organization-AuthSource: 155M-CAHT.goldbox.com
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-OriginalSize: 8453
X-MS-Exchange-Organization-Recipient-Limit-Verified: True


Thanks! Works fine!



jholtman wrote:
&gt; 
&gt; Had the test wrong in the last one'  try this:
&gt; 
&gt;&gt; x
&gt;   X     value     row     col ID         n
&gt; 1 1 11.105009 5511625 3463000  1 -619.1125
&gt; 2 2 10.324148 5499625 3465000  0    1.0000
&gt; 3 3  8.744591 5503625 3475000  0    1.0000
&gt; 4 4  9.523473 5494625 3475000  3 -578.2354
&gt; 5 5  8.856097 5507625 3480000  4 -619.1125
&gt; 6 6  8.636881 5514625 3497000  5 -140.8012
&gt;&gt; id_max &lt;- 5
&gt;&gt; id_change &lt;- (x$ID == 0) &amp; (x$n &gt; 0)
&gt;&gt; x$ID[id_change] &lt;- cumsum(id_change)[id_change] + id_max
&gt;&gt; x
&gt;   X     value     row     col ID         n
&gt; 1 1 11.105009 5511625 3463000  1 -619.1125
&gt; 2 2 10.324148 5499625 3465000  6    1.0000
&gt; 3 3  8.744591 5503625 3475000  7    1.0000
&gt; 4 4  9.523473 5494625 3475000  3 -578.2354
&gt; 5 5  8.856097 5507625 3480000  4 -619.1125
&gt; 6 6  8.636881 5514625 3497000  5 -140.8012
&gt;&gt;
&gt; 
&gt; 
&gt; On Wed, Oct 22, 2008 at 9:06 AM, Chris82 &lt;rubenbauar@gmx.de&gt; wrote:
&gt;&gt;
&gt;&gt; hello R users,
&gt;&gt;
&gt;&gt; I didn't find a solution for a special problem.
&gt;&gt; I have two dataframes.
&gt;&gt;
&gt;&gt; dataframe1:
&gt;&gt;
&gt;&gt;  X        value         row             col                       ID
&gt;&gt;  1  8.973498062         5512625         3460000         1
&gt;&gt;  2 11.656658570         5501625         3464000         2
&gt;&gt;  3 11.121777570         5495625         3473000         3
&gt;&gt;  4  9.310465964         5508625         3477000         4
&gt;&gt;  5  8.883483845         5515625         3496000         5
&gt;&gt;
&gt;&gt;
&gt;&gt; dataframe2:
&gt;&gt;
&gt;&gt;  X        value         row             col               ID                  
&gt;&gt; n
&gt;&gt;  1 11.105009400         5511625 3463000                   1            
&gt;&gt; -619.112472616732
&gt;&gt;  2 10.324148150         5499625 3465000                     0          
&gt;&gt; 1.000000000000
&gt;&gt;  3  8.744590903         5503625 3475000                   0            
&gt;&gt; 1.000000000000
&gt;&gt;  4  9.523473123         5494625 3475000                   3         
&gt;&gt; -578.235381588725
&gt;&gt;  5  8.856097133         5507625 3480000                     4       
&gt;&gt; -619.112472616732
&gt;&gt;  6  8.636881453         5514625 3497000                   5         
&gt;&gt; -140.801233634174
&gt;&gt;
&gt;&gt; Now I want if column &quot;n&quot; in dataframe2 is greater than 0 column &quot;ID&quot;
&gt;&gt; which
&gt;&gt; is 0 is now maxium column &quot;ID&quot; in dataframe1 +1 and the for the second 0
&gt;&gt; maximum + 2
&gt;&gt;
&gt;&gt; the finished dataframe2 should look like this:
&gt;&gt;
&gt;&gt;  X        value         row             col                       ID          
&gt;&gt; n
&gt;&gt;  1 11.105009400         5511625 3463000                   1      
&gt;&gt; -619.112472616732
&gt;&gt;  2 10.324148150         5499625 3465000                     6    
&gt;&gt; 1.000000000000
&gt;&gt;  3  8.744590903         5503625 3475000                   7      
&gt;&gt; 1.000000000000
&gt;&gt;  4  9.523473123         5494625 3475000                   3    
&gt;&gt; -578.235381588725
&gt;&gt;  5  8.856097133         5507625 3480000                     4  
&gt;&gt; -619.112472616732
&gt;&gt;  6  8.636881453         5514625 3497000                   5    
&gt;&gt; -140.801233634174
&gt;&gt;
&gt;&gt; My idea was below:
&gt;&gt;
&gt;&gt; lastrow1 &lt;- length(dataframe2[,1])
&gt;&gt; lastrow2 &lt;- length(dataframe1[,1])
&gt;&gt; anz &lt;- sum(dataframe2[,6] &gt; 0)
&gt;&gt;
&gt;&gt;
&gt;&gt; for (k in 1:anz){
&gt;&gt; for (i in 1:lastrow1){
&gt;&gt; for (j in 1:lastrow2){
&gt;&gt; if (dataframe2[i,6] &gt; 0){
&gt;&gt; dataframe2[i,5] &lt;- max(dataframe1[j,5])+(k-k+1)
&gt;&gt; }
&gt;&gt; }
&gt;&gt; }
&gt;&gt; }
&gt;&gt;
&gt;&gt;
&gt;&gt; but the result is:
&gt;&gt;
&gt;&gt;  X        value         row             col                       ID                  
&gt;&gt; n
&gt;&gt;  1 11.105009400         5511625 3463000                   1      
&gt;&gt; -619.112472616732
&gt;&gt;  2 10.324148150         5499625 3465000                     6     
&gt;&gt; 1.000000000000
&gt;&gt;  3  8.744590903         5503625 3475000                   6       
&gt;&gt; 1.000000000000
&gt;&gt;  4  9.523473123         5494625 3475000                   3    
&gt;&gt; -578.235381588725
&gt;&gt;  5  8.856097133         5507625 3480000                     4  
&gt;&gt; -619.112472616732
&gt;&gt;  6  8.636881453         5514625 3497000                   5    
&gt;&gt; -140.801233634174
&gt;&gt;
&gt;&gt; R gives me the right value in the second row of &quot;ID&quot; with &quot;6&quot; but the
&gt;&gt; third
&gt;&gt; row of &quot;ID&quot; is also &quot;6&quot; but should be &quot;7&quot;
&gt;&gt;
&gt;&gt; any ideas?
&gt;&gt;
&gt;&gt; thanks!
&gt;&gt; --
&gt;&gt; View this message in context:
&gt;&gt; http://www.nabble.com/Substitute-problem-tp20110333p20110333.html
&gt;&gt; Sent from the R help mailing list archive at Nabble.com.
&gt;&gt;
&gt;&gt; ______________________________________________
&gt;&gt; R-help@r-project.org mailing list
&gt;&gt; https://stat.ethz.ch/mailman/listinfo/r-help
&gt;&gt; PLEASE do read the posting guide
&gt;&gt; http://www.R-project.org/posting-guide.html
&gt;&gt; and provide commented, minimal, self-contained, reproducible code.
&gt;&gt;
&gt; 
&gt; 
&gt; 
&gt; -- 
&gt; Jim Holtman
&gt; Cincinnati, OH
&gt; +1 513 646 9390
&gt; 
&gt; What is the problem that you are trying to solve?
&gt; 
&gt; ______________________________________________
&gt; R-help@r-project.org mailing list
&gt; https://stat.ethz.ch/mailman/listinfo/r-help
&gt; PLEASE do read the posting guide
&gt; http://www.R-project.org/posting-guide.html
&gt; and provide commented, minimal, self-contained, reproducible code.
&gt; 
&gt; 

-- 
View this message in context: http://www.nabble.com/Substitute-problem-tp20110333p20136308.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.
]