Re: [R] Assign value to a row in dataframe

2015-01-21 Thread zuzana zajkova
Hi Petr,

your solution works also perfectly, thanks a lot! Again, I have learned new
things :)

(Sorry for problems with the dput...)

Best wishes,

Zuzana




On 21 January 2015 at 11:57, PIKAL Petr  wrote:

> Hi
>
> I am not sure if I catch it correctly but from your example state has
> preference over state new except in the case where state is 0.
>
> I would change state_bef 0 to NA and use na.locf function from zoo package.
>
> test$state_bef[test$state_bef=="0"] <- NA
> test$state_bef <- na.locf(test$state_bef, na.rm=FALSE)
> test$state_new <- ifelse(test$state == "0", as.character(test$state_bef),
> as.character(test$state))
>
> library(zoo)
>
> # as you failed to use dput for data I need to do some transformation
> before I got appropriate object.
>
> temp<-read.delim("clipboard", header=F, sep=" ")
> temp<-t(temp)
> temp<-t(temp[complete.cases(temp),])
> temp<-data.frame(temp)
> names(temp)[4:6]<-c("state", "state_bef", "state_new")
>
>
> #  here is the code
> temp$state_bef[temp$state_bef=="0"] <- NA
> temp$state_bef <- na.locf(temp$state_bef, na.rm=FALSE)
> temp$state_new <-  ifelse(temp$state == "0", as.character(temp$state_bef),
> as.character(temp$state))
> temp
> V1 V2   V3 state state_bef state_new
> 1  279 2011-11-12 08:24:57 a   a
> 2  280 2011-11-12 08:31:42 b a b
> 3  281 2011-11-13 00:00:00 0 b b
> 4  282 2011-11-14 00:00:00 0 b b
> 5  283 2011-11-15 00:00:00 0 b b
> 6  284 2011-11-16 00:00:00 0 b b
> 7  285 2011-11-17 00:00:00 0 b b
> 8  286 2011-11-18 00:00:00 0 b b
> 9  287 2011-11-19 00:00:00 0 b b
> 10 288 2011-11-19 06:13:18 a b a
> 11 289 2011-11-19 06:40:06 b a b
> 12 290 2011-11-19 08:56:54 a     b a
> 13 291 2011-11-19 09:19:39 b a b
> >
>
> which results in desired solution.
>
> Cheers
> Petr
>
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of zuzana
> > zajkova
> > Sent: Tuesday, January 20, 2015 11:15 PM
> > To: r-help@r-project.org
> > Subject: [R] Assign value to a row in dataframe
> >
> > Hi,
> >
> > I have probably basic question, but I would be happy if somebody could
> > help
> > me with this:
> >
> > I have a dataframe where I want to assign a value to other column
> > copying
> > the value in previous row under some condition.
> >
> > Here is an example (dput on the end of message):
> >
> > > test[278:290,]
> >datetime state state_bef state_new
> > 279 2011-11-12 08:24:57 a 0 a
> > 280 2011-11-12 08:31:42 b a b
> > 281 2011-11-13 00:00:00 0 b b
> > 282 2011-11-14 00:00:00 0 0 b
> > 283 2011-11-15 00:00:00 0 0 0
> > 284 2011-11-16 00:00:00 0 0 0
> > 285 2011-11-17 00:00:00 0 0 0
> > 286 2011-11-18 00:00:00 0 0 0
> > 287 2011-11-19 00:00:00 0 0 0
> > 288 2011-11-19 06:13:18 a 0 a
> > 289 2011-11-19 06:40:06 b a b
> > 290 2011-11-19 08:56:54 a b a
> > 291 2011-11-19 09:19:39 b a b
> >
> >
> > What I need is:
> > if state != "0", the state_new==state
> > if state == "0" & state_bef!="0", the state_new==state_bef
> > if state == "0" & state_bef=="0", the state_new==state_bef of the
> > previous
> > row.
> > The idea is when there is "00:00:00" in datetime, I need to repeat the
> > last
> > "state" value in the "state_new"
> >
> > I have tried various ifelse conditions and loops, the last is this,
> > which
> > doesn't work for all rows:
> >
> > test$state_new[test$state!="0"] <- test$state[test$state!="0"]
> > test$state_new[test$state=="0" & test$state_bef!="0"] <-
> > test$state_bef[test$state=="0" & test$state_bef!="0"]
> > test$state_new[test$state=="0" & test$state_bef=="0"] <-
> > test$state_new[test$state=="0" & test$state_bef=="0"]  # doesn't work
> &g

Re: [R] Assign value to a row in dataframe

2015-01-21 Thread zuzana zajkova
Hi Jim,

your code works just perfectly, it is exactly what I was looking for, thank
you very much!!! I'm glad to learn something new, I haven't seen the use of
"drow in 1:(dim(all)[1])" before.

I made the code a bit shorter, excluding the use of "stat_bef" column,
which I created just for my intents with loops.

# simplified version without "state_bef"
for(drow in 1:(dim(test)[1])) {
  if(test$state[drow] != "0") test$state_new[drow]<-test$state[drow]
  else {
 test$state_new[drow]<-test$state_new[drow-1]
  }
}

Best wishes,

Zuzana


On 21 January 2015 at 00:20, Jim Lemon  wrote:

> Hi Zuzana,
> From your description it seems that you want to repeat the last
> "state_new" value when there are repeated zeros in both "state" and
> "state_bef". If that is the case, you may need to step through the
> data frame like this:
>
> for(drow in 1:(dim(test)[1])) {
>  if(test$state[drow] != 0) test$state_new[drow]<-test$state[drow]
>  else {
>   if(test$state_bef[drow] != 0) test$state_new[drow]<-test$state_bef[drow]
>   else test$state_new[drow]<-test$state_new[drow-1]
>  }
> }
>
> This assumes that "state" and "state_bef" will never both be zero in
> the first row. If this might happen, you will have to add a "memory"
> variable (e.g. "state_last"), initialize it to whatever value you want
> and then set it equal to "state_new" at the end of each step.
>
> It may be possible to do this as you were attempting above using
> something like "rle", but I think it will be difficult.
>
> Jim
>
>
> On Wed, Jan 21, 2015 at 9:14 AM, zuzana zajkova  wrote:
> > Hi,
> >
> > I have probably basic question, but I would be happy if somebody could
> help
> > me with this:
> >
> > I have a dataframe where I want to assign a value to other column copying
> > the value in previous row under some condition.
> >
> > Here is an example (dput on the end of message):
> >
> >> test[278:290,]
> >datetime state state_bef state_new
> > 279 2011-11-12 08:24:57 a 0 a
> > 280 2011-11-12 08:31:42 b a b
> > 281 2011-11-13 00:00:00 0 b b
> > 282 2011-11-14 00:00:00 0 0 b
> > 283 2011-11-15 00:00:00 0 0 0
> > 284 2011-11-16 00:00:00 0 0 0
> > 285 2011-11-17 00:00:00 0 0 0
> > 286 2011-11-18 00:00:00 0 0 0
> > 287 2011-11-19 00:00:00 0 0 0
> > 288 2011-11-19 06:13:18 a 0 a
> > 289 2011-11-19 06:40:06 b a b
> > 290 2011-11-19 08:56:54 a b a
> > 291 2011-11-19 09:19:39 b a b
> >
> >
> > What I need is:
> > if state != "0", the state_new==state
> > if state == "0" & state_bef!="0", the state_new==state_bef
> > if state == "0" & state_bef=="0", the state_new==state_bef of the
> previous
> > row.
> > The idea is when there is "00:00:00" in datetime, I need to repeat the
> last
> > "state" value in the "state_new"
> >
> > I have tried various ifelse conditions and loops, the last is this, which
> > doesn't work for all rows:
> >
> > test$state_new[test$state!="0"] <- test$state[test$state!="0"]
> > test$state_new[test$state=="0" & test$state_bef!="0"] <-
> > test$state_bef[test$state=="0" & test$state_bef!="0"]
> > test$state_new[test$state=="0" & test$state_bef=="0"] <-
> > test$state_new[test$state=="0" & test$state_bef=="0"]  # doesn't work for
> > all rows...
> >
> > This should be the result
> >
> >  datetime state state_bef state_new
> > 279 2011-11-12 08:24:57 a 0 a
> > 280 2011-11-12 08:31:42 b a b
> > 281 2011-11-13 00:00:00 0 b b
> > 282 2011-11-14 00:00:00 0 0 b
> > 283 2011-11-15 00:00:00 0 0 b
> > 284 2011-11-16 00:00:00 0 0 b
> > 285 2011-11-17 00:00:00 0 0 b
> > 286 2011-11-18 00:00:00 0 0 b
> > 287 2011-11-19 00:00:00 0 0 b
> > 288 2011-11-19 06:13:18 a 0 a
> > 289 2011-11-19 06:40:06 b a b
> > 290 2011-11-19 08:56:54 a

