[R] remove loop which compares row i to row i-1

jcrosbie james at crosb.ie
Thu Jul 12 19:55:21 CEST 2012


Thank you, 

I am sorry but I am still trying to figure out how to make the function
work. 

I have a column called tUnitsort$BlockNumber which can range from 0 to 6. 
I have another two columns with the date and the hour ending for the given
day. 
Example

Date        Hour   BlockNumber  MyTo  NewColumn
2011-01   1          2                            140     140
2011-01   1          1                           70        140      
2011-01   1          0                           0           140   
2011-02   1          2                           160     160
2011-02   1          1                           70        160
2011-02   1          0                           0          160
2011-03   1          2                           150     150

I want to create a NewColumn which will place the MyTo number for the
highest block number for the rest blocks in a given hour ending within a
day. 


ifelse(tUnitsort[,4]>=tUnitsort[-1,4],tUnitsort[,7],tUnitsort[-1,7]) 

I am unsure how to refference the element before in this case.  I thought
the -1 was doing this but I believe I'm wrong now. 

http://r.789695.n4.nabble.com/file/n4636337/BR3_2011_New.csv
BR3_2011_New.csv 

--
View this message in context: http://r.789695.n4.nabble.com/remove-loop-which-compares-row-i-to-row-i-1-tp4635327p4636337.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list