[R] Getting the list of lines evaluated in a function call

2012-02-06 Thread Francois Rousseu

Hello useRs
I am looking for a function that can give the list of lines that were evaluated 
or used to generatethe last output from any function, whether an error message 
was generated or not. For example, let's say I have a function like this:
foo - function( x ){   if( x10 ){ 
   ans - x+100   
}else{  ans - x-100  } ans 
}
and I type:
 foo(4)[1] -96
I would like a function that returns something like this
list.lines(foo)[1] 1 3 4 5 6
or:
 foo(hello)Error in x + 100 : non-numeric argument to binary operator
list.lines(foo)[1] 1 2
Is there already a function in R doing something similar or anybody has any 
hints for functions that I could use to create such a function?
Sincerely,Francois Rousseu 



  
[[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] tcltk window freezes when using locator( )

2011-11-06 Thread Francois Rousseu

Hello useRs
 
Using the following code:
 
library(tcltk)
win-tktoplevel()
ff-function(){
 plot(1:10,1:10)
 pol-locator(1)
 print(pol)
 }
button-tkbutton(win,text=test,command=ff)
tkpack(button)
 
makes the win panel stop responding when the plot is closed before choosing a 
location. Usually, the windows task manager 
has to be used to close the window (which causes R to be stopped as well) or a 
message saying that R is not responding is 
displayed. I was having the same problem with R 2.13.0 so I upgraded to 2.14.0 
but the problem persists. I am using windows 7.
 
 sessionInfo()
R version 2.14.0 (2011-10-31)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_Canada.1252  LC_CTYPE=French_Canada.1252   
[3] LC_MONETARY=French_Canada.1252 LC_NUMERIC=C  
[5] LC_TIME=French_Canada.1252
attached base packages:
[1] tcltk stats graphics  grDevices utils datasets  methods   base  
 
Am I doing something wrong or more likely is this a bug?
 
Thanks,
Francois Rousseu
 
 
 
  
[[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] tcltk window freezes when using locator( )

2011-11-06 Thread Francois Rousseu

In fact, the same thing happens (window freezes) when a long computation 
generated by the tcltk window is stopped through the R console.
 
library(tcltk)
library(svMisc)
win-tktoplevel()
n-1
ff-function(){
 for(i in 1:n){progress(i,n)}
 }
button-tkbutton(win,text=test,command=ff)
tkpack(button)
 
Francois Rousseu

 

 From: francoisrous...@hotmail.com
 To: r-help@r-project.org
 Date: Sun, 6 Nov 2011 21:55:58 -0500
 Subject: [R] tcltk window freezes when using locator( )
 
 
 Hello useRs
 
 Using the following code:
 
 library(tcltk)
 win-tktoplevel()
 ff-function(){
 plot(1:10,1:10)
 pol-locator(1)
 print(pol)
 }
 button-tkbutton(win,text=test,command=ff)
 tkpack(button)
 
 makes the win panel stop responding when the plot is closed before choosing a 
 location. Usually, the windows task manager 
 has to be used to close the window (which causes R to be stopped as well) or 
 a message saying that R is not responding is 
 displayed. I was having the same problem with R 2.13.0 so I upgraded to 
 2.14.0 but the problem persists. I am using windows 7.
 
  sessionInfo()
 R version 2.14.0 (2011-10-31)
 Platform: x86_64-pc-mingw32/x64 (64-bit)
 locale:
 [1] LC_COLLATE=French_Canada.1252 LC_CTYPE=French_Canada.1252 
 [3] LC_MONETARY=French_Canada.1252 LC_NUMERIC=C 
 [5] LC_TIME=French_Canada.1252 
 attached base packages:
 [1] tcltk stats graphics grDevices utils datasets methods base 
 
 Am I doing something wrong or more likely is this a bug?
 
 Thanks,
 Francois Rousseu
 
 
 
 
 [[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.
  
[[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] Error installing packages

2011-10-28 Thread Francois Rousseu

Hi Picohan
I had a really similar error messages recently when trying to install packages 
from sources and it was related to my version of windows not being in english. 
See this for a discussion:
 
http://r.789695.n4.nabble.com/Building-package-DESCRIPTION-file-not-existing-td3935084.html
 
Cheers,
Francois Rousseu  
 

 Date: Fri, 28 Oct 2011 02:11:24 -0700
 From: han...@picoquant.com
 To: r-help@r-project.org
 Subject: Re: [R] Error installing packages
 
 Thanks for the tip, but I am not on win 7, I am on win xp.
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Re-Error-installing-packages-tp3947187p3947308.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.
  
[[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] Building package/DESCRIPTION file not existing?

2011-10-26 Thread Francois Rousseu

Thanks to both of you.
 
Indeed, it was a language issue. I eventually detected a check warning stating 
that the DESCRIPTION file had non-ASCII characters and unknown encoding, but no 
special characters were in the file. 
From reading various messages on mailing lists, I added Encoding: latin1 and it 
worked. Then, when installing the package tarball with install.packages, the  
é  in the  Propriétaire  for the library 
directory was changed to  ii . So I used it's DOS equivalent Program~1 and 
it also worked. I haven't notice any warning about using non-english Windows in 
the Writng R Extensions manual, but 
I may have missed it. Anyway, I realize now that using non-english Windows is 
probably a really bad idea in general.
 
Cheers,
Francois Rousseu 
 
 



 From: maech...@stat.math.ethz.ch
 Date: Wed, 26 Oct 2011 10:37:30 +0200
 To: francoisrous...@hotmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] Building package/DESCRIPTION file not existing?
 
  Francois Rousseu francoisrous...@hotmail.com
  on Mon, 24 Oct 2011 20:10:27 -0400 writes:
 
  Hello useRs
 
  I am trying to build a package for personal use and for
  making easier working with other people but I keep getting
  the same error message about the DESCRIPTION file not
  existing.
 
  when trying to install from a source tar.gz file:
 
  Error in .read_description(dfile) : file
  'C:/Users/Propri�taire/AppData/Local/Temp/RtmpHFMONb/R.INSTALL647a3535/mypkg/DESCRIPTION'
  does not exist
 
  when trying to build a binary version:
 
  Error in .read_description(dfile) : file
  'C:/Users/Propri�taire/Documents/RETROBIRD/mypkg/DESCRIPTION'
  does not exist
 
  In this last case, the DESCRIPTION file is certainly
  there! Also, help and DESCRIPTION files are edited and my
  path variable seems to be set correctly as I can access R
  and tex (form miktex 2.9) from the console. I feel it
  might be related to language issues (windows on my system
  is in french, see sessionInfo() at bottom of message) or
  something about temporary directories, but I really can't
  find the problem. I've looked into the cygwin warning, but
  it didn't seemed to be the problem, though I may be wrong.
 
 Yes, I'm almost sure it's the language issues.
 
 I've recently taught a course on R Package building
 and on Windows, the user had problems because of an 'ä'
 (a-Umlaut) in one of the directories in her 'path'.
 
 So if you work from another place than
 'C:/Users/Propri�taire/' this may solve the main problem.
 
 Bonnes salutations,
 Martin Maechler, ETH Zurich
 
  Any hints? Below is the complete sequence with errors.
 
  Thanks, Francois Rousseu
 
 [.]
  
[[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] Building package/DESCRIPTION file not existing?

2011-10-24 Thread Francois Rousseu


Hello useRs
 
I am trying to build a package for personal use and for making easier working 
with other people but I keep getting the same error message about the 
DESCRIPTION file not existing.
 
when trying to install from a source tar.gz file:
 
Error in .read_description(dfile) : 
  file 
'C:/Users/Propriétaire/AppData/Local/Temp/RtmpHFMONb/R.INSTALL647a3535/mypkg/DESCRIPTION'
 does not exist
 
when trying to build a binary version:
 
Error in .read_description(dfile) : 
  file 'C:/Users/Propriétaire/Documents/RETROBIRD/mypkg/DESCRIPTION' does not 
exist

In this last case, the DESCRIPTION file is certainly there! Also, help and 
DESCRIPTION files are edited and my path variable seems to be set correctly as 
I can access R and tex (form miktex 2.9) from the console. I feel it might be 
related to language issues (windows on my system is in french, see 
sessionInfo() at bottom of message) or something about temporary directories, 
but I really can't find the problem. I've looked into the cygwin warning, but 
it didn't seemed to be the problem, though I may be wrong.
 
Any hints? Below is the complete sequence with errors.
 
Thanks,
Francois Rousseu
 
   
 setwd(C:/Users/Propriétaire/Documents/RETROBIRD/)
 library(devtools)
 f - function(x,y) x+y
 d - data.frame(a=1, b=2)
 package.skeleton(list=c(f,d), name=mypkg)

## editing of help and description files
 
Creating directories ...
Creating DESCRIPTION ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './mypkg/Read-and-delete-me'.

 build(C:/Users/Propriétaire/Documents/RETROBIRD/mypkg)

* checking for file 
'C:\Users\Propriétaire\Documents\RETROBIRD\mypkg/DESCRIPTION' ... OK
* preparing 'mypkg':
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* looking to see if a 'data/datalist' file should be added
* building 'mypkg_1.0.tar.gz'
cygwin warning:
  MS-DOS style path detected: 
C:/Users/Propri\xC3\xA9taire/Documents/RETROBIRD/mypkg_1.0.tar.gz
  Preferred POSIX equivalent is: 
/cygdrive/c/Users/Propri\xC3\xA9taire/Documents/RETROBIRD/mypkg_1.0.tar.gz
  CYGWIN environment variable option nodosfilewarning turns off this warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
[1] C:/Users/Propriétaire/Documents/RETROBIRD/mypkg_1.0.tar.gz

 install.packages(pkgs=mypkg_1.0.tar.gz,lib=C:/Users/Propriétaire/Documents/R/win-library/2.13,repos=NULL,type=source)

* installing *source* package 'mypkg' ...
Error in .read_description(dfile) : 
  file 
'C:/Users/Propriétaire/AppData/Local/Temp/RtmpHFMONb/R.INSTALL647a3535/mypkg/DESCRIPTION'
 does not exist
ERROR: installing package DESCRIPTION failed for package 'mypkg'
* removing 'C:/Users/Propriétaire/Documents/R/win-library/2.13/mypkg'
Warning messages:
1: running command 'C:/PROGRA~1/R/R-213~1.0/bin/x64/R CMD INSTALL -l 
C:/Users/Propriétaire/Documents/R/win-library/2.13   mypkg_1.0.tar.gz' had 
status 1 
2: In install.packages(pkgs = mypkg_1.0.tar.gz, lib = 
C:/Users/Propriétaire/Documents/R/win-library/2.13,  :
  installation of package 'mypkg_1.0.tar.gz' had non-zero exit status
 
 build(C:/Users/Propriétaire/Documents/RETROBIRD/mypkg,binary=T)

* installing to library 'C:/Users/Propriétaire/Documents/R/win-library/2.13'
* installing *source* package 'mypkg' ...
Error in .read_description(dfile) : 
  file 'C:/Users/Propriétaire/Documents/RETROBIRD/mypkg/DESCRIPTION' does not 
exist
ERROR: installing package DESCRIPTION failed for package 'mypkg'
* removing 'C:/Users/Propriétaire/Documents/R/win-library/2.13/mypkg'
Error: Command failed (1)
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-213~1.0/bin/x64/R CMD INSTALL 
C:\Users\Propriétaire\Documents\RETROBIRD\mypkg --build' had status 1 

 sessionInfo()

R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=French_Canada.1252  LC_CTYPE=French_Canada.1252   
[3] LC_MONETARY=French_Canada.1252 LC_NUMERIC=C  
[5] LC_TIME=French_Canada.1252
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 
other attached packages:
[1] roxygen2_2.1 digest_0.5.1 devtools_0.4
loaded via a namespace (and not attached):
[1] brew_1.0-6 plyr_1.6   RCurl_1.6-10.1 stringr_0.5tools_2.13.0
  
[[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] calculating distance inland from coastline

2011-07-14 Thread Francois Rousseu

Hi Simon
 
A combination of functions gDistance, gBuffer and gIntersects from package 
rgeos should do the job. Also, have a look at www.naturalearthdata.com. They 
have various shapefiles with coastlines and land polygons, though I don't know 
how the resolution compares with the worldHires database.
 
Cheers,
Francois Rousseu
 

 Date: Thu, 14 Jul 2011 05:43:23 -0700
 From: s.j.good...@leeds.ac.uk
 To: r-help@r-project.org
 Subject: [R] calculating distance inland from coastline
 
 Hi All, 
 
 Does anybody know of any existing functions that will calculate distance
 inland from a coastline?
 
 It's possible to test if a lon,lat location is land or sea using
 map.where(), but I need to add a buffer to this of say 2km, to allow for
 points that are just on the coast, and below the resolution of the
 worldHires database.
 
 I'm working with a marine mammal satellite telemetry dataset and wish to
 filter out spurious locations on land.
 
 On another issue, does anybody know of any free vector map datasets that are
 more up to date and have a higher resolution than the worldHires database
 from the 'maps' package.
 
 Thanks, Simon 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/calculating-distance-inland-from-coastline-tp3667464p3667464.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.
  
[[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] Retrieving call sequence leading to a plot / Zooming in maps

2011-04-28 Thread Francois Rousseu

Hello R users
 
When I want to zoom in on a map or any plot in R, I usually use the locator 
function to reset the 
limit of the plot and do something like:
 
library(maptools)
library(mapdata)
 
map('worldHires',ylim=c(40,55),xlim=c(-90,-60))
points(-71,47,col=red,pch=16)
text(-73,49,Hello)

l-locator(2)

map('worldHires',ylim=range(l$y),xlim=range(l$x))
points(-71,47,col=red,pch=16)
text(-73,49,Hello)
 
I find this a bit annoying to type when there are a lot of things in a complex 
map. Now, what 
I would like to do is create a function that would zoom in on any type of plot 
or map without having 
to retype the steps that lead to the new rescaled plot. For this, I guess the 
function would have to 
find which calls/expressions led to the actual plot. Then, the function would 
only need to change 
the ylim and xlim in the expression leading to the plot creation and reevaluate 
all expressions. 
So my question is this: is there a function that can retrieve the call sequence 
that led to the actual plot?
 
Perhaps a function similar to this already exists? I've looked into the zoom 
and zoomInPlot functions, 
but none of them do exactly what I want. The zoomInPlot function comes close, 
but it seems to be 
limited to simple plots.
 
Thanks
Francois Rousseu
 
  
[[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] Coordinates of the text region

2011-03-26 Thread Francois Rousseu

Hello R people
 
Is there a way to get the coordinates of the text region (coordinates of the 
four corners for example) when using the text function? I'm looking for a way 
that does not make use of interactive function like locator. My goal is to 
determine the position of other structures in a graphic so that they don't 
overlap with the text.
 
Thanks
Francois Rousseu
  
[[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] Coordinates of the text region

2011-03-26 Thread Francois Rousseu

Let's say I do the following:
 
plot(0,0,type=n,xlim=c(0,10),ylim=c(0,10))
rect(4,5,5,6,border=black,col=white)
text(4.5,5.5,species,cex=2)
 
I would like to be able to determine a rectangle size that will be able to 
contain the text species. I'm working on a function using multiple lines and 
boxes where text of varying length has to be written.
 
Francois
 

 
 
 On Mar 26, 2011, at 8:39 PM, Francois Rousseu wrote:
 
 
  Hello R people
 
  Is there a way to get the coordinates of the text region 
  (coordinates of the four corners for example)
 
 What text region are you talking about?
 
  when using the text function? I'm looking for a way that does not 
  make use of interactive function like locator. My goal is to 
  determine the position of other structures in a graphic so that they 
  don't overlap with the text.
 
 The plotrix package and the rms package have functions for avoiding 
 plotted points but you seem to be looking for something else.
 
 -- 
 
 David Winsemius, MD
 West Hartford, CT
 
  
[[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] naming vectors

2011-02-21 Thread Francois Rousseu

Hello R users
 
I was trying to find a less annoying way of naming vectors than:
 
x-1:10
names(x)[1:length(x)]-A
 
So I tried:
 
x-1:10
names(x)-A #but this gave only the first element named (as described in 
the help files)
 
and
 
x-1:10
names(x)[]-A   #but this gave all elements named NA
 
The curious thing with this last option is that if the same line is ran a 
second time, now the vector gets the name A for all elements, which is what 
is desired
 
names(x)[]-A
 
I'm guessing the first time the names attribute is created and the second time 
values are given to this attribute. But shouldn't we expect the elements to be 
all named on the first try with the given value?
 
Cheers
Francois  
 
 
 
 
 
  
[[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] naming vectors

2011-02-21 Thread Francois Rousseu

 
I guess I will just get over my laziness and use the rep function instead! But 
my goal was more to point out the weird names attribution behaviour. 
 
I'm using named vectors of dates that can be associated to 2 stages (incubation 
and rearing in nesting birds) to overlay a vector of observed data and a vector 
of theoritical data to see if the stages match on same dates. A data frame 
could also be used for this task, but I thought that vectors are a bit simpler 
and faster to create.  
 
Francois Rousseu
 
 Date: Mon, 21 Feb 2011 15:58:36 +0100
 From: ivan.calan...@uni-hamburg.de
 To: r-help@r-project.org
 Subject: Re: [R] naming vectors
 
 It is indeed an interesting behavior and I have no idea what you could 
 do except what you did, though I would use:
 names(x) - rep(A, length(x))
 
 But I don't really understand why you want to give the same name to all 
 elements? There might be another way around depending on your goal
 
 Ivan
 
 Le 2/21/2011 15:44, Francois Rousseu a écrit :
  Hello R users
 
  I was trying to find a less annoying way of naming vectors than:
 
  x-1:10
  names(x)[1:length(x)]-A
 
  So I tried:
 
  x-1:10
  names(x)-A #but this gave only the first element named (as described in 
  the help files)
 
  and
 
  x-1:10
  names(x)[]-A #but this gave all elements named NA
 
  The curious thing with this last option is that if the same line is ran a 
  second time, now the vector gets the name A for all elements, which is 
  what is desired
 
  names(x)[]-A
 
  I'm guessing the first time the names attribute is created and the second 
  time values are given to this attribute. But shouldn't we expect the 
  elements to be all named on the first try with the given value?
 
  Cheers
  Francois
 
 
 
 
 
  
  [[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.
 
 
 -- 
 Ivan CALANDRA
 PhD Student
 University of Hamburg
 Biozentrum Grindel und Zoologisches Museum
 Abt. Säugetiere
 Martin-Luther-King-Platz 3
 D-20146 Hamburg, GERMANY
 +49(0)40 42838 6231
 ivan.calan...@uni-hamburg.de
 
 **
 http://www.for771.uni-bonn.de
 http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php
 
 __
 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] Testing for empty result of which

2011-02-15 Thread Francois Rousseu

Hello R users 
 
When using the function which to get matches, I usually do
 
w-which(x==y)
length(w)==0 
 
to determine if there are matches or not. Is there a base function that can do 
the thing more directly by returning a logical value if the result of which is 
empty or not?
 
Thanks
Francois Rousseu  
[[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] Cumulative percentage by unit of time

2010-12-15 Thread Francois Rousseu

Hi Sebastien!
 
How about this:
 
d-data.frame(nest,LD,FD)
l-apply(d,1,function(i){seq(i[LD],i[FD],by=1)})
jul-60:273
active-sapply(jul,function(i){sum(sapply(l,function(k){i %in% k}))})
ans-data.frame(jul,perc_act=100*active/length(nest))
ans 
 
When you say cumulative percentage active, do you mean nests active on a given 
date or do you also want to include nests that have been active?
 
Cheers,
Francois Rousseu
 
 
 
Date: Wed, 15 Dec 2010 14:34:04 -0500
From: sebastien.ri...@gmail.com
To: r-help@r-project.org
Subject: [R] Cumulative percentage by unit of time

Hi All,
 
I've been struggling on that one for a couple of days. I've tried several
things, but nothing is worth publishing.
 
I'm working with a bird nests data frame for which I have a laying date (LD)
and a fledgling date (FD) (in calendar Julian date) by nest id. For the
period spanning between LD and SD, the nest is termed active. Each nest id
occur once in the data frame.
 
How could I get the cumulative percentage of active nests by date within a
specified time frame ? Let's say from Julian date 60 to 273 ?
 
I would like the results to look like this :
 
Julian_date  prct_ active
60  0
61  5
62  10
63  25
...
 
Here is an example of the data frame
 
nest_id LD FD
   1193219
   2131159
   3196221
   4152179
   5136164
…
 
Cheers,
 
Sebastien
 
[[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. 
[[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.