[R] Assign value to a row in dataframe

2015-01-20 Thread zuzana zajkova
Hi,

I have probably basic question, but I would be happy if somebody could help
me with this:

I have a dataframe where I want to assign a value to other column copying
the value in previous row under some condition.

Here is an example (dput on the end of message):

> test[278:290,]
   datetime state state_bef state_new
279 2011-11-12 08:24:57 a 0 a
280 2011-11-12 08:31:42 b a b
281 2011-11-13 00:00:00 0 b b
282 2011-11-14 00:00:00 0 0 b
283 2011-11-15 00:00:00 0 0 0
284 2011-11-16 00:00:00 0 0 0
285 2011-11-17 00:00:00 0 0 0
286 2011-11-18 00:00:00 0 0 0
287 2011-11-19 00:00:00 0 0 0
288 2011-11-19 06:13:18 a 0 a
289 2011-11-19 06:40:06 b a b
290 2011-11-19 08:56:54 a b a
291 2011-11-19 09:19:39 b a b


What I need is:
if state != "0", the state_new==state
if state == "0" & state_bef!="0", the state_new==state_bef
if state == "0" & state_bef=="0", the state_new==state_bef of the previous
row.
The idea is when there is "00:00:00" in datetime, I need to repeat the last
"state" value in the "state_new"

I have tried various ifelse conditions and loops, the last is this, which
doesn't work for all rows:

test$state_new[test$state!="0"] <- test$state[test$state!="0"]
test$state_new[test$state=="0" & test$state_bef!="0"] <-
test$state_bef[test$state=="0" & test$state_bef!="0"]
test$state_new[test$state=="0" & test$state_bef=="0"] <-
test$state_new[test$state=="0" & test$state_bef=="0"]  # doesn't work for
all rows...

This should be the result

 datetime state state_bef state_new
279 2011-11-12 08:24:57 a 0 a
280 2011-11-12 08:31:42 b a b
281 2011-11-13 00:00:00 0 b b
282 2011-11-14 00:00:00 0 0 b
283 2011-11-15 00:00:00 0 0 b
284 2011-11-16 00:00:00 0 0 b
285 2011-11-17 00:00:00 0 0 b
286 2011-11-18 00:00:00 0 0 b
287 2011-11-19 00:00:00 0 0 b
288 2011-11-19 06:13:18 a 0 a
289 2011-11-19 06:40:06 b a b
290 2011-11-19 08:56:54 a b a
291 2011-11-19 09:19:39 b a b


In the dataframe I send as an example there is just one block of this
repeated "0" values, but within real dataframe there are more blocks like
that.

Thanks for any ideas!

Best regards,

Zuzana






