[R] Max value of each 2 rows in dataframe

Rui Barradas ruipbarradas at sapo.pt
Tue Feb 12 19:05:36 CET 2013


Hello,

Your data example is a mess. Can't you please use ?dput to post it?
Supposing your data is named 'dat', use


dput(head(dat, 20))   # Paste the output of this in a post


Hope this helps,

Rui Barradas

Em 12-02-2013 15:30, zuzana zajkova escreveu:
> Hello,
>
> I would like to ask you for help. I have quite a big dataframe (119 313
> rows), this is a part of it:
>
> "jul" "ind" "time" "secs" "geo" "act" "lig" "date.x" "clock" "h" "m" "s"
> "d" "mo" "y" "dtime" "land" "date.y" "sriseIC" "ssetIC" "dssetIC" "dsriseIC"
> "1207" 14628 5500519 2010-01-19 15:14:59 40197.635414 17016001 0 64
> "19/01/10" "15:14:59" 15 14 59 19 1 10 15.2497222222222 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1208" 14628 5500519 2010-01-19 15:19:59 40197.638886 17016001 NA 64
> "19/01/10" "15:19:59" 15 19 59 19 1 10 15.3330555555556 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1209" 14628 5500519 2010-01-19 15:24:59 40197.642359 17016001 0 64
> "19/01/10" "15:24:59" 15 24 59 19 1 10 15.4163888888889 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1210" 14628 5500519 2010-01-19 15:29:59 40197.645831 17016001 NA 64
> "19/01/10" "15:29:59" 15 29 59 19 1 10 15.4997222222222 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1211" 14628 5500519 2010-01-19 15:34:59 40197.649303 17016001 0 64
> "19/01/10" "15:34:59" 15 34 59 19 1 10 15.5830555555556 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1212" 14628 5500519 2010-01-19 15:39:59 40197.652775 17016001 NA 64
> "19/01/10" "15:39:59" 15 39 59 19 1 10 15.6663888888889 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1213" 14628 5500519 2010-01-19 15:44:59 40197.656248 17016001 0 64
> "19/01/10" "15:44:59" 15 44 59 19 1 10 15.7497222222222 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1214" 14628 5500519 2010-01-19 15:49:59 40197.65972 17016001 NA 64
> "19/01/10" "15:49:59" 15 49 59 19 1 10 15.8330555555556 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1215" 14628 5500519 2010-01-19 15:54:59 40197.663192 17016001 0 64
> "19/01/10" "15:54:59" 15 54 59 19 1 10 15.9163888888889 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1216" 14628 5500519 2010-01-19 15:59:59 40197.666664 17016001 NA 64
> "19/01/10" "15:59:59" 15 59 59 19 1 10 15.9997222222222 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1217" 14628 5500519 2010-01-19 16:04:59 40197.670136 17016001 0 64
> "19/01/10" "16:04:59" 16 4 59 19 1 10 16.0830555555556 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1218" 14628 5500519 2010-01-19 16:09:59 40197.673609 17016001 NA 64
> "19/01/10" "16:09:59" 16 9 59 19 1 10 16.1663888888889 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1219" 14628 5500519 2010-01-19 16:14:59 40197.677081 17016001 0 64
> "19/01/10" "16:14:59" 16 14 59 19 1 10 16.2497222222222 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1220" 14628 5500519 2010-01-19 16:19:59 40197.680553 17016001 NA 64
> "19/01/10" "16:19:59" 16 19 59 19 1 10 16.3330555555556 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1221" 14628 5500519 2010-01-19 16:24:59 40197.684025 17016001 0 64
> "19/01/10" "16:24:59" 16 24 59 19 1 10 16.4163888888889 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1222" 14628 5500519 2010-01-19 16:29:59 40197.687498 17016001 NA 64
> "19/01/10" "16:29:59" 16 29 59 19 1 10 16.4997222222222 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1223" 14628 5500519 2010-01-19 16:34:59 40197.69097 17016001 0 64
> "19/01/10" "16:34:59" 16 34 59 19 1 10 16.5830555555556 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1224" 14628 5500519 2010-01-19 16:39:59 40197.694442 17016001 NA 64
> "19/01/10" "16:39:59" 16 39 59 19 1 10 16.6663888888889 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1225" 14628 5500519 2010-01-19 16:44:59 40197.697914 17016001 0 64
> "19/01/10" "16:44:59" 16 44 59 19 1 10 16.7497222222222 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1226" 14628 5500519 2010-01-19 16:49:59 40197.701386 17016001 NA 64
> "19/01/10" "16:49:59" 16 49 59 19 1 10 16.8330555555556 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1227" 14628 5500519 2010-01-19 16:54:59 40197.704859 17016001 0 64
> "19/01/10" "16:54:59" 16 54 59 19 1 10 16.9163888888889 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1228" 14628 5500519 2010-01-19 16:59:59 40197.708331 17016001 NA 64
> "19/01/10" "16:59:59" 16 59 59 19 1 10 16.9997222222222 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1229" 14628 5500519 2010-01-19 17:04:59 40197.711803 17016001 0 40
> "19/01/10" "17:04:59" 17 4 59 19 1 10 17.0830555555556 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1230" 14628 5500519 2010-01-19 17:09:59 40197.715275 17016001 NA 17
> "19/01/10" "17:09:59" 17 9 59 19 1 10 17.1663888888889 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1231" 14628 5500519 2010-01-19 17:14:59 40197.718747 17016001 0 6
> "19/01/10" "17:14:59" 17 14 59 19 1 10 17.2497222222222 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1232" 14628 5500519 2010-01-19 17:19:59 40197.72222 17016001 NA 0
> "19/01/10" "17:19:59" 17 19 59 19 1 10 17.3330555555556 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1233" 14628 5500519 2010-01-19 17:24:59 40197.725692 17016001 0 0
> "19/01/10" "17:24:59" 17 24 59 19 1 10 17.4163888888889 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1234" 14628 5500519 2010-01-19 17:29:59 40197.729164 17016001 NA 0
> "19/01/10" "17:29:59" 17 29 59 19 1 10 17.4997222222222 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1235" 14628 5500519 2010-01-19 17:34:59 40197.732636 17016001 0 0
> "19/01/10" "17:34:59" 17 34 59 19 1 10 17.5830555555556 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1236" 14628 5500519 2010-01-19 17:39:59 40197.736109 17016001 NA 0
> "19/01/10" "17:39:59" 17 39 59 19 1 10 17.6663888888889 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1237" 14628 5500519 2010-01-19 17:44:59 40197.739581 17016001 0 0
> "19/01/10" "17:44:59" 17 44 59 19 1 10 17.7497222222222 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1238" 14628 5500519 2010-01-19 17:49:59 40197.743053 17016001 NA 0
> "19/01/10" "17:49:59" 17 49 59 19 1 10 17.8330555555556 NA "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
> "1239" 14628 5500519 2010-01-19 17:54:59 40197.746525 17016001 0 0
> "19/01/10" "17:54:59" 17 54 59 19 1 10 17.9163888888889 0 "19/01/2010"
> "8:09" "19:29" 19.4833333333333 8.15
>
> There are data for "act" each 10 minutes, for "lig" each 5 minutes.
> What I wold like to get are just the rows with information for each 10
> minutes (the "act" time), but I don't want just to erase the rows with NA
> values. Before that, my aim is this:
> - if "act" value (6th column) is not NA, into the "lig" column (in the same
> row) I need to get the maximum value for "lig" of the same row and  one row
> before.
> for example: in the line 1231: act==0, lig==6, lig in the line 1230 is 17.
> I would like it to became in line 1231: act==0, lig==17.
>
> I would be thankful for your advice.
>
> Zuzana
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list