> dput(test)
structure(list(datetime = structure(c(1320264600, 1320265473,
1320266409, 1320266418, 1320266460, 1320267591, 1320268350, 1320268371,
1320276948, 1320277332, 1320278400, 1320280380, 1320283950, 1320283977,
1320286293, 1320287010, 1320287022, 1320287055, 1320287604, 1320288678,
1320295476, 1320296490, 1320296766, 1320300015, 1320319140, 1320320367,
1320331629, 1320333789, 1320354315, 1320355689, 132036, 1320364800,
1320366489, 1320378507, 1320378702, 1320393177, 1320394809, 1320412825,
1320413140, 1320417361, 1320418849, 1320418855, 1320419854, 1320419860,
1320420244, 1320420268, 1320420277, 1320451200, 1320452443, 1320455566,
1320455716, 1320455839, 1320455845, 1320455851, 1320455896, 1320456094,
1320456109, 1320457492, 1320458053, 1320460879, 1320465739, 1320465748,
1320466018, 1320469426, 1320469468, 1320475630, 1320476410, 1320482851,
1320489187, 1320490969, 1320495052, 1320495061, 1320519571, 1320519580,
1320519610, 1320520594, 1320520600, 1320520618, 1320520624, 1320520636,
1320526588, 1320527017, 1320537600, 1320554581, 1320554911, 1320554926,
1320554941, 1320571210, 1320573523, 1320608509, 1320609532, 1320611587,
1320616504, 1320616513, 1320616768, 1320618364, 1320620602, 1320620833,
1320622147, 1320623194, 1320624000, 1320632149, 1320632164, 1320632446,
1320646327, 1320646810, 1320663212, 1320663716, 1320665483, 1320665870,
1320666332, 132065, 132080, 132089, 1320666899, 1320666968,
1320668141, 1320668147, 1320669017, 1320669545, 1320670070, 1320670076,
1320670118, 1320670130, 1320670154, 1320670166, 1320670175, 1320670181,
1320670232, 1320670244, 1320670262, 1320670700, 1320671432, 1320671891,
1320672518, 1320673208, 1320673478, 1320673484, 1320673556, 1320673628,
1320673706, 1320673739, 1320673751, 1320673769, 1320673775, 1320673799,
1320673817, 1320673835, 1320673853, 1320674531, 1320675434, 1320675968,
1320676139, 1320676154, 1320676592, 1320677327, 1320677822, 1320678038,
1320678047, 1320678179, 1320678185, 1320678533, 1320679199, 1320679535,
1320679718, 1320682901, 132068, 1320684239, 1320684248, 1320684362,
1320685019, 1320685346, 1320685718, 1320686645, 1320710400, 1320711704,
1320712352, 1320721790, 1320722021, 1320722066, 1320722237, 1320730745,
1320730766, 1320730784, 1320730886, 1320730892, 1320730904, 1320730955,
1320731075, 1320731120, 1320731126, 1320731132, 1320731165, 1320

[R] Heatmap - strange horizontal lines

2014-10-23 Thread zuzana zajkova
Dear list,

I would like to make heatmaps from my data. Acctualy, I have already done
it, but the issue it that is doesn't work well for all files.

All files have the same structure, after importing them I do few
calculations using the same script, to obtain variables for plotting.

You can find the files here, the pb2166 is the one which works fine and I
get normal (expected) heatmap plot, the pb2214 it the other type, for which
I obtain strange horizontal lines...

https://www.dropbox.com/s/rz2ywnloepvr3d8/pb2166.csv?dl=0
https://www.dropbox.com/s/42taaybtbortv0p/pb2214.csv?dl=0

The structure of data is this (the same, from my point of view...):

str(pb2166)
'data.frame':  55119 obs. of  3 variables:
 $ dtime: num  17.9 18.1 18.3 18.4 18.6 ...
 $ act  : int  9 1 0 0 0 0 0 0 0 0 ...
 $ jul  : num  13573 13573 13573 13573 13573 ...

str(pb2214)
'data.frame':  44707 obs. of  3 variables:
 $ dtime: num  17.9 18.1 18.2 18.4 18.6 ...
 $ act  : int  9 1 0 0 0 0 0 0 0 0 ...
 $ jul  : num  13573 13573 13573 13573 13573 ...


To  create a heatmap I tried ggplot/qlot and levelplot aswell, the results
are the same... for pb2166 works ok, for pb2214 doesn't...

qplot(jul, dtime, data=pb2166, geom="tile", fill=act) +
scale_fill_gradient(low="gold", high="green4")
levelplot(act ~ jul * dtime, pb2166 )

qplot(jul, dtime, data=pb2214, geom="tile", fill=act) +
scale_fill_gradient(low="gold", high="green4")
levelplot(act ~ jul * dtime, pb2214 )

I would be very thankful if somebody could take a look on the data and find
something what I am missing.

Kind regards,

Zuzana

[[alternative HTML version deleted]]

__
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.


Re: [R] Fwd: problem importing apparently common txt files

2014-05-22 Thread zuzana zajkova
Thank you! It seems to work.

Zuzana

On 22 May 2014 15:47, arun  wrote:

> Hi,
>
> Check if this works:
>  dat1 <- read.table("folder2.txt",
> header=TRUE,stringsAsFactors=FALSE,sep="\t",fileEncoding="UTF-16")
>
>
> 'data.frame':79 obs. of  6 variables:
>  $ Documento: chr  "6143066.17.4.12.DSC_0001.png"
> "6143066.17.4.12.DSC_0001.png" "6143066.17.4.12.DSC_0001.png"
> "6143066.17.4.12.DSC_0002.png" ...
>  $ Longitud : num  8.83 8.94 NA 8.94 8.99 ...
>  $ Ángulo   : num  -90 90.3 NA -89.7 -90 ...
>  $ Área : num  NA NA 551 NA NA ...
>  $ Altura   : num  NA NA 16.7 NA NA ...
>  $ Anchura  : num  NA NA 52.5 NA NA ...
>
>
>
> A.K.
>
>
> On Thursday, May 22, 2014 9:11 AM, zuzana zajkova 
> wrote:
> Dear list,
>
> I would like to import into R studio txt files coming from Adobe photoshop.
> These files contain different measures. The files are apparently common txt
> files with columns separate by tab.  However with common function
> read.table the import process doesn't work and weird symbols appear once
> imported.  An example file is attached.
>
> Do you have any idea what it is happening?
>
> Thank you in advance
>
> Zuzana
>
>
>
> Here just a view of a file.
> "Documento""Longitud""Ángulo""Área""Altura""Anchura"
> "6143066.17.4.12.DSC_0001.png""8.832613""-90.00"
> "6143066.17.4.12.DSC_0001.png""8.937918""90.337288"
> "6143066.17.4.12.DSC_0001.png""551.103109""16.736842"
> "52.543860"
> "6143066.17.4.12.DSC_0002.png""8.942544""-89.662891"
> "6143066.17.4.12.DSC_0002.png""8.994992""-90.00"
> "6143066.17.4.12.DSC_0002.png""550.146507""16.736842"
> "52.491228"
> "6106937.17.4.12.DSC_0004.png""12.159715""-89.008611"
> __
> 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.
>
>

[[alternative HTML version deleted]]

__
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.


[R] Fwd: problem importing apparently common txt files

2014-05-22 Thread zuzana zajkova
Dear list,

I would like to import into R studio txt files coming from Adobe photoshop.
These files contain different measures. The files are apparently common txt
files with columns separate by tab.  However with common function
read.table the import process doesn't work and weird symbols appear once
imported.  An example file is attached.

Do you have any idea what it is happening?

Thank you in advance

Zuzana



Here just a view of a file.
"Documento""Longitud""Ángulo""Área""Altura""Anchura"
"6143066.17.4.12.DSC_0001.png""8.832613""-90.00"
"6143066.17.4.12.DSC_0001.png""8.937918""90.337288"
"6143066.17.4.12.DSC_0001.png""551.103109""16.736842"
"52.543860"
"6143066.17.4.12.DSC_0002.png""8.942544""-89.662891"
"6143066.17.4.12.DSC_0002.png""8.994992""-90.00"
"6143066.17.4.12.DSC_0002.png""550.146507""16.736842"
"52.491228"
"6106937.17.4.12.DSC_0004.png""12.159715""-89.008611"
"Documento""Longitud"  "Ángulo""Área"  "Altura"
"Anchura"
"6143066.17.4.12.DSC_0001.png"  "8.832613"  "-90.00"
"6143066.17.4.12.DSC_0001.png"  "8.937918"  "90.337288" 
"6143066.17.4.12.DSC_0001.png"  "551.103109""16.736842" 
"52.543860"
"6143066.17.4.12.DSC_0002.png"  "8.942544"  "-89.662891"
"6143066.17.4.12.DSC_0002.png"  "8.994992"  "-90.00"
"6143066.17.4.12.DSC_0002.png"  "550.146507""16.736842" 
"52.491228"
"6106937.17.4.12.DSC_0004.png"  "12.159715" "-89.008611"
"6106937.17.4.12.DSC_0004.png"  "12.054468" "-88.54"
"6106937.17.4.12.DSC_0004.png"  "574.210834""17.526316" 
"52.192982"
"6106937.17.4.12.DSC_0005.png"  "12.210640" "-89.753112"
"6106937.17.4.12.DSC_0005.png"  "12.316239" "-89.510454"
"6106937.17.4.12.DSC_0005.png"  "573.669129""17.561404" 
"52.122807"
"6188609.17.4.12.DSC_0009.png"  "13.268267" "-91.590146"
"6188609.17.4.12.DSC_0009.png"  "13.319529" "-91.357689"
"6188609.17.4.12.DSC_0009.png"  "526.275162""15.491228" 
"52.438596"
"6188609.17.4.12.DSC_0010.png"  "13.196761" "-91.371180"
"6188609.17.4.12.DSC_0010.png"  "13.231048" "-91.215643"
"6188609.17.4.12.DSC_0010.png"  "526.780856""15.491228" 
"52.385965"
"6143090.15.4.12.DSC_0013.png"  "12.140351" "-90.00"
"6143090.15.4.12.DSC_0013.png"  "12.00" "-90.00"
"6143090.15.4.12.DSC_0013.png"  "610.210834""18.421053" 
"52.596491"
"6143090.15.4.12.DSC_0014.png"  "12.090731" "-89.750728"
"6143090.15.4.12.DSC_0014.png"  "11.992736" "-90.00"
"6143090.15.4.12.DSC_0014.png"  "610.641120""18.245614" 
"52.649123"
"6195159.14.5.12.DSC_0017.png"  "16.742131" "-88.559723"
"6195159.14.5.12.DSC_0017.png"  "16.847362" "-88.568721"
"6195159.14.5.12.DSC_0017.png"  "630.465066""20.473684" 
"55.684211"
"6195159.14.5.12.DSC_0018.png"  "16.797712" "-88.205510"
"6195159.14.5.12.DSC_0018.png"  "16.846130" "-88.747572"
"6195159.14.5.12.DSC_0018.png"  "630.216990""20.491228" 
"55.684211"
"6175701.15.4.12.DSC_0021.png"  "14.732429" "-101.116408"   
"6175701.15.4.12.DSC_0021.png"  "14.629281" "-101.195797"   
"6175701.15.4.12.DSC_0021.png"  "518.332718""18.298246" 
"53.614035"
"6175701.15.4.12.DSC_0022.png"  "14.780985" "-101.703689"   
"6175701.15.4.12.DSC_0022.png"  "14.801433" "-101.064184"   
"6175701.15.4.12.DSC_0022.png"  "517.615882""18.245614" 
"53.508772"
"6134530.15.4.12.DSC_0025.png"  "10.868923" "-94.025757"
"6134530.15.4.12.DSC_0025.png"  "10.865356" "-93.748940"
"6134530.15.4.12.DSC_0025.png"  "569.846414""18.649123" 
"54.526316"
"6134530.15.4.12.DSC_0026.png"  "10.902122" "-93.875406"
"6134530.15.4.12.DSC_0026.png"  "10.899807" "-93.691386"
"6134530.15.4.12.DSC_0026.png"  "570.213296""18.67" 
"54.456140"
"6140703.DSC_0029.png"  "13.057253" "-94.469557"
"6140703.DSC_0029.png"  "13.019577" "-94.327648"
"6140703.DSC_0029.png"  "507.530317""16.157895" 
"51.473684"
"6140703.DSC_0030.png"  "12.981982" "-94.184916"
"6140703.DSC_0030.png"  "13.086967" "-94.151285"

Re: [R] Counting number of consecutive occurrences per rows

2013-05-03 Thread zuzana zajkova
ot;win", "win", "win", "win", "win", "win",
"win", "win", "win", "win", "win", "win", "win", "win", "win",
"win", "win", "win", "win", "win", "win", "win", "win", "win",
"win", "win", "win", "win", "win", "win", "win", "win", "win",
"win", "win", "win", "win", "win", "win", "win", "win", "win",
"win"), night = structure(c(1310962792, 1310963392, 1310963992,
1310964592, 1310965192, 1310965792, 1310966392, 1310966992, 1310967592,
1310968192, 1310968792, 1310969392, 1310969992, 1310970592, 1310971192,
1310971792, 1310972392, 1310972992, 1310973592, 1310974192, 1310974792,
1310975392, 1311107991, 1311108591, 1311109191, 1311109791, 130391,
130991, 131591, 132191, 132791, 133391, 133991,
134591, 135191, 135791, 136391, 136991, 137591,
138191, 138791, 139391, 139991, 1311034191, 1311034791,
1311035391, 1311035991, 1311036591, 1311037191, 1311037791, 1311038391,
1311038991, 1311039591, 1311040191, 1311040791, 1311041391, 1311041991,
1311042591, 1311043191, 1311043791), class = c("POSIXct", "POSIXt"
), tzone = "GMT"), day = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0), act = c(196, 200, 199, 200, 197, 198, 197,
200, 200, 197, 200, 200, 198, 200, 1, 1, 0, 0, 1, 2, 200, 200,
200, 200, 200, 200, 199, 61, 0, 194, 198, 198, 196, 193, 194,
193, 197, 198, 199, 200, 197, 199, 199, 200, 198, 200, 200, 198,
200, 34, 1, 1, 0, 0, 199, 200, 199, 7, 0, 0)), .Names = c("daten",
"juln", "fen", "night", "day", "act"), row.names = 9990:10049, class =
"data.frame")





On 29 April 2013 14:35, PIKAL Petr  wrote:

> Hi
>
> rrr<-rle(as.numeric(cut(test$act, c(0,1,199,200), include.lowest=T)))
> test$res <- rep(rrr$lengths, rrr$lengths)
>
> If you put it in function
>
> fff<- function(x, limits=c(0,1,199,200)) {
> rrr<-rle(as.numeric(cut(x, limits, include.lowest=T)))
> res <- rep(rrr$lengths, rrr$lengths)
> res
> }
>
> you can use split/lapply approach
>
> test$res2<-unlist(lapply(split(test$act, factor(test$day, levels=c(1,0))),
> fff))
>
> Beware of correct ordering of days in output. Without correct leveling of
> factor 0 precedes 1.
>
> And for the last part probably aggregate can be the way.
>
> > aggregate(test$res, list(test$jul, cut(test$act, c(0,1,199,200),
> include.lowest=T)), max)
>   Group.1   Group.2 x
> 1   14655 [0,1] 4
> 2   14655   (1,199] 3
> 3   14655 (199,200] 3
> > aggregate(test$res, list(test$jul, cut(test$act, c(0,1,199,200),
> include.lowest=T)), min)
>   Group.1   Group.2 x
> 1   14655 [0,1] 4
> 2   14655   (1,199] 1
> 3   14655 (199,200] 2
>
> Regards
> Petr
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> > project.org] On Behalf Of zuzana zajkova
> > Sent: Monday, April 29, 2013 12:45 PM
> > To: r-help@r-project.org
> > Subject: [R] Counting number of consecutive occurrences per rows
> >
> > Hi,
> >
> > I would appreciate if somebody could help me with following
> > calculation.
> > I have a dataframe, by 10 minutes time, for mostly one year data. This
> > is small example:
> >
> > > dput(test)
> > structure(list(jul = structure(c(14655, 14655, 14655, 14655, 14655,
> > 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655,
> > 14655), origin = structure(0, class = "Date")),
> > time = structure(c(1266258354, 1266258954, 1266259554, 1266260154,
> > 1266260754, 1266261354, 1266261954, 1266262554, 1266263154,
> > 1266263754, 1266264354, 1266264954, 1266265554, 1266266154,
> > 1266266754, 1266267354), class = c("POSIXct", "POSIXt"), tzone =
> > "GMT"),
> > act = c(130, 23, 45, 200, 200, 200, 199, 150, 0, 0, 0, 0,
> > 34, 200, 200, 145), day = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 0, 0, 0, 0, 0, 0)), .Names = c("jul", "time", "act", "day"
> > ), class = "data.frame", row.names = c(510L, 512L, 514L, 516L, 518L,
> > 520L, 522L, 524L, 526L, 528L, 530L, 532L, 534L, 536L, 538L,
> > 540L))
> >
> > L

[R] Counting number of consecutive occurrences per rows

2013-04-29 Thread zuzana zajkova
Hi,

I would appreciate if somebody could help me with following calculation.
I have a dataframe, by 10 minutes time, for mostly one year data. This is
small example:

> dput(test)
structure(list(jul = structure(c(14655, 14655, 14655, 14655,
14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655,
14655, 14655, 14655), origin = structure(0, class = "Date")),
time = structure(c(1266258354, 1266258954, 1266259554, 1266260154,
1266260754, 1266261354, 1266261954, 1266262554, 1266263154,
1266263754, 1266264354, 1266264954, 1266265554, 1266266154,
1266266754, 1266267354), class = c("POSIXct", "POSIXt"), tzone =
"GMT"),
act = c(130, 23, 45, 200, 200, 200, 199, 150, 0, 0, 0, 0,
34, 200, 200, 145), day = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0)), .Names = c("jul", "time", "act", "day"
), class = "data.frame", row.names = c(510L, 512L, 514L, 516L,
518L, 520L, 522L, 524L, 526L, 528L, 530L, 532L, 534L, 536L, 538L,
540L))

Looks like this:

> test
 jultime act day
510 14655 2010-02-15 18:25:54 130   1
512 14655 2010-02-15 18:35:54  23   1
514 14655 2010-02-15 18:45:54  45   1
516 14655 2010-02-15 18:55:54 200   1
518 14655 2010-02-15 19:05:54 200   1
520 14655 2010-02-15 19:15:54 200   1
522 14655 2010-02-15 19:25:54 199   1
524 14655 2010-02-15 19:35:54 150   1
526 14655 2010-02-15 19:45:54   0   1
528 14655 2010-02-15 19:55:54   0   1
530 14655 2010-02-15 20:05:54   0   0
532 14655 2010-02-15 20:15:54   0   0
534 14655 2010-02-15 20:25:54  34   0
536 14655 2010-02-15 20:35:54 200   0
538 14655 2010-02-15 20:45:54 200   0
540 14655 2010-02-15 20:55:54 145   0


What I would like to calculate is the number of consecutive occurrences of
values 200,  0 and together values from 1 til 199 (in fact the values that
differ from 200 and 0) in column "act".

I would like to get something like this (result$res)

> result
  jultime act day res res2
510 14655 2010-02-15 18:25:54 130   1   33
512 14655 2010-02-15 18:35:54  23   1   33
514 14655 2010-02-15 18:45:54  45   1   33
516 14655 2010-02-15 18:55:54 200   1   33
518 14655 2010-02-15 19:05:54 200   1   33
520 14655 2010-02-15 19:15:54 200   1   33
522 14655 2010-02-15 19:25:54 199   1   22
524 14655 2010-02-15 19:35:54 150   1   22
526 14655 2010-02-15 19:45:54   0   1   42
528 14655 2010-02-15 19:55:54   0   1   42
530 14655 2010-02-15 20:05:54   0   0   42
532 14655 2010-02-15 20:15:54   0   0   42
534 14655 2010-02-15 20:25:54  34   0   11
536 14655 2010-02-15 20:35:54 200   0   22
538 14655 2010-02-15 20:45:54 200   0   22
540 14655 2010-02-15 20:55:54 145   0   11

And if possible, distinguish among day==1 and day==0 (see the "act" values
of 0 for example), results as in result$res2.

After it I would like to make a resume table per days (jul):
where maxres is max(result$res) for the "act" value
where minres is min(result$res) for the "act" value
where sumres is sum(result$res) for the "act" value (for example, if the
200 value ocurrs in different times per day(jul) consecutively 3, 5, 1, 6
and 7 times the sumres would be 3+5+1+6+7= 22)

something like this (this are made up numbers):

julact maxres  minres sumres
146550  4   1   25
14655 200 32  48
146551-199   3171
146560   8238
14656 200 15360
146561-199   114 46
...
(theoretically the sum of sumres per day(jul) should be 144)


> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)


I hope my explanation is sufficient. I appreciate any hint.
Thank you,

Zuzana

[[alternative HTML version deleted]]

__
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.


[R] Fwd: Dotchart per groups

2013-04-15 Thread zuzana zajkova
Hi all,

I would like to ask you for advice. I did a dotplot - using dotchart
function.
There are two localites (loc) with values 75 or 56 in my data ZZ.
The f column has 4 levels: P1, S1, S8, R6.
The dataframe is ordered by N value, pchloc value is assign to use "pch" in
plot.

> head(ZZ)
loc  fN color ordered pchloc
98   75 S1 6.39 green   1 16
99   75 S8 6.44  blue   2 16
71   75 S8 6.60  blue   3 16
100  75 R6 6.64 black   4 16
70   75 S1 6.81 green   5 16
51   75 S8 6.83  blue   6 16


> dput(ZZ)
structure(list(loc = c(75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L,
56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 56L,
56L, 75L, 75L, 75L, 56L, 75L, 56L, 56L, 75L, 75L, 75L, 75L, 75L,
75L, 56L, 56L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 56L,
56L, 56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 56L,
75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 56L, 75L, 75L,
56L, 75L, 56L, 75L, 75L, 56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L,
56L, 75L, 56L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 56L, 75L, 56L,
75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 75L,
56L, 75L, 56L, 56L, 56L, 75L, 75L, 56L, 75L, 56L, 75L, 56L, 56L,
56L, 56L, 56L), f = structure(c(2L, 3L, 3L, 4L, 2L, 3L, 4L, 3L,
2L, 3L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 2L, 4L, 3L, 1L, 3L, 1L, 3L,
3L, 4L, 3L, 2L, 4L, 4L, 3L, 2L, 2L, 4L, 2L, 3L, 4L, 2L, 3L, 3L,
3L, 4L, 4L, 2L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 1L, 3L, 4L, 2L, 2L,
2L, 3L, 2L, 2L, 3L, 4L, 2L, 2L, 4L, 1L, 4L, 1L, 2L, 2L, 3L, 1L,
4L, 2L, 3L, 2L, 3L, 1L, 3L, 4L, 1L, 3L, 1L, 4L, 1L, 1L, 1L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 4L,
4L, 4L, 1L, 4L, 4L, 4L, 4L, 1L, 4L, 4L, 1L, 4L, 2L, 1L, 4L, 3L,
4L, 4L, 1L, 4L, 1L, 4L, 1L, 1L), .Label = c("P1", "S1", "S8",
"R6"), class = "factor"), N = c(6.39, 6.44, 6.6, 6.64, 6.81,
6.83, 6.84, 6.91, 6.93, 6.93, 6.94, 6.95, 7.01, 7.04, 7.12, 7.16,
7.24, 7.26, 7.26, 7.27, 7.29, 7.34, 7.34, 7.34, 7.41, 7.42, 7.42,
7.43, 7.43, 7.43, 7.44, 7.44, 7.45, 7.47, 7.49, 7.51, 7.52, 7.53,
7.53, 7.54, 7.54, 7.55, 7.55, 7.57, 7.57, 7.58, 7.59, 7.61, 7.61,
7.65, 7.67, 7.68, 7.69, 7.69, 7.7, 7.72, 7.72, 7.73, 7.75, 7.76,
7.78, 7.78, 7.78, 7.8, 7.81, 7.86, 7.86, 7.88, 7.92, 7.94, 7.95,
7.95, 7.98, 8, 8, 8.01, 8.02, 8.04, 8.11, 8.16, 8.17, 8.22, 8.23,
8.23, 8.26, 8.27, 8.31, 8.35, 8.37, 8.37, 8.41, 8.44, 8.45, 8.47,
8.49, 8.52, 8.55, 8.59, 8.62, 8.71, 8.71, 8.72, 8.78, 8.85, 8.91,
8.95, 9.02, 9.07, 9.07, 9.1, 9.12, 9.17, 9.19, 9.34, 9.36, 9.46,
9.46, 9.52, 9.63, 9.82, 10.01, 10.33, 10.33, 10.49, 10.88, 11.01,
11.24, 12.6), color = c("green", "blue", "blue", "black", "green",
"blue", "black", "blue", "green", "blue", "green", "green", "green",
"green", "blue", "green", "blue", "green", "black", "blue", "red",
"blue", "red", "blue", "blue", "black", "blue", "green", "black",
"black", "blue", "green", "green", "black", "green", "blue",
"black", "green", "blue", "blue", "blue", "black", "black", "green",
"blue", "blue", "blue", "green", "blue", "green", "blue", "red",
"blue", "black", "green", "green", "green", "blue", "green",
"green", "blue", "black", "green", "green", "black", "red", "black",
"red", "green", "green", "blue", "red", "black", "green", "blue",
"green", "blue", "red", "blue", "black", "red", "blue", "red",
"black", "red", "red", "red", "green", "red", "red", "green",
"red", "red", "red", "green", "red", "blue", "red", "red", "red",
"red", "red", "red", "black", "black", "black", "red", "black",
"black", "black", "black", "red", "black", "black", "red", "black",
"green", "red", "black", "blue", "black", "black", "red", "black",
"red", "black", "red", "red"), ordered = c(1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128), pchloc = c(16, 16, 16, 16, 16, 16, 16, 16, 1, 1, 16, 16,
16, 16, 16, 16, 16, 1, 16, 16, 1, 1, 16, 16, 16, 1, 16, 1, 1,
16, 16, 16, 16, 16, 16, 1, 1, 16, 16, 16, 16, 1, 16, 16, 16,
16, 1, 1, 1, 1, 16, 16, 16, 16, 16, 16, 16, 1, 16, 1, 16, 16,
16, 16, 16, 1, 16, 16, 16, 16, 1, 16, 16, 1, 16, 1, 16, 16, 1,
1, 16, 16, 16, 16, 16, 16, 1, 16, 1, 16, 16, 16, 16, 16, 1, 16,
1, 16, 1, 16, 16, 16, 16, 16, 16, 16, 1, 16, 16, 16, 16, 16,
1, 16, 1, 1, 1, 16, 16, 1, 16, 1, 16, 1, 1, 1, 1, 1)), .Names = c("loc",
"f", "N", "color", "ordered", "pchloc"), row.names = c(98L, 99L,
71L, 100L, 70L, 51L, 68L, 83L, 34L, 35L, 82L, 50L, 42L, 46L,
63L, 62L, 43L, 6L, 44L, 87L, 5L, 31L, 61L, 79L, 55L, 36L, 67L,
2L, 32L, 108L, 47L, 66L, 86L, 88L, 122L, 11L, 16L, 94L, 95L,
115L, 123L, 24L, 80L, 78L, 111L, 103L, 3L, 22L, 23L

[R] Dotchart per groups

2013-04-11 Thread zuzana zajkova
Hi all,

I would like to ask you for help. I did a dotplot - using dotchart
function.
There are two localites (loc) with values 75 or 56 in my data ZZ.
The f column has 4 levels: P1, S1, S8, R6.
The dataframe is ordered by N value, pchloc value is assign to use "pch" in
plot.

> head(ZZ)
loc  fN color ordered pchloc
98   75 S1 6.39 green   1 16
99   75 S8 6.44  blue   2 16
71   75 S8 6.60  blue   3 16
100  75 R6 6.64 black   4 16
70   75 S1 6.81 green   5 16
51   75 S8 6.83  blue   6 16


> dput(ZZ)
structure(list(loc = c(75L, 75L, 75L, 75L, 75L, 75L, 75L, 75L,
56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 56L,
56L, 75L, 75L, 75L, 56L, 75L, 56L, 56L, 75L, 75L, 75L, 75L, 75L,
75L, 56L, 56L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 56L,
56L, 56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 56L,
75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 56L, 75L, 75L,
56L, 75L, 56L, 75L, 75L, 56L, 56L, 75L, 75L, 75L, 75L, 75L, 75L,
56L, 75L, 56L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 56L, 75L, 56L,
75L, 75L, 75L, 75L, 75L, 75L, 75L, 56L, 75L, 75L, 75L, 75L, 75L,
56L, 75L, 56L, 56L, 56L, 75L, 75L, 56L, 75L, 56L, 75L, 56L, 56L,
56L, 56L, 56L), f = structure(c(2L, 3L, 3L, 4L, 2L, 3L, 4L, 3L,
2L, 3L, 2L, 2L, 2L, 2L, 3L, 2L, 3L, 2L, 4L, 3L, 1L, 3L, 1L, 3L,
3L, 4L, 3L, 2L, 4L, 4L, 3L, 2L, 2L, 4L, 2L, 3L, 4L, 2L, 3L, 3L,
3L, 4L, 4L, 2L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 1L, 3L, 4L, 2L, 2L,
2L, 3L, 2L, 2L, 3L, 4L, 2L, 2L, 4L, 1L, 4L, 1L, 2L, 2L, 3L, 1L,
4L, 2L, 3L, 2L, 3L, 1L, 3L, 4L, 1L, 3L, 1L, 4L, 1L, 1L, 1L, 2L,
1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 4L,
4L, 4L, 1L, 4L, 4L, 4L, 4L, 1L, 4L, 4L, 1L, 4L, 2L, 1L, 4L, 3L,
4L, 4L, 1L, 4L, 1L, 4L, 1L, 1L), .Label = c("P1", "S1", "S8",
"R6"), class = "factor"), N = c(6.39, 6.44, 6.6, 6.64, 6.81,
6.83, 6.84, 6.91, 6.93, 6.93, 6.94, 6.95, 7.01, 7.04, 7.12, 7.16,
7.24, 7.26, 7.26, 7.27, 7.29, 7.34, 7.34, 7.34, 7.41, 7.42, 7.42,
7.43, 7.43, 7.43, 7.44, 7.44, 7.45, 7.47, 7.49, 7.51, 7.52, 7.53,
7.53, 7.54, 7.54, 7.55, 7.55, 7.57, 7.57, 7.58, 7.59, 7.61, 7.61,
7.65, 7.67, 7.68, 7.69, 7.69, 7.7, 7.72, 7.72, 7.73, 7.75, 7.76,
7.78, 7.78, 7.78, 7.8, 7.81, 7.86, 7.86, 7.88, 7.92, 7.94, 7.95,
7.95, 7.98, 8, 8, 8.01, 8.02, 8.04, 8.11, 8.16, 8.17, 8.22, 8.23,
8.23, 8.26, 8.27, 8.31, 8.35, 8.37, 8.37, 8.41, 8.44, 8.45, 8.47,
8.49, 8.52, 8.55, 8.59, 8.62, 8.71, 8.71, 8.72, 8.78, 8.85, 8.91,
8.95, 9.02, 9.07, 9.07, 9.1, 9.12, 9.17, 9.19, 9.34, 9.36, 9.46,
9.46, 9.52, 9.63, 9.82, 10.01, 10.33, 10.33, 10.49, 10.88, 11.01,
11.24, 12.6), color = c("green", "blue", "blue", "black", "green",
"blue", "black", "blue", "green", "blue", "green", "green", "green",
"green", "blue", "green", "blue", "green", "black", "blue", "red",
"blue", "red", "blue", "blue", "black", "blue", "green", "black",
"black", "blue", "green", "green", "black", "green", "blue",
"black", "green", "blue", "blue", "blue", "black", "black", "green",
"blue", "blue", "blue", "green", "blue", "green", "blue", "red",
"blue", "black", "green", "green", "green", "blue", "green",
"green", "blue", "black", "green", "green", "black", "red", "black",
"red", "green", "green", "blue", "red", "black", "green", "blue",
"green", "blue", "red", "blue", "black", "red", "blue", "red",
"black", "red", "red", "red", "green", "red", "red", "green",
"red", "red", "red", "green", "red", "blue", "red", "red", "red",
"red", "red", "red", "black", "black", "black", "red", "black",
"black", "black", "black", "red", "black", "black", "red", "black",
"green", "red", "black", "blue", "black", "black", "red", "black",
"red", "black", "red", "red"), ordered = c(1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
128), pchloc = c(16, 16, 16, 16, 16, 16, 16, 16, 1, 1, 16, 16,
16, 16, 16, 16, 16, 1, 16, 16, 1, 1, 16, 16, 16, 1, 16, 1, 1,
16, 16, 16, 16, 16, 16, 1, 1, 16, 16, 16, 16, 1, 16, 16, 16,
16, 1, 1, 1, 1, 16, 16, 16, 16, 16, 16, 16, 1, 16, 1, 16, 16,
16, 16, 16, 1, 16, 16, 16, 16, 1, 16, 16, 1, 16, 1, 16, 16, 1,
1, 16, 16, 16, 16, 16, 16, 1, 16, 1, 16, 16, 16, 16, 16, 1, 16,
1, 16, 1, 16, 16, 16, 16, 16, 16, 16, 1, 16, 16, 16, 16, 16,
1, 16, 1, 1, 1, 16, 16, 1, 16, 1, 16, 1, 1, 1, 1, 1)), .Names = c("loc",
"f", "N", "color", "ordered", "pchloc"), row.names = c(98L, 99L,
71L, 100L, 70L, 51L, 68L, 83L, 34L, 35L, 82L, 50L, 42L, 46L,
63L, 62L, 43L, 6L, 44L, 87L, 5L, 31L, 61L, 79L, 55L, 36L, 67L,
2L, 32L, 108L, 47L, 66L, 86L, 88L, 122L, 11L, 16L, 94L, 95L,
115L, 123L, 24L, 80L, 78L, 111L, 103L, 3L, 22L, 23L, 

Re: [R] Double condition

2013-03-25 Thread zuzana zajkova
Hi,

although it takes some 10 minutes to do the calculation (the original
dataframe has more than 100 000 rows..), it seems to work ok.
Thanks for your time and help,

Zuzana

On 25 March 2013 15:37, Rui Barradas  wrote:

> Hello,
>
> I believe the following solves your problem. It's a bit more complicated
> but with the sample dataset you've provided the result is as wished.
>
>
>
> tmp <- lapply(split(subz, subz$time), function(x) {
> i1 <- which(as.character(x$fix) == "noon")[1]
> i2 <- which(as.character(x$fix) == "midnight")
> x$day[i2] <- x$day[i1]
> x})
> names(tmp) <- NULL
> result <- do.call(rbind, tmp)
>
>
>
> Hope this helps,
>
> Rui Barradas
>
> Em 25-03-2013 14:15, zuzana zajkova escreveu:
>
>> Hi Rui,
>>
>> thank you for your code, but unfortunately it doesn't work correctly. What
>> I got is this:
>>
>>
>>  subz
>>>
>>   jultimedtime  fixddawnddusk day
>> 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333   1
>> 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667   1
>> 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333   1
>> 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667   1
>>
>> 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333   1
>> 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667   1
>> 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333   1
>>   101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667   1
>>
>> 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333   0
>> 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667   0
>> 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333   0
>>
>> Where "day" for "time" 19:54:49 for midnight is 1 and for noon is 0. There
>> are supposed to be 0 both (as "dtime" 19.91361 > "ddusk" for noon
>> 19.88333)
>> Probably the problem would be adding 1 to he index in
>> subz$day[idx + 1] <- subz$day[idx]
>> So far, I haven't found solution...
>>
>> Zuzana
>>
>>
>>
>> On 22 March 2013 20:01, Rui Barradas  wrote:
>>
>>  Hello,
>>>
>>> Try the following.
>>>
>>>
>>> idx <- which(subz$fix == "noon")
>>> if(idx[length(idx)] == nrow(subz)) idx <- idx[-length(idx)]
>>> subz$day[idx + 1] <- subz$day[idx]
>>>
>>>
>>> Hope this helps,
>>>
>>> Rui Barradas
>>>
>>> Em 22-03-2013 18:18, zuzana zajkova escreveu:
>>>
>>>  Hi,
>>>>
>>>> I would appreciate if somebody could help me with this small issue...
>>>> I have a dataframe like this (originaly has more than 100 000 rows):
>>>>
>>>>   subz
>>>>
>>>>>
>>>>> jultimedtime  fixddawn
>>>>  ddusk day
>>>> 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333   1
>>>> 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667   1
>>>> 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333   1
>>>> 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667   0
>>>> 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333   1
>>>> 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667   0
>>>> 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333   1
>>>> 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667   0
>>>> 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333   0
>>>> 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667   0
>>>> 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333   0
>>>>
>>>>   dput(subz)
>>>>
>>>>>
>>>>>  structure(list(jul = c(15006, 15006, 15006, 15006, 15006, 15006,
>>>> 15006, 15006, 15006, 15006, 15006), time = structure(c(1296587689,
>>>> 1296588289, 1296588289, 129659, 129659, 1296589489, 1296589489,
>>>> 1296590089, 1296590089, 1296590689, 1296590689), class = c("POSIXct",
>>>> "POSIXt"), tzone = "GMT"), dtime = c(19.24694, 19.41361,
>>>> 19.413611

[R] Double condition

2013-03-25 Thread zuzana zajkova
Hi Rui,

thank you for your code, but unfortunately it doesn't work correctly. What
I got is this:


> subz
 jultimedtime  fixddawnddusk day
101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333   1
101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667   1
101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333   1
101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667   1

101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333   1
101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667   1
101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333   1
 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667   1

101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333   0
101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667   0
101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333   0

Where "day" for "time" 19:54:49 for midnight is 1 and for noon is 0. There
are supposed to be 0 both (as "dtime" 19.91361 > "ddusk" for noon 19.88333)
Probably the problem would be adding 1 to he index in
subz$day[idx + 1] <- subz$day[idx]
So far, I haven't found solution...

Zuzana



On 22 March 2013 20:01, Rui Barradas  wrote:

> Hello,
>
> Try the following.
>
>
> idx <- which(subz$fix == "noon")
> if(idx[length(idx)] == nrow(subz)) idx <- idx[-length(idx)]
> subz$day[idx + 1] <- subz$day[idx]
>
>
> Hope this helps,
>
> Rui Barradas
>
> Em 22-03-2013 18:18, zuzana zajkova escreveu:
>
>> Hi,
>>
>> I would appreciate if somebody could help me with this small issue...
>> I have a dataframe like this (originaly has more than 100 000 rows):
>>
>>  subz
>>>
>>   jultimedtime  fixddawnddusk day
>> 101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333   1
>> 101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667   1
>> 101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333   1
>> 101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667   0
>> 101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333   1
>> 101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667   0
>> 101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333   1
>> 101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667   0
>> 101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333   0
>> 101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667   0
>> 101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333   0
>>
>>  dput(subz)
>>>
>> structure(list(jul = c(15006, 15006, 15006, 15006, 15006, 15006,
>> 15006, 15006, 15006, 15006, 15006), time = structure(c(1296587689,
>> 1296588289, 1296588289, 129659, 129659, 1296589489, 1296589489,
>> 1296590089, 1296590089, 1296590689, 1296590689), class = c("POSIXct",
>> "POSIXt"), tzone = "GMT"), dtime = c(19.24694, 19.41361,
>> 19.41361, 19.58028, 19.58028, 19.74694,
>> 19.74694, 19.91361, 19.91361, 20.08028,
>> 20.08028), fix = structure(c(2L, 1L, 2L, 1L, 2L, 1L,
>> 2L, 1L, 2L, 1L, 2L), .Label = c("midnight", "noon"), class = "factor"),
>>  ddawn = c(7.916667, 7.916667, 7.916667,
>>  7.916667, 7.916667, 7.916667,
>> 7.916667,
>>  7.916667, 7.916667, 7.916667,
>> 7.916667
>>  ), ddusk = c(19.88333, 19.56667, 19.88333,
>>  19.56667, 19.88333, 19.56667,
>> 19.88333,
>>  19.56667, 19.88333, 19.56667,
>> 19.88333
>>  ), day = c(1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0)), .Names = c("jul",
>> "time", "dtime", "fix", "ddawn", "ddusk", "day"), row.names =
>> 101608:101618, class = "data.frame")
>>
>> where "day" is calculated as
>>
>> subz$day <- ifelse( subz$dtime > subz$ddusk | subz$dtime < subz$ddawn, 0,
>> 1
>> )
>>
>> The way I would like to calculate "day" is this
>> - for the same "time",  the "day" is calculated for "noon" as mentioned
>> above but  for "midnight" is just copying the same value as for "noon"

Re: [R] Double condition

2013-03-25 Thread zuzana zajkova
Hi,

To Mason:
I like your idea with reshaping the dataframe. I've read the paper and
checked the help for the "cast" function, but I wasn't able to reshape it
to wanted form, which as you mentioned would be (column names):
jul   timedtime  ddawn.noon ddawn.midnight   ddusk.noon   ddusk.midnight

And maybe it would be easier to do with this dataframe (the basic one which
later I use to create other dataframes, the one mentioned above as well),
I'm not sure:
> LOC[ 21:30,]
 jul  fix  dawn  dusk   lat   long
21 14664 midnight 07:49 20:00 15.92 -25.30
22 14664 noon 07:49 19:50 24.04 -24.07
23 14665 midnightNA NA
24 14665 noonNA NA
25 14666 midnightNA NA
26 14666 noon 07:48 19:55 21.19 -24.65
27 14667 midnight 07:51 19:55 24.32 -25.05
28 14667 noon 07:51 20:00 20.43 -25.69
29 14668 midnight 07:49 20:00 19.08 -25.47
30 14668 noon 07:49 19:53 26.24 -24.61

> dput(LOC[ 21:30,])
structure(list(jul = c("14664", "14664", "14665", "14665", "14666",
"14666", "14667", "14667", "14668", "14668"), fix = structure(c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("midnight", "noon"
), class = "factor"), dawn = structure(c(38L, 38L, NA, NA, NA,
37L, 40L, 40L, 38L, 38L), .Label = c("07:12", "07:13", "07:14",
"07:15", "07:16", "07:17", "07:18", "07:19", "07:20", "07:21",
"07:22", "07:23", "07:24", "07:25", "07:26", "07:27", "07:28",
"07:29", "07:30", "07:31", "07:32", "07:33", "07:34", "07:35",
"07:36", "07:37", "07:38", "07:39", "07:40", "07:41", "07:42",
"07:43", "07:44", "07:45", "07:46", "07:47", "07:48", "07:49",
"07:50", "07:51", "07:52", "07:53", "07:54", "07:55", "07:56",
"07:57", "07:58", "07:59", "08:00", "08:01", "08:02", "08:03",
"08:04", "08:05", "08:06", "08:07", "08:08", "08:11", "08:12",
"08:13", "08:15", "08:16", "08:17", "08:18", "08:19", "08:20",
"08:21", "08:22", "08:23", "08:25", "08:27", "08:28", "08:29",
"08:30", "08:31", "08:32", "08:35", "08:41"), class = "factor"),
dusk = structure(c(55L, 45L, NA, NA, NA, 50L, 50L, 55L, 55L,
48L), .Label = c("18:53", "19:00", "19:01", "19:03", "19:05",
"19:07", "19:08", "19:09", "19:10", "19:12", "19:13", "19:14",
"19:15", "19:16", "19:17", "19:19", "19:20", "19:21", "19:22",
"19:23", "19:24", "19:25", "19:26", "19:28", "19:29", "19:30",
"19:32", "19:33", "19:34", "19:35", "19:36", "19:37", "19:38",
"19:39", "19:40", "19:41", "19:42", "19:43", "19:44", "19:45",
"19:46", "19:47", "19:48", "19:49", "19:50", "19:51", "19:52",
"19:53", "19:54", "19:55", "19:56", "19:57", "19:58", "19:59",
"20:00", "20:01", "20:02", "20:03", "20:04", "20:05", "20:06",
"20:07", "20:08", "20:09", "20:10", "20:11", "20:13", "20:15",
"20:20", "20:25", "20:26", "20:29", "20:30", "20:31", "20:35",
"20:36", "20:38", "20:40", "20:41", "20:43", "20:44", "20:45",
"20:46", "20:47", "20:48", "20:49", "20:50", "20:51", "20:52",
"20:54", "20:55", "20:56", "20:58", "21:00", "21:01", "21:02",
"21:03", "21:04", "21:05", "21:06", "21:07", "21

[R] Double condition

2013-03-22 Thread zuzana zajkova
Hi,

I would appreciate if somebody could help me with this small issue...
I have a dataframe like this (originaly has more than 100 000 rows):

> subz
 jultimedtime  fixddawnddusk day
101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333   1
101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667   1
101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333   1
101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667   0
101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333   1
101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667   0
101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333   1
101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667   0
101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333   0
101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667   0
101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333   0

> dput(subz)
structure(list(jul = c(15006, 15006, 15006, 15006, 15006, 15006,
15006, 15006, 15006, 15006, 15006), time = structure(c(1296587689,
1296588289, 1296588289, 129659, 129659, 1296589489, 1296589489,
1296590089, 1296590089, 1296590689, 1296590689), class = c("POSIXct",
"POSIXt"), tzone = "GMT"), dtime = c(19.24694, 19.41361,
19.41361, 19.58028, 19.58028, 19.74694,
19.74694, 19.91361, 19.91361, 20.08028,
20.08028), fix = structure(c(2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L), .Label = c("midnight", "noon"), class = "factor"),
ddawn = c(7.916667, 7.916667, 7.916667,
7.916667, 7.916667, 7.916667, 7.916667,
7.916667, 7.916667, 7.916667, 7.916667
), ddusk = c(19.88333, 19.56667, 19.88333,
19.56667, 19.88333, 19.56667, 19.88333,
19.56667, 19.88333, 19.56667, 19.88333
), day = c(1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0)), .Names = c("jul",
"time", "dtime", "fix", "ddawn", "ddusk", "day"), row.names =
101608:101618, class = "data.frame")

where "day" is calculated as

subz$day <- ifelse( subz$dtime > subz$ddusk | subz$dtime < subz$ddawn, 0, 1
)

The way I would like to calculate "day" is this
- for the same "time",  the "day" is calculated for "noon" as mentioned
above but  for "midnight" is just copying the same value as for "noon".
So for the same "time" the "day" value should be the same for "noon" and
"midnight".
Something like this:

  jultimedtime  fixddawnddusk day
101608 15006 2011-02-01 19:14:49 19.24694 noon 7.916667 19.88333   1
101609 15006 2011-02-01 19:24:49 19.41361 midnight 7.916667 19.56667   1
101610 15006 2011-02-01 19:24:49 19.41361 noon 7.916667 19.88333   1
101611 15006 2011-02-01 19:34:49 19.58028 midnight 7.916667 19.56667   1
101612 15006 2011-02-01 19:34:49 19.58028 noon 7.916667 19.88333   1
101613 15006 2011-02-01 19:44:49 19.74694 midnight 7.916667 19.56667   1
101614 15006 2011-02-01 19:44:49 19.74694 noon 7.916667 19.88333   1
101615 15006 2011-02-01 19:54:49 19.91361 midnight 7.916667 19.56667   0
101616 15006 2011-02-01 19:54:49 19.91361 noon 7.916667 19.88333   0
101617 15006 2011-02-01 20:04:49 20.08028 midnight 7.916667 19.56667   0
101618 15006 2011-02-01 20:04:49 20.08028 noon 7.916667 19.88333   0

Where I get stuck, is I don't know how to get the value for "midnight".

Any suggestion is welcome. Thanks

Zuzana

[[alternative HTML version deleted]]

__
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.


Re: [R] Max value of each 2 rows in dataframe

2013-02-13 Thread zuzana zajkova
Hi,

thank you for your response. I tried the
A[-1,]<-do.call(rbind,lapply(split(A[-1,],((1:nrow(A[-1,])-1)%/%2)+1),function(x){x[4]<-max(x[4]);x}))
but somehow my computer got stuck...

I tried the other option using rollapply and that works pretty well, doing
exactly what I wanted to get.
This is my final solution:

 maxlig<-rollapply(A$lig[-1],2,max,align="right",fill=NA)
 maxlig<-c(A$lig[[1]], maxlig)  # to get back the value from 1st row
 A<-cbind(A, maxlig)
 A$lig<-A$maxlig
 A$x <- ifelse(as.numeric(row.names(A)) %% 2==1, 'keep', '') # add column x
where value is 'keep' or blank
 A <- A[A$x == "keep",] # remove where x is blank, keep the values in 10
minutes interval
 A$maxlig<-A$x<-NULL

Thank you for your help,

Zuzana


On 13 February 2013 06:55, arun  wrote:

> Hi,
>
> For the dataset A,
> Assuming that this is what you meant: the maximum value of "lig" in each 2
> rows excluding the first row:
>
> #dataset: A
>
> A[-1,]<-do.call(rbind,lapply(split(A[-1,],((1:nrow(A[-1,])-1)%/%2)+1),function(x){x[4]<-max(x[4]);x}))
>  A
> #   oktime secs lig  geo ind
> #1  ok 2010-01-15 04:45:00 40193.45  28 17016001 5500519
> #2  ok 2010-01-15 04:49:59 40193.45  64 17016001 5500519
> #3  ok 2010-01-15 04:54:59 40193.45  64 17016001 5500519
> #4  ok 2010-01-15 04:59:59 40193.46  32 17016001 5500519
> #5  ok 2010-01-15 05:04:59 40193.46  32 17016001 5500519
> #6  ok 2010-01-15 05:09:59 40193.47  13 17016001 5500519
> #7  ok 2010-01-15 05:14:59 40193.47  13 17016001 5500519
> #8  ok 2010-01-15 05:19:59 40193.47   8 17016001 5500519
> #9  ok 2010-01-15 05:24:59 40193.48   8 17016001 5500519
> #10 ok 2010-01-15 05:29:59 40193.48   0 17016001 5500519
> #11 ok 2010-01-15 05:34:59 40193.48   0 17016001 5500519
> #12 ok 2010-01-15 05:39:59 40193.49  64 17016001 5500519
> #13 ok 2010-01-15 05:44:59 40193.49  64 17016001 5500519
> #14 ok 2010-01-15 05:49:59 40193.49  64 17016001 5500519
> #15 ok 2010-01-15 05:54:59 40193.50  64 17016001 5500519
> #16 ok 2010-01-15 05:59:59 40193.50  64 17016001 5500519
> #17 ok 2010-01-15 06:04:59 40193.50  64 17016001 5500519
> #18 ok 2010-01-15 06:09:59 40193.51  51 17016001 5500519
> #19 ok 2010-01-15 06:14:59 40193.51  51 17016001 5500519
> #20 ok 2010-01-15 06:19:59 40193.51  64 17016001 5500519
>
> #If you need a rolling max,
> library(zoo)
> rollapply(A$lig,2,max,align="right",fill=NA)
>  #[1] NA 64 64 44 32 22 13  4  8  8  0 45 64 64 64 64 64 64 51 64
>
>
> A.K.
>
>
>
>
>
> - Original Message -
> From: zuzana zajkova 
> To: Rui Barradas 
> Cc: r-help@r-project.org
> Sent: Tuesday, February 12, 2013 6:53 PM
> Subject: Re: [R] Max value of each 2 rows in dataframe
>
> Hi,
>
> sorry for not useable data...
>
> When I tried to use the dput function to the dataframe let's call it A, had
> some problems with the time and clock variables... however I attach an
> other dataframe B, which is created by merging A with other dataframe. The
> B dataframe has a little different structure as I mentioned before about B,
> each time is kind of doubled by variable "fix".
>
> I realized also that probably the most simple way would be to apply the
> changes directly to the original source dataframe (has 119 313 rows), which
> is later used for creating other dataframes.
> Here I attach few lines (hope this format will work well), data are grabbed
> every 5 minutes. For this data I would like to save the first row as it is
> and from there save the max value of next 5 and 10 minutes.
> example: the 3rd line should get the "lig" value equal to max of "lig"
> value of line 2 and 3 and so on
>
>
> structure(list(ok = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "ok", class =
> "factor"),
> time = structure(c(1263548700, 1263548999, 1263549299, 1263549599,
> 1263549899, 1263550199, 1263550499, 1263550799, 1263551099,
> 1263551399, 1263551699, 1263551999, 1263552299, 1263552599,
> 1263552899, 1263553199, 1263553499, 1263553799, 1263554099,
> 1263554399), class = c("POSIXct", "POSIXt"), tzone = ""),
> secs = c(40193.447917, 40193.451389, 40193.454861, 40193.458333,
> 40193.461806, 40193.465278, 40193.46875, 40193.47, 40193.475694,
> 40193.479167, 40193.482639, 40193.486111, 40193.489583, 40193.493056,
> 40193.496528, 40193.5, 40193.503472, 40193.506944, 40193.510417,
> 40193.513889), lig = c(28L, 64L, 44L, 32L, 22L, 13L, 4L,
>0L, 8L, 0L, 0L, 45L, 64L, 64L, 64L, 47L, 64L, 50L, 51L,
> 64L), geo = c(17016001, 17016001, 1701

Re: [R] Max value of each 2 rows in dataframe

2013-02-12 Thread zuzana zajkova
6667, 8.116667,
8.116667, 8.116667, 8.116667, 8.116667,
8.116667), fix = structure(c(1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label =
c("midnight",
"noon"), class = "factor"), dawn = structure(c(NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = c("07:06", "07:07",
"07:08", "07:09", "07:10", "07:11", "07:12", "07:13", "07:14",
"07:15", "07:16", "07:17", "07:18", "07:19", "07:20", "07:21",
"07:22", "07:23", "07:24", "07:25", "07:26", "07:27", "07:28",
"07:29", "07:30", "07:31", "07:32", "07:33", "07:34", "07:35",
"07:36", "07:37", "07:38", "07:39", "07:40", "07:41", "07:42",
"07:43", "07:44", "07:45", "07:46", "07:47", "07:48", "07:49",
"07:50", "07:51", "07:52", "07:53", "07:54", "07:55", "07:56",
"07:57", "07:58", "07:59", "08:00", "08:01", "08:02", "08:03",
"08:04", "08:05", "08:06", "08:07", "08:08", "08:09", "08:11",
"08:12", "08:18", "15:27"), class = "factor"), dusk =
structure(c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), .Label = c("15:40",
"19:01", "19:03", "19:04", "19:06", "19:07", "19:08", "19:09",
"19:10", "19:11", "19:12", "19:13", "19:14", "19:15", "19:16",
"19:17", "19:18", "19:19", "19:20", "19:21", "19:22", "19:23",
"19:24", "19:25", "19:26", "19:27", "19:28", "19:29", "19:30",
"19:31", "19:32", "19:33", "19:34", "19:35", "19:36", "19:37",
"19:38", "19:39", "19:40", "19:41", "19:42", "19:43", "19:44",
"19:45", "19:46", "19:47", "19:48", "19:49", "19:50", "19:51",
"19:52", "19:53", "19:54", "19:55", "19:56", "19:57", "19:58",
"19:59", "20:00", "20:01", "20:02", "20:03", "20:04", "20:05",
"20:06", "20:08", "20:09", "20:10", "20:13", "20:14", "20:15",
"20:16", "20:23", "20:29", "20:30", "20:34", "20:35", "20:36",
"20:38", "20:40", "20:42", "20:43", "20:44", "20:45", "20:46",
"20:47", "20:48", "20:49", "20:50", "20:52", "20:53", "20:54",
"20:55", "20:56", "20:57", "20:58", "20:59", "21:00", "21:01",
"21:02", "21:03", "21:04", "21:05", "21:06", "21:07", "21:08",
"21:09", "21:10", "21:12", "21:13", "21:15", "21:17", "21:18"
), class = "factor"), lat = c(14.97, 14.97, 14.97, 14.97, 14.97,
14.97, 14.97, 14.97, 14.97, 14.97, 14.97, 14.97, 14.97, 14.97,
14.97, 14.97, 14.97, 14.97, 14.97, 14.97), long = c(-24.64, -24.64,
-24.64, -24.64, -24.64, -24.64, -24.64, -24.64, -24.64, -24.64,
-24.64, -24.64, -24.64, -24.64, -24.64, -24.64, -24.64, -24.64,
-24.64, -24.64), ddawn = c(8.116667, 8.116667,
8.116667, 8.116667, 8.116667, 8.116667,
8.116667, 8.116667, 8.116667, 8.116667,
8.116667, 8.116667, 8.116667, 8.116667,
8.116667, 8.116667, 

[R] Max value of each 2 rows in dataframe

2013-02-12 Thread zuzana zajkova
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.24972 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.33306 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.41639 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.49972 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.58306 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.66639 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.74972 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.83306 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.91639 0 "19/01/2010"
"8:09" "19:29" 19.48333 8.15
"1216" 14628 5500519 2010-01-19 15:59:59 40197.64 17016001 NA 64
"19/01/10" "15:59:59" 15 59 59 19 1 10 15.99972 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.08306 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.16639 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.24972 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.33306 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.41639 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.49972 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.58306 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.66639 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.74972 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.83306 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.91639 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.99972 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.08306 0 "19/01/2010"
"8:09" "19:29" 19.48333 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.16639 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.24972 0 "19/01/2010"
"8:09" "19:29" 19.48333 8.15
"1232" 14628 5500519 2010-01-19 17:19:59 40197.7 17016001 NA 0
"19/01/10" "17:19:59" 17 19 59 19 1 10 17.33306 NA "19/01/2010"
"8:09" "19:29" 19.48333 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.41639 0 "19/01/2010"
"8:09" "