[R] legend not appearing in Word document

2010-12-12 Thread Tim Clark
I need help with using graphics in Word 2007 that will later be converted into 
a 
pdf document.  I have tried several formats and found that I get the best 
quality of graphics using .wmf, .eps format, but when I convert it to .pdf I 
get 
a bunch of lines across the figures.  I also tried .tiff and .png but they give 
me much lower quality.  The best quality that converts to pdf appears to be 
.eps.  However, I have now come across a problem with my figure legends.  For 
some reason the legend is visible in R but not in Word.  Does anyone know why a 
legend in .eps format won't work in Word, or how I can get it to work?  I have 
made an example of the legend below that you should be able to save as .eps and 
paste into Word as an example.  I would appreciate any help you can offer on 
getting the legend in .eps format to work, or on other formats that may be 
better for Word and pdf files.

Thanks,

Tim

  library(plotrix)
  Satelite.Palette - 
colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red))
  mycol-Satelite.Palette(ceiling(5000+1))#Max relative angle multiplied by 
100 to give larger range.  Max is 3.1415, rounded up to 3.15 plus one.
  col.labels-round((seq(0,5000,length.out=5)/1000),1)
  plot(0, 0, type=n, axes=F, xlab=, ylab=)   #New plot for legend
  color.legend(0,0,1,1,col.labels, mycol, align=rb, gradient=y)   #Adds 
legend




 Tim Clark
Marine Ecologist
National Park of American Samoa
Pago Pago, AS 96799 




__
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] legend not appearing in Word document

2010-12-12 Thread Tim Clark
Thanks, I will take it up with MS.  I just downloaded their latest converter 
and that hasn't fixed the issue.  Hopefully they will have additional advice.

Aloha,

Tim

Tim Clark
Marine Ecologist
National Park of American Samoa
Pago Pago, AS 96799 





From: Schalk Heunis schalk.heu...@enerweb.co.za

Cc: r help r-help r-help@r-project.org; Tim Clark tim_cl...@nps.gov
Sent: Sun, December 12, 2010 6:05:23 AM
Subject: Re: [R] legend not appearing in Word document

Tim

Works in Word 2002 on Windows XP with PDF-xchange 3.0 to convert to pdf.

Saw reponse from Duncan - agree might be problem with Word 2007 PDF converter.

HTH
Schalk 





I need help with using graphics in Word 2007 that will later be converted into a
pdf document.  I have tried several formats and found that I get the best
quality of graphics using .wmf, .eps format, but when I convert it to .pdf I 
get
a bunch of lines across the figures.  I also tried .tiff and .png but they give
me much lower quality.  The best quality that converts to pdf appears to be
.eps.  However, I have now come across a problem with my figure legends.  For
some reason the legend is visible in R but not in Word.  Does anyone know why a
legend in .eps format won't work in Word, or how I can get it to work?  I have
made an example of the legend below that you should be able to save as .eps and
paste into Word as an example.  I would appreciate any help you can offer on
getting the legend in .eps format to work, or on other formats that may be
better for Word and pdf files.

Thanks,

Tim

  library(plotrix)
  Satelite.Palette -
colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red))
  mycol-Satelite.Palette(ceiling(5000+1))#Max relative angle multiplied by
100 to give larger range.  Max is 3.1415, rounded up to 3.15 plus one.
  col.labels-round((seq(0,5000,length.out=5)/1000),1)
  plot(0, 0, type=n, axes=F, xlab=, ylab=)   #New plot for legend
  color.legend(0,0,1,1,col.labels, mycol, align=rb, gradient=y)   #Adds
legend




 Tim Clark
Marine Ecologist
National Park of American Samoa
Pago Pago, AS 96799




__
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] Count continuous dates

2010-11-10 Thread Tim Clark
Dear List,

I have a series of dates and I am needing to know the greatest length of 
continuous dates - i.e. the number of dates before a break in the series.  For 
example, below there are three continuous series of dates with lengths 4, 6, 
and 
8.  How can I count the number of continuous dates?  rle() will do it for 
constant integers, but I can't figure a way to modify it for continuous dates.

x-c(1/10/10,2/10/10,3/10/10,4/10/10,
 6/10/10,7/10/10,8/10/10,9/10/10,10/10/10,11/10/10,
 
13/10/10,14/10/10,15/10/10,16/10/10,17/10/10,18/10/10,19/10/10,20/10/10)

x-strptime(x,%d/%m/%y)



Thanks!

Tim
 Tim Clark
Marine Ecologist
National Park of American Samoa
Pago Pago, AS 96799 




__
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] Count continuous dates

2010-11-10 Thread Tim Clark
Josh,

Great use of rle()!  I knew it had to fit in there somewhere!  Thanks for the 
help!

Tim

 Tim Clark
Marine Ecologist
National Park of American Samoa
Pago Pago, AS 96799 



- Original Message 
From: Joshua Wiley jwiley.ps...@gmail.com
To: Tim Clark mudiver1...@yahoo.com
Cc: r help r-help r-help@r-project.org
Sent: Wed, November 10, 2010 7:45:15 PM
Subject: Re: [R] Count continuous dates

Hi Tim,

Thanks for providing nice sample data!  It made this super easy :)

## use diff() to find the differences
## use rle() to find the run lengths
## use max to find the highest one
max(rle(as.vector(diff(x)))$lengths)


Cheers,

Josh

On Wed, Nov 10, 2010 at 10:07 PM, Tim Clark mudiver1...@yahoo.com wrote:
 Dear List,

 I have a series of dates and I am needing to know the greatest length of
 continuous dates - i.e. the number of dates before a break in the series.  For
 example, below there are three continuous series of dates with lengths 4, 6, 
and
 8.  How can I count the number of continuous dates?  rle() will do it for
 constant integers, but I can't figure a way to modify it for continuous dates.

 x-c(1/10/10,2/10/10,3/10/10,4/10/10,
  6/10/10,7/10/10,8/10/10,9/10/10,10/10/10,11/10/10,

13/10/10,14/10/10,15/10/10,16/10/10,17/10/10,18/10/10,19/10/10,20/10/10)
)

 x-strptime(x,%d/%m/%y)



 Thanks!

 Tim
  Tim Clark
 Marine Ecologist
 National Park of American Samoa
 Pago Pago, AS 96799




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



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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.


[R] Different results in FFT analysis

2010-10-23 Thread Tim Clark
, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 2, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 6, 4, 4, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 1, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
6, 13, 6, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 2, 11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 4, 7, 20, 37, 4, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 4, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 1)

Tim Clark

Marine Ecologist
National Park of American Samoa
Pago Pago, AS  96799




__
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] (no subject)

2010-10-11 Thread Tim Clark
Dear List,

I am trying to plot date vs. time, but am having problems getting my y-axis 
labels how I want them.  When left on its own R plots time at 6 hour intervals 
from 03:00 to 23:00.  I am wanting 6 hour intervals from 2:00 to 22:00.  I 
realize yaxp doesn't work in plot(), so I am trying to get it to work in 
par().  
However, now I get the ticks where I want them but the time is output as a very 
big number (serial time?).  I have also tried axis() using at= and also get 
seriel time numbers.  Any suggestions on how to format time on an axis?

  mydat$Date-as.POSIXct(as.character(mydat$Date), format=c(%m/%d/%Y))
  mydat$Time-as.POSIXct(as.character(mydat$Time), format=c(%H:%M:%S))

  plot(mydat$DateTime,mydat$Time, xlab=c(Date), ylab=c(Time),
  xlim=c(min(mydat$DateTime),max(mydat$DateTime)),
  ylim=c(min(mydat$Time),max(mydat$Time)),
  yaxt=n,
  yaxs=i,
  pch=19, cex=.4,
  type=n)

  par(yaxp=c(as.POSIXct(as.character(02:00), 
format=c(%H:%M)),as.POSIXct(as.character(22:00), format=c(%H:%M)),5))
  axis(2)


Thanks,

Tim
 Tim Clark

Marine Ecologist
National Park of American Samoa




__
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] Memory limit problem

2010-10-11 Thread Tim Clark
Dear List,

I am trying to plot bathymetry contours around the Hawaiian Islands using the 
package rgdal and PBSmapping.  I have run into a memory limit when trying to 
combine two fairly small objects using cbind().  I have increased the memory to 
4GB, but am being told I can't allocate a vector of size 240 Kb.  I am running 
R 
2.11.1 on a Dell Optiplex 760 with Windows XP.  I have pasted the error message 
and summaries of the objects below.  Thanks for your help.  Tim


 xyz-cbind(hi.to.utm,z=b.depth$z)
Error: cannot allocate vector of size 240 Kb

 memory.limit()
[1] 4000
 memory.size()
[1] 1971.68

 summary(hi.to.utm)
Object of class SpatialPoints
Coordinates:
    min   max
x  708745.5  923406.7
y 2046153.1 2327910.9
Is projected: TRUE 
proj4string :
[+proj=utm +zone=4 +datum=NAD83 +ellps=GRS80 +towgs84=0,0,0]
Number of points: 15328

 str(hi.to.utm)
Formal class 'SpatialPoints' [package sp] with 3 slots
  ..@ coords : num [1:15328, 1:2] 708746 710482 712218 713944 715681 ...
  .. ..- attr(*, dimnames)=List of 2
  .. .. ..$ : NULL
  .. .. ..$ : chr [1:2] x y
  ..@ bbox   : num [1:2, 1:2] 708746 2046153 923407 2327911
  .. ..- attr(*, dimnames)=List of 2
  .. .. ..$ : chr [1:2] x y
  .. .. ..$ : chr [1:2] min max
  ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots
  .. .. ..@ projargs: chr  +proj=utm +zone=4 +datum=NAD83 +ellps=GRS80 
+towgs84=0,0,0


 summary(b.depth)
   x    y   z    
 Min.   :-157.0   Min.   :18.50   Min.   :-5783  
 1st Qu.:-156.6   1st Qu.:18.98   1st Qu.:-4565  
 Median :-156.1   Median :19.80   Median :-3358  
 Mean   :-156.1   Mean   :19.73   Mean   :-3012  
 3rd Qu.:-155.5   3rd Qu.:20.41   3rd Qu.:-1601  
 Max.   :-155.0   Max.   :21.00   Max.   :    0  

 str(b.depth)
'data.frame':   15328 obs. of  3 variables:
 $ x: num  -157 -157 -157 -157 -157 ...
 $ y: num  21 21 21 21 21 ...
 $ z: num  -110 -114 -110 -88 -76 -122 -196 -224 -240 -238 ...

 

Tim Clark
Marine Ecologist
National Park of American Samoa





__
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] Changing x-axis on boxplot

2010-09-26 Thread Tim Clark
Dear List,
 
I am creating a boxplot with two subsets, very similar to the example by Roger 
Bivand at ?boxplot (reproduced below).  I am trying to change the labels on the 
x-axis to have one number to cover both subsets.  I can do this in other plots 
by using axis=FALSE followed by a separate axis() command.  I have also tried 
variations in the names= argument but can't get it to work.  Ideally I would 
like tickmarks on either side of each factor with the number for the level 
centered between the two tick marks.  Any suggestions?
 
Thanks,
 Tim 

Example:

boxplot(len ~ dose, data = ToothGrowth,
    boxwex = 0.25, at = 1:3 - 0.2,
    subset = supp == VC, col = yellow,
    main = Guinea Pigs' Tooth Growth,
    xlab = Vitamin C dose mg,
    ylab = tooth length,
    xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = i)
boxplot(len ~ dose, data = ToothGrowth, add = TRUE,
    boxwex = 0.25, at = 1:3 + 0.2,
    subset = supp == OJ, col = orange)
legend(2, 9, c(Ascorbic acid, Orange juice),
   fill = c(yellow, orange))


 Tim Clark

Marine Ecologist
National Park of American Samoa


 
__
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] Adding row name to dataframe

2010-09-26 Thread Tim Clark
Dear all,

I am trying to add a value to a dataframe and name the row with a number.  I 
have tried row.name, rowname, and attr(x,row.names) but none seem to work.  
It 
seems like it should be simple, so not sure why I can't get it to work.  Any 
suggestions?

Thanks,

Tim



x-seq(1,20,2)
y-seq(20,1,-2)
xy-data.frame(x,y)
xy-rbind(xy,c(0,0))

#Threeattempts that fail
row.names(xy[11,])-c(12)
rownames(xy[11,])-c(12)
attr(xy[11,], row.names)-c(12)


 Tim Clark

Marine Ecologist
National Park of American Samoa




__
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] Yet another memory limit problem

2010-08-19 Thread Tim Clark
Thanks for everyones help - mydat was not what I thought it was.  str(mydat) 
showed:
 $ Date   : Factor w/ 1504 levels ,2002-11-22,..: 295 295 295 295 295 
295 295 295 295 295 ...
 $ Time   : Factor w/ 72447 levels ,00:00:00,..: 15423 15470 15509 
17112 
17136 17159 17209 17239 17266 21527 ...
 
I didn't properly convert date and time using chron.  Not sure how R plots 
factor levels, but obviously it has problems with it!

Aloha,

Tim


 Tim Clark
Department of Zoology 
University of Hawaii 



- Original Message 
From: Peter Dalgaard pda...@gmail.com
To: Tim Clark mudiver1...@yahoo.com
Cc: r-help@r-project.org
Sent: Wed, August 18, 2010 8:34:56 AM
Subject: Re: [R] Yet another memory limit problem

On 08/18/2010 11:19 AM, Tim Clark wrote:
 Dear List,
...
 I would appreciate some help.  I think I set the target field correctly, both 
 memory.size and memory.limit indicate I have over 2G of memory, yet I can't 
 allocate 831.3Mb?  It just doesn't make sense to me.

That shouldn't by itself cause concern. It is always the _last_
allocation that triggers the message, so it could happen due to
allocation of 3 vectors of size 800M. Straw, camel, back...

Another matter is that memory.size is the amount _used_, not amount
_available_, so you would seem to have more like 1500M left.

However, it does look odd that mydat with dimensions 245x9 should
generate an 800M memory request. As others have suggested, perhaps mydat
is not what you think it should be...

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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.


[R] Yet another memory limit problem

2010-08-18 Thread Tim Clark
Dear List,

I have read and read and still don't get why I am getting a memory issue.  I am 
using a Samsung PC running Windows 7.  I have set memory in the target field:
 C:\Program Files (x86)\R\R-2.11.1\bin\Rgui.exe --max-mem-size=3G

But when I try a simple plot I get:

   plot(mydat$Date,mydat$Time)
Error: cannot allocate vector of size 831.3 Mb
 memory.size()
[1] 2099.61
 memory.limit()
[1] 3583
 dim(mydat)
[1] 245   9

I would appreciate some help.  I think I set the target field correctly, both 
memory.size and memory.limit indicate I have over 2G of memory, yet I can't 
allocate 831.3Mb?  It just doesn't make sense to me.

Thanks,

Tim




__
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] Reading files with varying number of columns

2010-07-18 Thread Tim Clark
Dear R list,
I am trying to read files with a varying number of columns and can't figure out 
how to get them in the proper format.  Some rows have five value and some have 
seven.  Is there a way to read them in so that two empty columns are added to 
every row that has only five values?  An example of the data follows.  Thanks!  
Tim

46,B,00301,2004-02-03,11:59:16
46,B,00301,2004-02-03,12:03:43
46,B,00301,2004-02-03,12:39:17
46,B,00301,2004-02-03,23:07:28
43,C,00232,2004-02-04,07:39:57,-1.5,meters
44,A,00230,2004-02-04,07:44:59
44,A,00230,2004-02-04,07:46:19
44,A,00230,2004-02-04,07:48:24
44,A,00230,2004-02-04,07:49:12
43,C,00232,2004-02-04,07:53:08,2.5,meters
44,A,00230,2004-02-04,07:54:34
44,A,00230,2004-02-04,07:55:08
43,C,00232,2004-02-04,07:56:18,2.9,meters
43,C,00232,2004-02-04,07:56:39,2.5,meters
46,B,00301,2004-02-04,08:00:49
43,C,00232,2004-02-04,08:02:12,-1.1,meters
43,C,00232,2004-02-04,08:04:01,2.2,meters
43,C,00232,2004-02-04,08:04:26,3.3,meters
43,C,00232,2004-02-04,08:40:26,2.9,meters
43,C,00232,2004-02-04,08:41:04,-2.2,meters
43,C,00232,2004-02-04,08:42:44,2.2,meters
43,C,00232,2004-02-04,08:44:31,2.9,meters
44,A,00231,2004-02-04,09:04:43
44,A,00231,2004-02-04,09:10:30
44,A,00231,2004-02-04,09:12:08
44,A,00231,2004-02-04,09:13:32
44,A,00231,2004-02-04,09:14:06
43,C,00232,2004-02-04,09:18:24,0.4,meters
43,C,00232,2004-02-04,09:20:13,2.5,meters
44,A,00231,2004-02-04,09:21:04
44,A,00231,2004-02-04,09:22:53
44,A,00231,2004-02-04,09:25:32
44,A,00231,2004-02-04,09:29:31
44,A,00231,2004-02-04,09:30:05
43,C,00232,2004-02-04,09:53:25,2.5,meters
43,C,00232,2004-02-04,09:53:53,1.5,meters
46,B,00301,2004-02-04,22:16:24
46,B,00301,2004-02-04,22:19:32
46,B,00258,2004-02-04,23:44:01
46,B,00258,2004-02-04,23:44:28


 Tim Clark

Marine Ecologist
National Park of American Samoa
Pago Pago, American Samoa  96799




__
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] Reading files with varying number of columns

2010-07-18 Thread Tim Clark
Thanks for the suggestion.  I had read fill but didn't pick up on the 
details.  It only uses the first five columns to determine column dimensions, 
so 
it ignored my last two columns.  Specifying col.names with fill=TRUE did the 
trick!

Aloha,

Tim


 




- Original Message 
From: Uwe Ligges lig...@statistik.tu-dortmund.de
To: Tim Clark mudiver1...@yahoo.com
Cc: r-help@r-project.org
Sent: Sun, July 18, 2010 6:03:47 AM
Subject: Re: [R] Reading files with varying number of columns

See argument fill in ?read.table

Uwe Ligges


On 18.07.2010 12:14, Tim Clark wrote:
 Dear R list,
 I am trying to read files with a varying number of columns and can't figure 
out
 how to get them in the proper format.  Some rows have five value and some have
 seven.  Is there a way to read them in so that two empty columns are added to
 every row that has only five values?  An example of the data follows.  Thanks!
 Tim

 46,B,00301,2004-02-03,11:59:16
 46,B,00301,2004-02-03,12:03:43
 46,B,00301,2004-02-03,12:39:17
 46,B,00301,2004-02-03,23:07:28
 43,C,00232,2004-02-04,07:39:57,-1.5,meters
 44,A,00230,2004-02-04,07:44:59
 44,A,00230,2004-02-04,07:46:19
 44,A,00230,2004-02-04,07:48:24
 44,A,00230,2004-02-04,07:49:12
 43,C,00232,2004-02-04,07:53:08,2.5,meters
 44,A,00230,2004-02-04,07:54:34
 44,A,00230,2004-02-04,07:55:08
 43,C,00232,2004-02-04,07:56:18,2.9,meters
 43,C,00232,2004-02-04,07:56:39,2.5,meters
 46,B,00301,2004-02-04,08:00:49
 43,C,00232,2004-02-04,08:02:12,-1.1,meters
 43,C,00232,2004-02-04,08:04:01,2.2,meters
 43,C,00232,2004-02-04,08:04:26,3.3,meters
 43,C,00232,2004-02-04,08:40:26,2.9,meters
 43,C,00232,2004-02-04,08:41:04,-2.2,meters
 43,C,00232,2004-02-04,08:42:44,2.2,meters
 43,C,00232,2004-02-04,08:44:31,2.9,meters
 44,A,00231,2004-02-04,09:04:43
 44,A,00231,2004-02-04,09:10:30
 44,A,00231,2004-02-04,09:12:08
 44,A,00231,2004-02-04,09:13:32
 44,A,00231,2004-02-04,09:14:06
 43,C,00232,2004-02-04,09:18:24,0.4,meters
 43,C,00232,2004-02-04,09:20:13,2.5,meters
 44,A,00231,2004-02-04,09:21:04
 44,A,00231,2004-02-04,09:22:53
 44,A,00231,2004-02-04,09:25:32
 44,A,00231,2004-02-04,09:29:31
 44,A,00231,2004-02-04,09:30:05
 43,C,00232,2004-02-04,09:53:25,2.5,meters
 43,C,00232,2004-02-04,09:53:53,1.5,meters
 46,B,00301,2004-02-04,22:16:24
 46,B,00301,2004-02-04,22:19:32
 46,B,00258,2004-02-04,23:44:01
 46,B,00258,2004-02-04,23:44:28


  Tim Clark

 Marine Ecologist
 National Park of American Samoa
 Pago Pago, American Samoa  96799




 __
 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-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] Generating all possible models from full model

2010-05-19 Thread Tim Clark
(mantas~year+cosmonth+sinmonth+coslunar+sinlunar, 
data=mydata))
  m23457-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+plankton, 
data=mydata))
  
  m23467-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+sinlunar+plankton, 
data=mydata))

  m23567-glm.convert(glm.nb(mantas~year+cosmonth+coslunar+sinlunar+plankton, 
data=mydata))
  
  m24567-glm.convert(glm.nb(mantas~year+sinmonth+coslunar+sinlunar+plankton, 
data=mydata))
  
  
m34567-glm.convert(glm.nb(mantas~cosmonth+sinmonth+coslunar+sinlunar+plankton, 
data=mydata))

#Six terms - 7 models  
  
m123456-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar,
 data=mydata))
  
m123457-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+plankton,
 data=mydata)) 
  
  
m123467-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+sinlunar+plankton,
 data=mydata)) 
  
  
m123567-glm.convert(glm.nb(mantas~site*year+cosmonth+coslunar+sinlunar+plankton,
 data=mydata)) 
  
  
m124567-glm.convert(glm.nb(mantas~site*year+sinmonth+coslunar+sinlunar+plankton,
 data=mydata))
  
  
m134567-glm.convert(glm.nb(mantas~site+cosmonth+sinmonth+coslunar+sinlunar+plankton,
 data=mydata))  
  
  
m234567-glm.convert(glm.nb(mantas~year+cosmonth+sinmonth+coslunar+sinlunar+plankton,
 data=mydata))

#Seven terms - 1 model
  
m1234567-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton,
 data=mydata))


Tim Clark
Department of Zoology 
University of Hawaii

__
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] Generating all possible models from full model

2010-05-19 Thread Tim Clark
Thanks to everyone for the replies and functions.  For some reason my emails 
are not going to the thread.  I just switched to the newer mail version for my 
yahoo account, so hopefully this one will get posted.

Aloha,

Tim

 Tim Clark
Department of Zoology 
University of Hawaii 



- Original Message 
From: Xiaogang Su xiaogan...@gmail.com
To: Tim Clark mudiver1...@yahoo.com
Cc: r-help@r-project.org
Sent: Wed, May 19, 2010 9:42:40 AM
Subject: Re: [R] Generating all possible models from full model

A couple of years ago, I wrote a function for doing this. It can be
found in the following file:
http://pegasus.cc.ucf.edu/~xsu/CLASS/STA4164/mt4-2009.doc
I also pasted a copy below. Hope you find it useful.  -XG

# 
# ALL POSSIBLE REGRESSIONS
# 
# The parameter k is the total number of predictors. To apply the function,
# you need to prepare the data so that all predictors for selection are named
# as x1, x2, ..., and the response is called y.

all.possible.regressions - function(dat, k){
    n - nrow(dat)
    regressors - paste(x, 1:k, sep=)
    lst - rep(list(c(T, F)), k)
    regMat - expand.grid(lst);
    names(regMat) - regressors
    formular - apply(regMat, 1, function(x)
            as.character(paste(c(y ~ 1, regressors[x]), collapse=+)))
    allModelsList - apply(regMat, 1, function(x)
            as.formula(paste(c(y ~ 1, regressors[x]),collapse= + )) )
    allModelsResults - lapply(allModelsList,
            function(x, data) lm(x, data=data), data=dat)
    n.models - length(allModelsResults)
    extract - function(fit) {
        df.sse - fit$df.residual
        p - n - df.sse -1
        sigma - summary(fit)$sigma
        MSE - sigma^2
        R2 - summary(fit)$r.squared
        R2.adj - summary(fit)$adj.r.squared
        sse - MSE*df.sse
        aic - n*log(sse) + 2*(p+2)
        bic - n*log(sse) + log(n)*(p+2)
        out - data.frame(df.sse=df.sse, p=p, SSE=sse, MSE=MSE,
            R2=R2, R2.adj=R2.adj, AIC=aic, BIC=bic)
        return(out)
    }
    result - lapply(allModelsResults, extract)
    result - as.data.frame(matrix(unlist(result), nrow=n.models, byrow=T))
    result - cbind(formular, result)
rownames(result) - NULL
colnames(result) - c(model, df.sse, p, SSE, MSE, R2,
R2.adj, AIC, BIC)
    return(result)
}
all.possible.regressions(dat=quasar, k=5)


On Tue, May 18, 2010 at 11:38 PM, Tim Clark mudiver1...@yahoo.com wrote:
 Is there a function that will allow me to run all model iterations if I 
 specify a full model?  I am using information criteria to choose between 
 possible candidate models.  I have been writing out all possible model 
 combinations by hand, and I am always worried that I am missing models or 
 have made a mistake somewhere.  It is also difficult to alter models if I 
 want to change a term.  For example, below are the set of models I would like 
 to run.  Is there a way to specify the full model and have R generate the 
 rest?  I.e. specify

  m1234567-glm.convert(glm.nb(mantas~site*year+cosmonth+sinmonth+coslunar+sinlunar+plankton,
  data=mydata))

 and have R run all the other models.


 library(MASS)

 #Intercept only
  m0-glm.convert(glm.nb(mantas~1,data=mydata))

 #One term - 7 models
  #Manta abundance is greater at one of the two sites
  m1-glm.convert(glm.nb(mantas~site,data=mydata))
  #Manta abundance increases each year as the population increases in size due 
 to births or immigration being greater than deaths and emmigration
  m2-glm.convert(glm.nb(mantas~year,data=mydata))
  #Manta abundances increases during part of the year due to seasonal cycles 
 in resources (mates, food)
  m3-glm.convert(glm.nb(mantas~cosmonth,data=mydata))
  m4-glm.convert(glm.nb(mantas~sinmonth,data=mydata))
  #Manta abundance decreases with increased lunar phase
  m5-glm.convert(glm.nb(mantas~coslunar, data=mydata))
  m6-glm.convert(glm.nb(mantas~sinlunar, data=mydata))
  #Manta abundance increases with increased levels of plankton
  m7-glm.convert(glm.nb(mantas~plankton,data=mydata))

 #Two terms - 21 models
  m12-glm.convert(glm.nb(mantas~site*year, data=mydata))   #Interaction term 
 to account for hotel being closed at Keauhou for some years
  m13-glm.convert(glm.nb(mantas~site+cosmonth,data=mydata))
  m14-glm.convert(glm.nb(mantas~site+sinmonth,data=mydata))
  m15-glm.convert(glm.nb(mantas~site+coslunar,data=mydata))
  m16-glm.convert(glm.nb(mantas~site+sinlunar,data=mydata))
  m17-glm.convert(glm.nb(mantas~site+plankton,data=mydata)) #Should this have 
 an interaction term?  Plankton may varry by site

  m23-glm.convert(glm.nb(mantas~year+cosmonth,data=mydata))
  m24-glm.convert(glm.nb(mantas~year+sinmonth,data=mydata))
  m25-glm.convert(glm.nb(mantas~year+coslunar,data=mydata))
  m26-glm.convert(glm.nb(mantas~year+sinlunar,data=mydata))
  m27-glm.convert(glm.nb(mantas~year+plankton,data=mydata))

  m34-glm.convert(glm.nb(mantas~cosmonth+sinmonth,data=mydata))
  m35-glm.convert(glm.nb(mantas~cosmonth+coslunar,data

Re: [R] bar order using lattice barchart()

2010-05-06 Thread Tim Clark
Greg,

Thanks for the great explanation.  Knowing the philosophy behind these kind of 
things really helps avoid problems in the future. 

Aloha,

Tim

Tim Clark
Department of Zoology 
University of Hawaii


--- On Thu, 5/6/10, Greg Snow greg.s...@imail.org wrote:

 From: Greg Snow greg.s...@imail.org
 Subject: RE: [R] bar order using lattice barchart()
 To: Tim Clark mudiver1...@yahoo.com, r-help@r-project.org 
 r-help@r-project.org
 Date: Thursday, May 6, 2010, 7:51 AM
 The short answer to your query is
 ?reorder
 
 The longer answer (or a longer answer) gets into a bit of
 philosophy (so feel free to go back to the short answer and
 skip this if you don't want to get into the philosophy, you
 have been warned).  Let's start with the question: is
 the order of the bars a property of the graph/analysis? The
 dataset as a whole? Or the individual variable?
 
 Some programs take the first approach, the order is a
 property of the graph or analysis, these programs have you
 specify things like the order at the time of creating the
 graph or doing the analysis.  I don't like this
 approach because it seems to me that this should be more
 inherent to the data than the output, also this means that
 you have to keep specifying the order for every
 graph/analysis and I am too lazy to like that.
 
 Your attempt was number 2, the order should be a property
 of the dataset.  For your example this makes a lot of
 sense, you want x ordered by y.  But this does not
 generalize to some other situations, so is not the standard
 for R.
 
 My favorite (and what is used in R, so apparently I'm not
 the only one) is to have things like the order be a property
 of the individual variable (x in this case).  Your data
 frame will have x as a factor by default (and even if you
 specifically told R to not convert it to a factor, then many
 plotting/analysis functions will still convert it to a
 factor).  If you don't specify the order of the factor
 levels then the default is to do it alphabetically and this
 will be used by plotting/analysis functions regardless of
 the order in the data set.  One of the easier ways to
 change the order of the factor levels, especially for a case
 like yours is using the reoder function, try something
 like:
 
  xy$x - reorder( xy$x, xy$y )
 
 You won't see any obvious differences when you print the
 data frame, but if you print just x then you should and your
 plots should come out the way that you want now.
 
 You did ask why? and were warned.  Hope this helps,
 
 -- 
 Gregory (Greg) L. Snow Ph.D.
 Statistical Data Center
 Intermountain Healthcare
 greg.s...@imail.org
 801.408.8111
 
 
  -Original Message-
  From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-
  project.org] On Behalf Of Tim Clark
  Sent: Wednesday, May 05, 2010 8:57 PM
  To: r-help@r-project.org
  Subject: [R] bar order using lattice barchart()
  
  Dear List,
  
  I am want to plot my data in increasing order using
 the lattice
  barchart() function.  I used order() to put my
 data in the order I
  want, but when I plot it I get the original order of
 the data.  I think
  this has to do with the row index number since order()
 does not re-
  number the rows in the new order but instead keeps the
 original row
  numbers and puts them in a different order.  For
 example:
  
  xy-data.frame(x=letters[1:5],y=c(3,9,2,1,10))
  
  #This produces a dataframe in alphebitical order with
 row numbers in
  #numerical order.
   xy
    x     
    y
  1 a  8.921657
  2 b 10.314625
  3 c  9.531537
  4 d 10.818563
  5 e  9.084872
  
  
  #If I re-order the data based on the value of y
  
  xy-xy[order(y),]
  
  #I get a dataframe ordered by y but the row numbers
 are still in
  #alphebetical order based on x
   xy
    x     
    y
  1 a  8.921657
  5 e  9.084872
  3 c  9.531537
  2 b 10.314625
  4 d 10.818563
  
  #I then try to plot the data and it plots it in
 alphabetical instead of
  #numeric order
  library(lattice)
  barchart(y~x, data=xy)
  
  
  
  Why are the rows not re-indexed, and how do I get
 barchart() to plot my
  data in increasing numeric order?
  
  Thanks,
  
  Tim
  
  
  
  
  Tim Clark
  Department of Zoology
  University of Hawaii
  
  __
  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-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] Estimating theta for negative binomial model

2010-05-04 Thread Tim Clark
Brian,

glm.convert() does exactly what I am wanting.  Thanks for putting it in MASS.  
Sorry about not giving credit.  It is a great package and I keep finding 
functions that make statistical programming easy!

Aloha,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Mon, 5/3/10, Prof Brian Ripley rip...@stats.ox.ac.uk wrote:

 From: Prof Brian Ripley rip...@stats.ox.ac.uk
 Subject: Re: [R] Estimating theta for negative binomial model
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Monday, May 3, 2010, 7:50 PM
 On Mon, 3 May 2010, Tim Clark wrote:
 
  Dear List,
  
  I am trying to do model averaging for a negative
 binomial model using the package AICcmodavg.  I need to
 use glm() since the package does not accept glm.nb()
 models.  I can get glm() to work if I first run glm.nb
 and take theta from that model, but is there a simpler way
 to estimate theta for the glm model?  The two models
 are:
  
  mod.nb-glm.nb(mantas~site,data=mydata)
  mod.glm-glm(mantas~site,data=mydata,
 family=negative.binomial(mod.nb$theta))
  
  How else can I get theta for the
 family=negative.binomial(theta=???)
 
 library(MASS) is missing here -- do give credit where
 credit is due.
 It contains functions
 
 glm.convert
 theta.ml
 
 and the first does what you seem to want and the second
 answers the actual question you asked.
 
  Thanks!
  
  Tim
  
  Tim Clark
  Department of Zoology
  University of Hawaii
 
 -- Brian D. Ripley,         
         rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford,         
    Tel:  +44 1865 272861 (self)
 1 South Parks Road,         
            +44 1865
 272866 (PA)
 Oxford OX1 3TG, UK           
     Fax:  +44 1865 272595
 




__
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] Estimating theta for negative binomial model

2010-05-03 Thread Tim Clark
Dear List,

I am trying to do model averaging for a negative binomial model using the 
package AICcmodavg.  I need to use glm() since the package does not accept 
glm.nb() models.  I can get glm() to work if I first run glm.nb and take theta 
from that model, but is there a simpler way to estimate theta for the glm 
model?  The two models are: 

mod.nb-glm.nb(mantas~site,data=mydata)
mod.glm-glm(mantas~site,data=mydata, family=negative.binomial(mod.nb$theta)) 

How else can I get theta for the family=negative.binomial(theta=???) 

Thanks!

Tim



Tim Clark
Department of Zoology 
University of Hawaii

__
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] Periodic regression - lunar percent cover

2010-04-29 Thread Tim Clark
Dear List,

I am trying include a lunar variable in a model and am having problems figuring 
out the correct way to include it.  I want to convert the percent lunar 
illumination (fraction of moon showing) to a combination of sin and cos 
variables to account for the periodic nature of the lunar cycle.  Would someone 
let me know if I am doing this correctly?  I have included the first 20 
variables from my dataset as an example.  Y is count data and lp is the lunar 
percent cover.  The lunar period is 29.53.

y-c(1, 3, 0, 0, 0, 0, 2, 4, 0, 1, 0, 5, 3, 2, 4, 2, 0, 1, 3, 5)
lp-c(0.80, 0.88, 0.62, 0.19, 0.21, 0.01, 0.70, 1.00, 0.88, 0.04, 0.70, 0.93, 
0.23, 0.99, 0.19, 0.79, 1.00, 0.03, 0.01, 0.00)
g1-glm(y~cos((2*pi*lp)/29.530589)+sin((2*pi*lp)/29.530589))

Thanks,

Tim




Tim Clark
Department of Zoology 
University of Hawaii

__
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] Best subset of models for glm.nb()

2010-04-20 Thread Tim Clark
Dear List,

I am looking for a function that will find the best subset of negative binomial 
models.  I have a large data set with 15 variables that I am interested in.  I 
want an easy way to run all possible models and find a subset of the best 
models that I can then look at in more detail.  I have found two functions that 
seem to provide what I am looking for, but am not sure which one (if either) 
are appropriate.

glmulti() in package glmulti does an exhaustive search of all models and gives 
a number of candidate models to choose from based on your choice of Information 
Criterion.  This seems to be exactly what I am after, but I found nothing about 
it on this list which makes me think there is some reason no one is using it.

gl1ce() in package lasso2 uses the least absolute shrinkage and selection 
operator (lasso) to do something.  I found it at another thread:
http://tolstoy.newcastle.edu.au/R/help/05/03/0121.html
I did not understand the paper it was based on, and want to know if it even 
does what I am interested in before investing a lot of time in trying to 
understand it.

Yes, I have read about the problems with stepwise algorithms and am looking for 
a valid alternative to narrowing down models when you have a lot of data and a 
large number of variables your interested in.  

Any thoughts on either of these methods?  Or should I be doing something else?

Thanks for your help,

Tim


Tim Clark
Department of Zoology 
University of Hawaii

__
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] r help date format changes with c() vs. rbind()

2010-02-19 Thread Tim Clark
Dear List,

I am having a problem with dates and I would like to understand what is going 
on.  Below is an example.  I can produce a date/time using as.POSIXct, but I am 
trying to combine two as.POSIXct objects and keep getting strange results.  I 
thought I was using the wrong origin, but according to 
structure(0,class=Date) I am not (see below).  In my example a is a simple 
date/time object, b combines it using rbind(), c converts b to a date/time 
object again using as.POSIXct and gives the incorrect time, and d combines a 
using c() and gives the correct time.  Why doesn't c give me the correct answer?

Thanks,

Tim


 a-as.POSIXct(2000-01-01 12:00:00)
 a
[1] 2000-01-01 12:00:00 HST

 b-rbind(a,a)
 b
   [,1]
a 946764000
a 946764000

 c-as.POSIXct(b,origin=1970-01-01)
 c
[1] 2000-01-01 22:00:00 HST
[2] 2000-01-01 22:00:00 HST

 d-c(a,a)
 d
[1] 2000-01-01 12:00:00 HST
[2] 2000-01-01 12:00:00 HST


 structure(0,class=Date)
[1] 1970-01-01


Tim Clark
Department of Zoology 
University of Hawaii

__
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] r help date format changes with c() vs. rbind()

2010-02-19 Thread Tim Clark
Glad to know it isn't just me!  I couldn't use Phil's data.frame method since 
my real problem went from a POSIXct object to a large matrix where I used rbind 
and then back to POSIXct.  Jim's function worked great on converting the final 
product back to the proper date.

Thanks!

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 2/19/10, jim holtman jholt...@gmail.com wrote:

 From: jim holtman jholt...@gmail.com
 Subject: Re: [R] r help date format changes with c() vs. rbind()
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Friday, February 19, 2010, 12:19 PM
 I have used the following function to
 convert to POSIXct from a numeric without any
 problems:
  
  unix2POSIXct - function (time)  
 structure(time, class = c(POSIXt,
 POSIXct))
  
  unix2POSIXct(946764000)
 [1] 2000-01-01 17:00:00 EST
  
 
 
 
 
 On Fri, Feb 19, 2010 at 4:07 PM,
 Tim Clark mudiver1...@yahoo.com
 wrote:
 
 Dear
 List,
 
 I am having a problem with dates and I would like to
 understand what is going on.  Below is an example.  I can
 produce a date/time using as.POSIXct, but I am trying to
 combine two as.POSIXct objects and keep getting strange
 results.  I thought I was using the wrong origin, but
 according to structure(0,class=Date) I am not
 (see below).  In my example a is a simple date/time object,
 b combines it using rbind(), c converts b to a date/time
 object again using as.POSIXct and gives the incorrect time,
 and d combines a using c() and gives the correct time.  Why
 doesn't c give me the correct answer?
 
 
 Thanks,
 
 Tim
 
 
  a-as.POSIXct(2000-01-01 12:00:00)
  a
 [1] 2000-01-01 12:00:00 HST
 
  b-rbind(a,a)
  b
       [,1]
 a 946764000
 a 946764000
 
 
  c-as.POSIXct(b,origin=1970-01-01)
  c
 [1] 2000-01-01 22:00:00 HST
 [2] 2000-01-01 22:00:00 HST
 
  d-c(a,a)
  d
 [1] 2000-01-01 12:00:00 HST
 
 [2] 2000-01-01 12:00:00 HST
 
 
  structure(0,class=Date)
 [1] 1970-01-01
 
 
 Tim Clark
 Department of Zoology
 University of Hawaii
 
 __
 
 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.
 
 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 
 




__
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] Formatting question for separate polygons

2010-02-12 Thread Tim Clark
Thanks Uwe!  And Peter for the correction.  I would never have come up with 
that!

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 2/12/10, Uwe Ligges lig...@statistik.tu-dortmund.de wrote:

 From: Uwe Ligges lig...@statistik.tu-dortmund.de
 Subject: Re: [R] Formatting question for separate polygons
 To: Peter Ehlers ehl...@ucalgary.ca
 Cc: Tim Clark mudiver1...@yahoo.com, r-help@r-project.org
 Date: Friday, February 12, 2010, 1:57 AM
 
 
 On 12.02.2010 12:54, Peter Ehlers wrote:
  Nice, Uwe.
  Small correction: make that nrow=4:
 
  x1 - as.numeric(rbind(matrix(rep(x, each=2),
 nrow=4), NA))
 
 
 
 Whoops, thanks!
 
 Uwe
 
 
  -Peter Ehlers
 
  Uwe Ligges wrote:
 
 
  On 11.02.2010 22:38, Tim Clark wrote:
  Dear List,
 
  I am trying to plot several separate polygons
 on a graph. I have
  figured out how to do it by manually, but have
 too much data to use
  such a tedious method. I would appreciate your
 help. I have made a
  simple example to illustrate the problem. How
 can I get x into the
  proper format (x1)?
 
  #Sample data
  x-c(1,2,3,4,5,6)
  y-c(1,2,2,1)
 
  #I need to format the data like this
  x1-c(1,1,2,2,NA,3,3,4,4,NA,5,5,6,6,NA)
  y1-rep(c(1,2,2,1,NA),length(x)/2)
 
 
 
  x1 - as.numeric(rbind(matrix(rep(x, each=2),
 nrow=2), NA))
 
  Uwe Ligges
 
 
  #Final plot
  plot(c(1,6), 1:2, type=n)
  polygon(x1,y1,density=c(40))
 
 
  Thanks,
 
  Tim
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
 
 __
  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-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-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] Find each time a value changes

2010-02-11 Thread Tim Clark
It was brought to my attention that the rle() answer to this question was not 
posted.  The following gives the correct answer once the last value is deleted.

x-seq(1:100)
y1-rep(1,10)
y2-rep(2,10)
y-c(y1,y2,y1,y1,y1,y2,y1,y2,y1,y2)
xy-cbind(x,y)

print(xy)
print(str(xy))

# SEE WHAT RLE GIVES
test - rle(xy[,2])
print(str(test)
  
# USE JIMS TRICK OF CUMULATIVE SUMMING
# TO GET THE LOCATIONS  
result - cumsum(c(1,rle(xy[,2])$lengths))



Tim Clark
Department of Zoology 
University of Hawaii


--- On Wed, 2/10/10, Ben Tupper ben.bigh...@gmail.com wrote:

 From: Ben Tupper ben.bigh...@gmail.com
 Subject: Re: [R] Find each time a value changes
 To: r-help@r-project.org
 Cc: Tim Clark mudiver1...@yahoo.com
 Date: Wednesday, February 10, 2010, 4:16 PM
 Hi,
 
 On Feb 10, 2010, at 8:58 PM, Tim Clark wrote:
 
  Dear List,
 
  I am trying to find each time a value changes in a
 dataset.  The  
  numbers are variables for day vs. night values, so
 what I am really  
  getting is the daily sunrise and sunset.
 
  A simplified example is the following:
 
  x-seq(1:100)
  y1-rep(1,10)
  y2-rep(2,10)
  y-c(y1,y2,y1,y1,y1,y2,y1,y2,y1,y2)
  xy-cbind(x,y)
 
 
  I would like to know each time the numbers change.
  Correct answer should be:
  x=1,11,21,51,61,71,81,91
 
 
 I think this gets close...
 
 which(diff(y) != 0)
 [1] 10 20 50 60 70 80 90
 
 You'll need to fiddle to get exactly what you want.
 
 Cheers,
 Ben
 
 
 
  I would appreciate any help or suggestions.  It
 seems like it should  
  be simple but I’m stuck!
 
  Thanks,
 
  Tim
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
 
 
 
  __
  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-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] Formatting question for separate polygons

2010-02-11 Thread Tim Clark
Dear List,

I am trying to plot several separate polygons on a graph.  I have figured out 
how to do it by manually, but have too much data to use such a tedious method.  
I would appreciate your help.  I have made a simple example to illustrate the 
problem.  How can I get x into the proper format (x1)?

#Sample data
x-c(1,2,3,4,5,6)
y-c(1,2,2,1)

#I need to format the data like this
x1-c(1,1,2,2,NA,3,3,4,4,NA,5,5,6,6,NA)
y1-rep(c(1,2,2,1,NA),length(x)/2)

#Final plot
plot(c(1,6), 1:2, type=n)
polygon(x1,y1,density=c(40))


Thanks,

Tim

 
Tim Clark
Department of Zoology 
University of Hawaii

__
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] Find each time a value changes

2010-02-10 Thread Tim Clark
Dear List,

I am trying to find each time a value changes in a dataset.  The numbers are 
variables for day vs. night values, so what I am really getting is the daily 
sunrise and sunset.  

A simplified example is the following:
  
x-seq(1:100)
y1-rep(1,10)
y2-rep(2,10)
y-c(y1,y2,y1,y1,y1,y2,y1,y2,y1,y2)
xy-cbind(x,y)


I would like to know each time the numbers change.
Correct answer should be:
x=1,11,21,51,61,71,81,91

I would appreciate any help or suggestions.  It seems like it should be simple 
but I’m stuck!

Thanks,

Tim


Tim Clark
Department of Zoology 
University of Hawaii




__
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] Find each time a value changes

2010-02-10 Thread Tim Clark
Thanks everyone!  I would have been banging my head around for quite a while 
and still wouldn't have come up with either solution.  The function rle() is a 
good one to know!

Aloha,

Tim



Tim Clark
Department of Zoology 
University of Hawaii


--- On Wed, 2/10/10, Ben Tupper ben.bigh...@gmail.com wrote:

 From: Ben Tupper ben.bigh...@gmail.com
 Subject: Re: [R] Find each time a value changes
 To: r-help@r-project.org
 Cc: Tim Clark mudiver1...@yahoo.com
 Date: Wednesday, February 10, 2010, 4:16 PM
 Hi,
 
 On Feb 10, 2010, at 8:58 PM, Tim Clark wrote:
 
  Dear List,
 
  I am trying to find each time a value changes in a
 dataset.  The  
  numbers are variables for day vs. night values, so
 what I am really  
  getting is the daily sunrise and sunset.
 
  A simplified example is the following:
 
  x-seq(1:100)
  y1-rep(1,10)
  y2-rep(2,10)
  y-c(y1,y2,y1,y1,y1,y2,y1,y2,y1,y2)
  xy-cbind(x,y)
 
 
  I would like to know each time the numbers change.
  Correct answer should be:
  x=1,11,21,51,61,71,81,91
 
 
 I think this gets close...
 
 which(diff(y) != 0)
 [1] 10 20 50 60 70 80 90
 
 You'll need to fiddle to get exactly what you want.
 
 Cheers,
 Ben
 
 
 
  I would appreciate any help or suggestions.  It
 seems like it should  
  be simple but I’m stuck!
 
  Thanks,
 
  Tim
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
 
 
 
  __
  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-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] Plotting color.legend() outside of plot region

2009-11-30 Thread Tim Clark
Dear List,

I am trying to plot a color.legend() in the right outer margin of my device 
region.  I have read multiple threads on the subject and still can't get it 
right.  I have stolen an example from one of the threads to demonstrate my 
problem.  I have extended the outer margin using par(oma()), and have used 
par(xpd=NA) to tell it to plot in the device region.  I can get the legend to 
plot in the figure region but it will not plot in the outer margin.  What am I 
doing wrong?  Example follows with the legend in the figure region.  I would 
like it more to the right in the device region. 

Thank,

Tim

library(TeachingDemos)
op - par(mfrow = c(3,3), ## split region
  oma = c(0,0,4,12) + 0.1, ## create outer margin
  mar = c(5,4,2,2) + 0.1) ## shrink some margins
plot(1:10, main = a, pch = 1:2, col= 1:2)
plot(1:10, main = b, pch = 1:2, col= 1:2)
tmp1 - cnvrt.coords( 0.5, 0, input='plt' )$tdev # save location for mtext
plot(1:10, main = c, pch = 1:2, col= 1:2)
plot(1:10, main = d, pch = 1:2, col= 1:2)
plot(1:10, main = e, pch = 1:2, col= 1:2)
plot(1:10, main = f, pch = 1:2, col= 1:2)
plot(1:10, main = g, pch = 1:2, col= 1:2)
plot(1:10, main = h, pch = 1:2, col= 1:2)
plot(1:10, main = i, pch = 1:2, col= 1:2)
## title
mtext(My Plots, side = 3, outer = TRUE, font = 2, line = 1, cex = 
1.2,at=tmp1$x)


## draw legend
#Set colors
  Satelite.Palette - 
colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red))
  mycol-Satelite.Palette(101)
  
#Add legend
  BL-unlist(corner.label(x=-1,y=-1,figcorner=FALSE))#Coordinates for 
bottom left corner of plot
  TR-unlist(corner.label(x=1,y=1,figcorner=FALSE))  #Coordinates for top 
right corner of plot

  par(xpd=NA) #Plots to the device region (outer margin)
  library(plotrix)
  col.labels-seq(0,100,20)
  
color.legend(TR[1],BL[2],TR[1]+1,TR[2],col.labels,mycol,align=rb,gradient=y)

#Reset par
  par(op)





Tim Clark
Department of Zoology 
University of Hawaii

__
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] Plotting color.legend() outside of plot region

2009-11-30 Thread Tim Clark
Peter,

Thanks, layout() does exactly what I want.  Now I also realize why I wasn't 
able to get the legend where I wanted it.  I didn't realize par(xpd=...) was 
only for the last plot.  That explains why I was getting weird results when 
trying to move my legend around!

Aloha,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Mon, 11/30/09, Peter Ehlers ehl...@ucalgary.ca wrote:

 From: Peter Ehlers ehl...@ucalgary.ca
 Subject: Re: [R] Plotting color.legend() outside of plot region
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Monday, November 30, 2009, 12:28 PM
 
 Tim Clark wrote:
  Dear List,
  
  I am trying to plot a color.legend() in the right
 outer margin of my device region.  I have read multiple
 threads on the subject and still can't get it right.  I
 have stolen an example from one of the threads to
 demonstrate my problem.  I have extended the outer
 margin using par(oma()), and have used par(xpd=NA) to tell
 it to plot in the device region.  I can get the legend
 to plot in the figure region but it will not plot in the
 outer margin.  What am I doing wrong?  Example
 follows with the legend in the figure region.  I would
 like it more to the right in the device region. 
  Thank,
  
  Tim
  
  library(TeachingDemos)
  op - par(mfrow = c(3,3), ## split region
            oma =
 c(0,0,4,12) + 0.1, ## create outer margin
            mar =
 c(5,4,2,2) + 0.1) ## shrink some margins
  plot(1:10, main = a, pch = 1:2, col= 1:2)
  plot(1:10, main = b, pch = 1:2, col= 1:2)
  tmp1 - cnvrt.coords( 0.5, 0, input='plt' )$tdev #
 save location for mtext
  plot(1:10, main = c, pch = 1:2, col= 1:2)
  plot(1:10, main = d, pch = 1:2, col= 1:2)
  plot(1:10, main = e, pch = 1:2, col= 1:2)
  plot(1:10, main = f, pch = 1:2, col= 1:2)
  plot(1:10, main = g, pch = 1:2, col= 1:2)
  plot(1:10, main = h, pch = 1:2, col= 1:2)
  plot(1:10, main = i, pch = 1:2, col= 1:2)
  ## title
  mtext(My Plots, side = 3, outer = TRUE, font = 2,
 line = 1, cex = 1.2,at=tmp1$x)
  
  
  ## draw legend
  #Set colors
    Satelite.Palette -
 colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red))
    mycol-Satelite.Palette(101)
    #Add legend
    BL-unlist(corner.label(x=-1,y=-1,figcorner=FALSE)) 
   #Coordinates for bottom left corner of plot
    TR-unlist(corner.label(x=1,y=1,figcorner=FALSE)) 
     #Coordinates for top right corner of plot
  
    par(xpd=NA) #Plots to the device
 region (outer margin)
    library(plotrix)
    col.labels-seq(0,100,20)
    color.legend(TR[1],BL[2],TR[1]+1,TR[2],col.labels,mycol,align=rb,gradient=y)
  
  #Reset par
    par(op)
  
 The par(xpd=...) only applies to the last plot. I can't
 think offhand how to avoid that. I would use Paul
 Murrell's
 handy layout() function. Something like this (you'll have
 to adjust margins, etc)
 
 m - matrix(c(1:9,10,10,10), 3, 4)
 nf - layout(m)
 layout.show(nf)
 
 plot(1:10, main = a, pch = 1:2, col= 1:2)
 plot(1:10, main = b, pch = 1:2, col= 1:2)
 plot(1:10, main = c, pch = 1:2, col= 1:2)
 plot(1:10, main = d, pch = 1:2, col= 1:2)
 plot(1:10, main = e, pch = 1:2, col= 1:2)
 plot(1:10, main = f, pch = 1:2, col= 1:2)
 plot(1:10, main = g, pch = 1:2, col= 1:2)
 plot(1:10, main = h, pch = 1:2, col= 1:2)
 plot(1:10, main = i, pch = 1:2, col= 1:2)
 
 plot(0:1, 0:1, type=n, axes=F, xlab=, ylab=)
 color.legend(.2,.2,.8,.8, col.labels, mycol, align=rb,
 gradient=y)
 
 See ?layout
 
  -Peter Ehlers
 
  
  
  
  
  Tim Clark
  Department of Zoology University of Hawaii
  
  __
  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-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] Removing objects from a list based on nrow

2009-11-29 Thread Tim Clark
Dear List,

I have a list containing data frames of various numbers of rows.  I need to 
remove any data frame that has less than 3 rows.  For example:

df1-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
df2-data.frame(letter=c(A,B),number=c(1,2))
df3-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
df4-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))

lst-list(df1,df2,df3,df4)

How can I determine that the second object (df2) has less than 3 rows and 
remove it from the list?

Thanks!

Tim




Tim Clark
Department of Zoology 
University of Hawaii

__
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] Removing objects from a list based on nrow

2009-11-29 Thread Tim Clark
Linlin,

Thanks!  That works great!

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Sat, 11/28/09, Linlin Yan yanlinli...@gmail.com wrote:

 From: Linlin Yan yanlinli...@gmail.com
 Subject: Re: [R] Removing objects from a list based on nrow
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Saturday, November 28, 2009, 10:43 PM
 Try these:
 sapply(lst, nrow) # get row numbers
 which(sapply(lst, nrow)  3) # get the index of rows
 which has less than 3 rows
 lst - lst[-which(sapply(lst, nrow)  3)] # remove
 the rows from the list
 
 On Sun, Nov 29, 2009 at 4:36 PM, Tim Clark mudiver1...@yahoo.com
 wrote:
  Dear List,
 
  I have a list containing data frames of various
 numbers of rows.  I need to remove any data frame that has
 less than 3 rows.  For example:
 
 
 df1-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
  df2-data.frame(letter=c(A,B),number=c(1,2))
 
 df3-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 
 df4-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 
  lst-list(df1,df2,df3,df4)
 
  How can I determine that the second object (df2) has
 less than 3 rows and remove it from the list?
 
  Thanks!
 
  Tim
 
 
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
  __
  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-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] Removing objects from a list based on nrow

2009-11-29 Thread Tim Clark
Jim,

Good catch!  I know in my current problem there are objects with less than 3 
rows, but will make sure to modify the function for future use.

Thanks,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Sun, 11/29/09, Linlin Yan yanlinli...@gmail.com wrote:

 From: Linlin Yan yanlinli...@gmail.com
 Subject: Re: [R] Removing objects from a list based on nrow
 To: jim holtman jholt...@gmail.com
 Cc: Tim Clark mudiver1...@yahoo.com, r-help@r-project.org
 Date: Sunday, November 29, 2009, 4:35 AM
 Thank Jim! You are right. I didn't
 notice the case of none of rows
 match the condition.
 
 On Sun, Nov 29, 2009 at 10:10 PM, jim holtman jholt...@gmail.com
 wrote:
  One thing to be careful of is if no dataframe have
 less than 3 rows:
 
 
 df1-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 
 df2-data.frame(letter=c(A,B),number=c(1,2))
 
 df3-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 
 df4-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 
  lst-list(df1,df3,df4)
  lst
  [[1]]
   letter number
  1      A      1
  2      B      2
  3      C      3
  4      D      4
  5      E      5
 
  [[2]]
   letter number
  1      A      1
  2      B      2
  3      C      3
  4      D      4
  5      E      5
 
  [[3]]
   letter number
  1      A      1
  2      B      2
  3      C      3
  4      D      4
  5      E      5
 
  lst[-which(sapply(lst, nrow)  3)]
  list()
 
 
  Notice the list is now empty.  Instead use:
 
  lst[sapply(lst, nrow) =3]
  [[1]]
   letter number
  1      A      1
  2      B      2
  3      C      3
  4      D      4
  5      E      5
 
  [[2]]
   letter number
  1      A      1
  2      B      2
  3      C      3
  4      D      4
  5      E      5
 
  [[3]]
   letter number
  1      A      1
  2      B      2
  3      C      3
  4      D      4
  5      E      5
 
 
  On Sun, Nov 29, 2009 at 3:43 AM, Linlin Yan yanlinli...@gmail.com
 wrote:
  Try these:
  sapply(lst, nrow) # get row numbers
  which(sapply(lst, nrow)  3) # get the index of
 rows which has less than 3 rows
  lst - lst[-which(sapply(lst, nrow)  3)] #
 remove the rows from the list
 
  On Sun, Nov 29, 2009 at 4:36 PM, Tim Clark mudiver1...@yahoo.com
 wrote:
  Dear List,
 
  I have a list containing data frames of
 various numbers of rows.  I need to remove any data frame
 that has less than 3 rows.  For example:
 
 
 df1-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 
 df2-data.frame(letter=c(A,B),number=c(1,2))
 
 df3-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 
 df4-data.frame(letter=c(A,B,C,D,E),number=c(1,2,3,4,5))
 
  lst-list(df1,df2,df3,df4)
 
  How can I determine that the second object
 (df2) has less than 3 rows and remove it from the list?
 
  Thanks!
 
  Tim
 
 
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
 
 __
  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-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.
 
 
 
 
  --
  Jim Holtman
  Cincinnati, OH
  +1 513 646 9390
 
  What is the problem that you are trying to solve?
 
 




__
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] Continuous legend colors

2009-11-29 Thread Tim Clark
Dear List,

I am trying to get a basic plot to show a continuous range of fill colors.  It 
is probably easiest to demonstrate.  I would like a legend like in the 
following example:

Satellite.Palette 
-colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red))
require(fields)
image.plot(volcano, col = Satellite.Palette (500), legend.lab=Scale)
contour(volcano, levels = seq(90, 200, by = 5), add = TRUE)


However, I am using the basic plot function.  So far I have figured out how to 
remove any space between the colors using the y.intersp call in legend().  Now 
I need to somehow plot the legend so that it 1) fits on the plotting region, 2) 
has fewer labels, and 3) doesn't have black lines between each color.  The 
example I am trying to get to work is:

Sat.Pal-Satellite.Palette (101)
x-rnorm(100, mean = 50, sd = 50)
y-rnorm(100, mean = 50, sd = 50)
z-seq(1,100, by=1)
plot(x,y,pch=16,col=Sat.Pal[z])

legend(topleft,
legend=seq(0,100, by=1),
fill=Sat.Pal[seq(1,101, by=1)],
bty=n,
y.intersp=.5)


I would appreciate any help or suggestions on how to get this to produce a 
legend with continuous colors.

Thanks,

Tim





Tim Clark
Department of Zoology 
University of Hawaii

__
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] Continuous legend colors

2009-11-29 Thread Tim Clark
Thanks Jim, that is exactly what I was looking for!

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Sun, 11/29/09, Jim Lemon j...@bitwrit.com.au wrote:

 From: Jim Lemon j...@bitwrit.com.au
 Subject: Re: [R] Continuous legend colors
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Sunday, November 29, 2009, 8:13 PM
 On 11/30/2009 03:22 PM, Tim Clark
 wrote:
  Dear List,
 
  I am trying to get a basic plot to show a continuous
 range of fill colors.  It is probably easiest to
 demonstrate.  I would like a legend like in the
 following example:
 
 
 Satellite.Palette-colorRampPalette(c(blue3,cyan,aquamarine,yellow,orange,red))
  require(fields)
  image.plot(volcano, col = Satellite.Palette (500),
 legend.lab=Scale)
  contour(volcano, levels = seq(90, 200, by = 5), add =
 TRUE)
 
 
  However, I am using the basic plot function.  So
 far I have figured out how to remove any space between the
 colors using the y.intersp call in legend().  Now I
 need to somehow plot the legend so that it 1) fits on the
 plotting region, 2) has fewer labels, and 3) doesn't have
 black lines between each color.  The example I am
 trying to get to work is:
 
  Sat.Pal-Satellite.Palette (101)
  x-rnorm(100, mean = 50, sd = 50)
  y-rnorm(100, mean = 50, sd = 50)
  z-seq(1,100, by=1)
  plot(x,y,pch=16,col=Sat.Pal[z])
 
  legend(topleft,
  legend=seq(0,100, by=1),
  fill=Sat.Pal[seq(1,101, by=1)],
  bty=n,
  y.intersp=.5)
 
 
  I would appreciate any help or suggestions on how to
 get this to produce a legend with continuous colors.
 
     
 Hi Tim,
 Have a look at the color.legend function in the plotrix
 package.
 
 Jim
 
 




__
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] Adding columns to lower level of list

2009-11-21 Thread Tim Clark
Dear List,


I have very little experience with lists and am having some very basic 
problems.  I don't know how to add columns to the lower levels of a list, or 
how to take something from the upper level and add it as a column to the lower 
level.  I am analyzing animal movement data in the package Adehabitat.  I have 
a list of animal movements called cut.ltr (class ltraj) that have been 
divided into a series of burst - i.e. movements with no gaps in time over a 
given threashold.  I would like to 

1.  Add the speed to each item in the list, and also the burst.  I can 
calculate speed as:

sp-lapply(cut.ltr,function(l){l$dist/l$dt})  

This creates a list of the correct size.  But I don't know how to add this to 
my original list.  I.e. add a column to the lower levels of the list called 
speed.

2.  Add the burst to each lower level of the list.  It is in the upper level, 
but I don't know how to access it.
I have tried attribute(), attr(), cut.ltr$burst, and several other creative 
guesses.

The first five items in the upper level are below - cut.ltr[1:5], along with 
head(cut.ltr[[1]]).  I would like my final result to have two more columns in 
cut.ltr[[1]].  One with speed, and the second with burst.

Thanks in advance for your help.

Tim





 cut.ltr[1:5]

*** List of class ltraj ***

Type of the traject: Type II (time recorded)
Irregular traject. Variable time lag between two locs

Characteristics of the bursts:
   id burst nb.reloc NAs  date.begindate.end
1 Abigail Abigail.1   47   0 2003-05-31 13:29:59 2003-06-01 00:59:56
2 Abigail Abigail.2  288   0 2003-06-18 17:28:11 2003-06-21 17:14:59
3 Abigail Abigail.3   10   0 2003-08-03 23:33:00 2003-08-04 01:43:58
4 Abigail Abigail.4   43   0 2003-08-04 08:15:25 2003-08-04 18:59:58
5 Abigail Abigail.5   78   0 2003-08-05 00:44:19 2003-08-05 20:15:00

 head(cut.ltr[[1]])
 x   ydate dx   dy dist  dt   
R2n abs.angle   rel.angle
1 809189.8 2189722 2003-05-31 13:29:59   81.87136 315.3389 325.7937 901   
0.0  1.316775  NA
2 809271.6 2190037 2003-05-31 13:45:00   13.00097 258.7351 259.0616 901  
106141.5  1.520590  0.20381526
3 809284.6 2190296 2003-05-31 14:00:01  250.52656 669.2065 714.5634 898  
338561.8  1.212584 -0.30800666
4 809535.2 2190965 2003-05-31 14:14:59 -171.14372 791.1522 809.4516 902 
1665046.9  1.783836  0.57125215
5 809364.0 2191756 2003-05-31 14:30:01  302.26979 707.0157 768.9202 900 
4169281.4  1.166785 -0.61705039
6 809666.3 2192463 2003-05-31 14:45:01  284.40962 725.2169 778.9919 900 
7742615.6  1.197057  0.03027109
 



Tim Clark
Department of Zoology 
University of Hawaii

__
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] Bezier interpolation

2009-10-29 Thread Tim Clark
Dear List,

I am trying to interpolate animal tracking data using Bezier curves.  I need a 
function similar to spline() or approx() but that has a method Bezier.  I have 
tried xspline() but it does not allow you to set the number of points to 
interpolate between a given interval (n points between min(x) and max(x)).  
Mark Hindell asked the same question in 2006 
(http://tolstoy.newcastle.edu.au/R/e2/help/06/12/7034.html).  I contacted him 
and he never found a workable function.  Has one been developed since then?  

Thanks,

Tim
 
Tim Clark
Department of Zoology 
University of Hawaii

__
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] Satellite ocean color palette?

2009-10-09 Thread Tim Clark
Dear List,

Is there a color palette avaliable similar to what is used in satellite ocean 
color imagery?  I.e. a gradient with blue on one end and red on the other, with 
yellow in the middle?  I have tried topo.colors(n) but that comes out more 
yellow on the end.  I am looking for something similar to what is found on the 
CoastWatch web page:

http://oceanwatch.pifsc.noaa.gov/imagery/GA2009281_2009282_sst_2D_eddy.jpg

Thanks!

Tim


Tim Clark
Department of Zoology 
University of Hawaii

__
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] Satellite ocean color palette?

2009-10-09 Thread Tim Clark
Thanks!  The colorRampPalette() did just what I need.

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 10/9/09, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote:

 From: Barry Rowlingson b.rowling...@lancaster.ac.uk
 Subject: Re: [R] Satellite ocean color palette?
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Friday, October 9, 2009, 9:06 AM
 On Fri, Oct 9, 2009 at 7:51 PM, Tim
 Clark mudiver1...@yahoo.com
 wrote:
  Dear List,
 
  Is there a color palette avaliable similar to what is
 used in satellite ocean color imagery?  I.e. a gradient
 with blue on one end and red on the other, with yellow in
 the middle?  I have tried topo.colors(n) but that comes out
 more yellow on the end.  I am looking for something similar
 to what is found on the CoastWatch web page:
 
  http://oceanwatch.pifsc.noaa.gov/imagery/GA2009281_2009282_sst_2D_eddy.jpg
 
  Thanks!
 
  You could build one yourself with the colorRamp function:
 
 satRampP =
 colorRampPalette(c(black,blue,cyan,yellow,orange,red,black))
 
  that looks roughly like the one in the jpg, but I'm not
 sure about
 the black at the far end...anyway, let's see:
 
 image(matrix(seq(0,1,len=100),100,1),col=satRampP(100))
 
 Or you could try my colour schemes package:
 
 https://r-forge.r-project.org/projects/colourscheme/
 
 Barry
 




__
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] Paste a character to an object

2009-10-04 Thread Tim Clark
David,

Thanks!  You just gave me the answer.  All I had to do was:

xx-c()
for (i in c('100', '75', '50') )
{
x-homerange[[1]]$polygons[[i]] ; xx-rbind(x,xx)
}
 xx

I didn't know you could use characters as index values in a for loop, or that 
you could use characters in double brackets instead of using the $ symbol.

homerange[[1]]$polygons[['100']]
is the same as
homerange[[1]]$polygons$'100

The list is actually the output of the NNCH function in Adehabitat.  I thought 
about changing the function first, but looked at the code and couldn't figure 
it out.  I knew there had to be an easier way.

I greatly appreciate all your help,

Tim

Tim Clark
Department of Zoology 
University of Hawaii


--- On Sat, 10/3/09, David Winsemius dwinsem...@comcast.net wrote:

 From: David Winsemius dwinsem...@comcast.net
 Subject: Re: [R] Paste a character to an object
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Saturday, October 3, 2009, 5:43 PM
 
 On Oct 3, 2009, at 11:14 PM, Tim Clark wrote:
 
  David,
  
  Thanks, that helps me in making an example of what I
 am trying to do.  Given the following example, I would
 like to run through a for loop and obtain a vector of the
 data only for the 100, 75, and 50 percent values.  Is
 there a way to get this to work, either using paste as in
 the example below or some other method?
  
  homerange - list()
  homerange[[1]] - test
  homerange[[1]]$polygons - test2
  homerange[[1]]$polygons$`100` - rnorm(20,10,1)
  homerange[[1]]$polygons$`90` - rnorm(20,10,1)
  homerange[[1]]$polygons$`75` - rnorm(20,10,1)
  homerange[[1]]$polygons$`50` - rnorm(20,10,1)
  
  xx-c()
  percent-c(100,75,50)
  for (i in 1:length(percent))
  {
  x-paste(homerange[[1]]$polygons$   
 ,    percent[i]) #This does not work!!!
                
                
   ^?^
 And why _would_ you expect an expression ending in a $ to
 be acceptable to the parser? You did not put quotes around
 it so the interpreter tried to evaluate it.
 
 You are probably looking for the capabilities of the
 functions get and assign which take string variable and
 either get the object named by a sstring or assign a vlaue
 to an object so named.
 
 But why are you intent in causing yourself all this
 pain?  (Not to mention asking questions I cannot
 answer.)  Working with expressions involving backquotes
 is a recipe for hair-pulling and frustration for us normal
 mortals. Why not call your lists p100, p90, p75,
 p50? Then everything is simple:
 
  xx-c()
  percent-c(100, 75, 50)
  for (i in c(p100, p75, p50) )
 + {
 + x-homerange[[1]]$polygons[[i]] ;
 xx-rbind(x,xx)  # could have simplified this
 + }
  xx
        [,1] 
    [,2]     [,3] 
     [,4]     [,5]   
   [,6]      [,7]     
 [,8]     [,9]
 x  9.660935 10.46526 10.75813  8.866064
 9.967950  9.987941 10.757160 10.180826 9.992162
 x 11.674645 10.51753 10.88061 10.515120 9.440838 11.460845
 12.033612  9.318392 9.592026
 x 10.057021 10.14339 10.29757  9.164233 8.977280 
 9.733971  9.965002  9.693649 9.430043
      [,10] 
    [,11]     [,12] 
    [,13]     [,14] 
    [,15]     [,16] 
    [,17]    [,18]
 x 11.78904  9.437353 11.910747 10.996167
 11.631264  9.386944  9.602160 10.498921 
 9.09349
 x  9.11036  9.546378 11.030323 
 9.715164  9.500268 11.762440  9.101104 
 9.610251 10.56210
 x  9.62574 12.738020  9.146863 10.497626
 10.485520 11.644503 10.303581 11.340263 11.34873
       [,19]     [,20]
 x 10.146955  9.640136
 x  9.334912 10.101603
 x  8.710609 11.265633
 
 
 
 
  
  
  The x-paste(...) in this function does not work,
 and that is what I am stuck on.  The result should be a
 vector the values for the 100,75,and 50 levels, but
 not the 90 level.
  
  Aloha,
  
  Tim Clark
  Department of Zoology
  University of Hawaii
  
  
  --- On Sat, 10/3/09, David Winsemius dwinsem...@comcast.net
 wrote:
  
  From: David Winsemius dwinsem...@comcast.net
  Subject: Re: [R] Paste a character to an object
  To: Tim Clark mudiver1...@yahoo.com
  Cc: r-help@r-project.org
  Date: Saturday, October 3, 2009, 4:45 PM
  
  On Oct 3, 2009, at 10:26 PM, Tim Clark wrote:
  
  Dear List,
  
  I can't seem to get a simple paste function to
 work
  like I need.  I have an object I need to call
 but it
  ends in a character string.  The object is a
 list of
  home range values for a range of percent
 isopleths.  I
  need to loop through a vector of percent values,
 so I need
  to paste the percent as a character on the end of
 the object
  variable.  I have no idea why the percent is
 in
  character form, and I can't use a simple index
 value
  (homerange[[1]]$polygons[100]) because there are a
 variable
  number of isopleths that are calculated and [100]
 will not
  always correspond to 100.  So I am stuck.
  
  What I want is:
  
  homerange[[1]]$polygons$100
  
  What I need is something like the following,
 but that
  works:
  
  percent-c(100,75,50)
  p=1
 
 paste(homerange[[1]]$polygons$,percent[p],sep=)
  
  Not a reproducible example, but here is some code

[R] Paste a character to an object

2009-10-03 Thread Tim Clark
Dear List,

I can't seem to get a simple paste function to work like I need.  I have an 
object I need to call but it ends in a character string.  The object is a list 
of home range values for a range of percent isopleths.  I need to loop through 
a vector of percent values, so I need to paste the percent as a character on 
the end of the object variable.  I have no idea why the percent is in character 
form, and I can't use a simple index value (homerange[[1]]$polygons[100]) 
because there are a variable number of isopleths that are calculated and [100] 
will not always correspond to 100.  So I am stuck.

What I want is:

homerange[[1]]$polygons$100

What I need is something like the following, but that works:

percent-c(100,75,50)
p=1
paste(homerange[[1]]$polygons$,percent[p],sep=)

Thanks for the help,

Tim



Tim Clark
Department of Zoology 
University of Hawaii

__
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] Paste a character to an object

2009-10-03 Thread Tim Clark
David,

Thanks, that helps me in making an example of what I am trying to do.  Given 
the following example, I would like to run through a for loop and obtain a 
vector of the data only for the 100, 75, and 50 percent values.  Is there a way 
to get this to work, either using paste as in the example below or some other 
method?

homerange - list()
homerange[[1]] - test
homerange[[1]]$polygons - test2
homerange[[1]]$polygons$`100` - rnorm(20,10,1)
homerange[[1]]$polygons$`90` - rnorm(20,10,1)
homerange[[1]]$polygons$`75` - rnorm(20,10,1)
homerange[[1]]$polygons$`50` - rnorm(20,10,1)

xx-c()
percent-c(100,75,50)
for (i in 1:length(percent))
{
x-paste(homerange[[1]]$polygons$,percent[i]) #This does not work!!!
xx-rbind(x,xx)
}

The x-paste(...) in this function does not work, and that is what I am stuck 
on.  The result should be a vector the values for the 100,75,and 50 
levels, but not the 90 level.

Aloha,

Tim




Tim Clark
Department of Zoology 
University of Hawaii


--- On Sat, 10/3/09, David Winsemius dwinsem...@comcast.net wrote:

 From: David Winsemius dwinsem...@comcast.net
 Subject: Re: [R] Paste a character to an object
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Saturday, October 3, 2009, 4:45 PM
 
 On Oct 3, 2009, at 10:26 PM, Tim Clark wrote:
 
  Dear List,
  
  I can't seem to get a simple paste function to work
 like I need.  I have an object I need to call but it
 ends in a character string.  The object is a list of
 home range values for a range of percent isopleths.  I
 need to loop through a vector of percent values, so I need
 to paste the percent as a character on the end of the object
 variable.  I have no idea why the percent is in
 character form, and I can't use a simple index value
 (homerange[[1]]$polygons[100]) because there are a variable
 number of isopleths that are calculated and [100] will not
 always correspond to 100.  So I am stuck.
  
  What I want is:
  
  homerange[[1]]$polygons$100
  
  What I need is something like the following, but that
 works:
  
  percent-c(100,75,50)
  p=1
  paste(homerange[[1]]$polygons$,percent[p],sep=)
 
 Not a reproducible example, but here is some code that
 shows that it is possible to construct names that would
 otherwise be invalid due to having numerals as a first
 character by using back-quotes:
 
  percent-c(100,75,50)
  p=1
  paste(homerange[[1]]$polygons$,percent[p],sep=)
 Error: syntax error
  homerange - list()
  homerange[[1]] - test
  homerange[[1]]$polygons - test2
 Warning message:
 In homerange[[1]]$polygons - test2 : Coercing LHS to
 a list
  homerange
 [[1]]
 [[1]][[1]]
 [1] test
 
 [[1]]$polygons
 [1] test2
 
 
  homerange[[1]]$polygons$`100` - percent[1]
 Warning message:
 In homerange[[1]]$polygons$`100` - percent[1] :
 Coercing LHS to a list
  homerange[[1]]$polygons$`100`
 [1] 100
 
 --David Winsemius
 
 
  
  Thanks for the help,
  
  Tim
  
  
  
  Tim Clark
  Department of Zoology
  University of Hawaii
  
  __
  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-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] bwplot scales in alphabetical order

2009-09-30 Thread Tim Clark
Dear List,

I know this has been covered before, but I don't seem to be able to get it 
right.  I am constructing a boxplot in lattice and can't get the scales in the 
correct alphebetical order.  I have already read that this is due to the way 
factors are treated, and I have to redefine the levels of the factors.  
However, I have failed.  
As a simple example:

library(lattice)
id-rep(letters[1:9], each=20)
x-rep(seq(1:10),each=18)
y-rnorm(180,50,20)

#Reverse alphebetical order
  bwplot(y~x|id, horizontal=FALSE)

#alphebetical order reading right to left
  id-factor(id,levels = sort(id,decreasing = TRUE))
  bwplot(y~x|id, horizontal=FALSE)

It appears that bwplot plots scales from the bottom left to the top right. If 
so my factor levels would need to be levels=c(7,8,9,4,5,6,1,2,3). I tried that 
but can't seem to get the factor function to work.

#Did not work!
id-factor(id,levels=c(7,8,9,4,5,6,1,2,3),lables=letters[1:9])

Your help would be greatly appreciated.

Tim





Tim Clark
Department of Zoology 
University of Hawaii

__
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] bwplot scales in alphabetical order

2009-09-30 Thread Tim Clark
Peter,

Thanks, that did it!

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Wed, 9/30/09, Peter Ehlers ehl...@ucalgary.ca wrote:

 From: Peter Ehlers ehl...@ucalgary.ca
 Subject: Re: [R] bwplot scales in alphabetical order
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Wednesday, September 30, 2009, 2:43 AM
 Tim,
 
 Add the argument as.table=TRUE to your call:
 
   bwplot(y~x|id, horizontal=FALSE, as.table=TRUE)
 
 Peter Ehlers
 
 Tim Clark wrote:
  Dear List,
  
  I know this has been covered before, but I don't seem
 to be able to get it right.  I am constructing a
 boxplot in lattice and can't get the scales in the correct
 alphebetical order.  I have already read that this is
 due to the way factors are treated, and I have to redefine
 the levels of the factors.  However, I have
 failed.  As a simple example:
  
  library(lattice)
  id-rep(letters[1:9], each=20)
  x-rep(seq(1:10),each=18)
  y-rnorm(180,50,20)
  
  #Reverse alphebetical order
    bwplot(y~x|id, horizontal=FALSE)
  
  #alphebetical order reading right to left
    id-factor(id,levels =
 sort(id,decreasing = TRUE))
    bwplot(y~x|id, horizontal=FALSE)
  
  It appears that bwplot plots scales from the bottom
 left to the top right. If so my factor levels would need to
 be levels=c(7,8,9,4,5,6,1,2,3). I tried that but can't seem
 to get the factor function to work.
  
  #Did not work!
 
 id-factor(id,levels=c(7,8,9,4,5,6,1,2,3),lables=letters[1:9])
  
  Your help would be greatly appreciated.
  
  Tim
  
  
  
  
  
  Tim Clark
  Department of Zoology University of Hawaii
  
  __
  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-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] xyplot help - colors and break in plot

2009-09-29 Thread Tim Clark
Felix,

Thanks, that did the trick!  Lattice is a lot less intuitive than basic 
plotting!

Also, another person suggested using gap.plot from the plotrix package to put a 
break in the graph.  I am surprised Lattice doesn't have something similar 
since it seems like a common problem when you have data that groups in clusters 
separated by a large range.

Aloha,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Mon, 9/28/09, Felix Andrews fe...@nfrac.org wrote:

 From: Felix Andrews fe...@nfrac.org
 Subject: Re: [R] xyplot help - colors and break in plot
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Monday, September 28, 2009, 1:50 PM
 2009/9/29 Tim Clark mudiver1...@yahoo.com:
  Dear List,
 
  I am new to lattice plots, and am having problems with
 getting my plot to do what I want.  Specifically:
 
  1. I would like the legend to have the same symbols as
 the plot.  I tried simpleKey but can't seem to get it
 to work with autoKey.  Right now my plot has dots
 (pch=19) and my legend shows circles.
 
 Rather than the pch = 19 argument, use par.settings =
 simpleTheme(pch
 = 19, cex = .4)
 
 
  2.  I have nine groups but xyplot seems to only
 be using seven colors, so two groups have the same
 color.  How do I get a range of nine colors?
 
 Yes, in the default theme, there are seven colours: see
 trellis.par.get(superpose.symbol)
 
 You can change the set of colours yourself by modifying
 that list (via
 trellis.par.set).
 
 An easier option is to use one of the predefined
 ColorBrewer palettes,
 with custom.theme() from the latticeExtra package, or just
 simpleTheme(). See ?brewer.pal (RColorBrewer package)
 You will see there are a few qualitative color palettes
 with 9 or more
 colours: e.g.
 brewer.pal(9, Set1)
 brewer.pal(12, Set3)
 
 
  3.  I have one group who's y range is much
 greater than all the others.  I would like to split the
 plot somehow so that the bottom part shows ylim=c(0,200) and
 the top shows ylim=c(450,550).  Is this possible?
 
 Yes... in the absence of a reproducible example, maybe
 something like
 
  xyplot(Area.km2 ~ DataPoint | (Area.km2  200),
 m.dp.area,
          groups = Manta,
 scales = list(y = free))
 
 or
 
 AreaRange - shingle(Area.km2,
 rbind(c(0,200),c(450,550)))
 xyplot(Area.km2 ~ DataPoint | AreaRange, m.dp.area,
         groups = Manta, scales = list(y
 = free))
 
 
  What I have so far is:
 
   library(lattice)
   xyplot(m.dp.area$Area.km2 ~ m.dp.area$DataPoint,
 m.dp.area, groups = m.dp.area$Manta,
         main = Cummulative area of
 100% MCP,
         xlab = Data Point,
         ylab = MCP Area,
         ylim = c(0,150),
         scales = list(tck = c(1,
 0)), #Removes tics on top and r-axis
         pch=19,cex=.4,
         auto.key = list(title =
 Mantas, x = .05, y=.95, corner = c(0,1),border = TRUE))
 #Legend
 
 
  Thanks,
 
  Tim
 
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
  __
  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.
 
 
 
 -- 
 Felix Andrews / 安福立
 Postdoctoral Fellow
 Integrated Catchment Assessment and Management (iCAM)
 Centre
 Fenner School of Environment and Society [Bldg 48a]
 The Australian National University
 Canberra ACT 0200 Australia
 M: +61 410 400 963
 T: + 61 2 6125 1670
 E: felix.andr...@anu.edu.au
 CRICOS Provider No. 00120C
 -- 
 http://www.neurofractal.org/felix/
 




__
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] xyplot help - colors and break in plot

2009-09-28 Thread Tim Clark
Dear List,

I am new to lattice plots, and am having problems with getting my plot to do 
what I want.  Specifically:

1. I would like the legend to have the same symbols as the plot.  I tried 
simpleKey but can't seem to get it to work with autoKey.  Right now my plot has 
dots (pch=19) and my legend shows circles.

2.  I have nine groups but xyplot seems to only be using seven colors, so two 
groups have the same color.  How do I get a range of nine colors?

3.  I have one group who's y range is much greater than all the others.  I 
would like to split the plot somehow so that the bottom part shows 
ylim=c(0,200) and the top shows ylim=c(450,550).  Is this possible?

What I have so far is:

  library(lattice)
  xyplot(m.dp.area$Area.km2 ~ m.dp.area$DataPoint, m.dp.area, groups = 
m.dp.area$Manta,
main = Cummulative area of 100% MCP,
xlab = Data Point,
ylab = MCP Area,
ylim = c(0,150),
scales = list(tck = c(1, 0)), #Removes tics on top and r-axis
pch=19,cex=.4,
auto.key = list(title = Mantas, x = .05, y=.95, corner = 
c(0,1),border = TRUE)) #Legend


Thanks,

Tim



Tim Clark
Department of Zoology 
University of Hawaii

__
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] Data formatting for matplot

2009-09-28 Thread Tim Clark
Henrique,

Thanks for the suggestion.  I think I may not understand matplot() because the 
graph did not come out like it should have.  Gabor suggested:

library(lattice)
xyplot(y ~ x, mydat, groups = id)

Which gave what I was looking for.  Is there a way to get matplot() to give the 
same graph?  I don't have to use matplot(), but would like to understand its 
use.

Thanks,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Sun, 9/27/09, Henrique Dallazuanna www...@gmail.com wrote:

 From: Henrique Dallazuanna www...@gmail.com
 Subject: Re: [R] Data formatting for matplot
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Sunday, September 27, 2009, 4:47 PM
 You can try this:
 
 matplot(do.call(cbind, split.dat))
 
 On Sun, Sep 27, 2009 at 11:42 PM, Tim Clark mudiver1...@yahoo.com
 wrote:
  Dear List,
 
  I am wanting to produce a multiple line plot, and know
 I can do it with matplot but can't get my data in the format
 I need.  I have a dataframe with three columns; individuals
 ID, x, and y.  I have tried split() but it gives me a list
 of matrices, which is closer but not quite what I need.
  For example:
 
  id-rep(seq(1,5,1),length.out=100)
  x-rnorm(100,5,1)
  y-rnorm(100,20,5)
 
  mydat-data.frame(id,x,y)
  split.dat-split(mydat[,2:3],mydat[,1])
 
  I would appreciate your help in either how to get this
 into a format acceptable to matplot or other options for
 creating a multiple line plot.
 
  Thanks,
 
  Tim
 
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
  __
  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.
 
 
 
 
 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O
 




__
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] Data formatting for matplot

2009-09-28 Thread Tim Clark
Thanks for everyones help.  It is great to have a number of options that result 
in the same graph.  

Aloha,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Mon, 9/28/09, Henrique Dallazuanna www...@gmail.com wrote:

 From: Henrique Dallazuanna www...@gmail.com
 Subject: Re: [R] Data formatting for matplot
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Monday, September 28, 2009, 1:43 AM
 Tim,
 
 With Gabor examples, I understand this,
 
 You can get a similar graph with  plot:
 
 with(mydat, plot(x, y, col = id))
 
 On Mon, Sep 28, 2009 at 3:01 AM, Tim Clark mudiver1...@yahoo.com
 wrote:
  Henrique,
 
  Thanks for the suggestion.  I think I may not
 understand matplot() because the graph did not come out like
 it should have.  Gabor suggested:
 
  library(lattice)
  xyplot(y ~ x, mydat, groups = id)
 
  Which gave what I was looking for.  Is there a way to
 get matplot() to give the same graph?  I don't have to use
 matplot(), but would like to understand its use.
 
  Thanks,
 
  Tim
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
 
  --- On Sun, 9/27/09, Henrique Dallazuanna www...@gmail.com
 wrote:
 
  From: Henrique Dallazuanna www...@gmail.com
  Subject: Re: [R] Data formatting for matplot
  To: Tim Clark mudiver1...@yahoo.com
  Cc: r-help@r-project.org
  Date: Sunday, September 27, 2009, 4:47 PM
  You can try this:
 
  matplot(do.call(cbind, split.dat))
 
  On Sun, Sep 27, 2009 at 11:42 PM, Tim Clark mudiver1...@yahoo.com
  wrote:
   Dear List,
  
   I am wanting to produce a multiple line plot,
 and know
  I can do it with matplot but can't get my data in
 the format
  I need.  I have a dataframe with three columns;
 individuals
  ID, x, and y.  I have tried split() but it gives
 me a list
  of matrices, which is closer but not quite what I
 need.
   For example:
  
   id-rep(seq(1,5,1),length.out=100)
   x-rnorm(100,5,1)
   y-rnorm(100,20,5)
  
   mydat-data.frame(id,x,y)
   split.dat-split(mydat[,2:3],mydat[,1])
  
   I would appreciate your help in either how to
 get this
  into a format acceptable to matplot or other
 options for
  creating a multiple line plot.
  
   Thanks,
  
   Tim
  
  
  
   Tim Clark
   Department of Zoology
   University of Hawaii
  
  
 __
   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.
  
 
 
 
  --
  Henrique Dallazuanna
  Curitiba-Paraná-Brasil
  25° 25' 40 S 49° 16' 22 O
 
 
 
 
 
 
 
 
 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O
 




__
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] Data formatting for matplot

2009-09-27 Thread Tim Clark
Dear List,

I am wanting to produce a multiple line plot, and know I can do it with matplot 
but can't get my data in the format I need.  I have a dataframe with three 
columns; individuals ID, x, and y.  I have tried split() but it gives me a list 
of matrices, which is closer but not quite what I need.  For example:

id-rep(seq(1,5,1),length.out=100)
x-rnorm(100,5,1)
y-rnorm(100,20,5)

mydat-data.frame(id,x,y)
split.dat-split(mydat[,2:3],mydat[,1])

I would appreciate your help in either how to get this into a format acceptable 
to matplot or other options for creating a multiple line plot.

Thanks,

Tim



Tim Clark
Department of Zoology 
University of Hawaii

__
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] Trying to rename spatial pts data frame slot that isn't a slot()

2009-08-30 Thread Tim Clark
Dear List,

I am analyzing the home range area of fish and seem to have lost the 
individuals ID names during my manipulations, and can't find out how to rename 
them.  I calculated the MCP of the fish using mcp() in Adehabitat.  MCP's were 
converted to spatial points data frame and exported to qGIS for manipulations.  
At this point the ID names were lost.  I brought the manipulated shapefiles 
back into qGIS, but can't figure out how to rename the individuals.

#Calculate MCP and save as a shapefile
my.mcp-mcp(xy, id=id, percent=100)
spol-area2spol(my.mcp)
spdf - SpatialPolygonsDataFrame(spol, data=data.frame
+(getSpPPolygonsLabptSlots(spol),
+row.names=getSpPPolygonsIDSlots(spol)), match.ID = TRUE)
writeOGR(spdf,dsn=mcp.dir,layer=All Mantas MCP, driver=ESRI
+Shapefile)

#Read shapefile manipulated in qGIS
mymcp-readOGR(dsn=mcp.dir,layer=All mantas MCP land differenc)


My spatial points data frame has a number of Slots, including one that 
contained the original names called Slot ID.  However, I can not access this 
slot using slot() or slotNames().  

 slotNames(mymcp)
[1] datapolygonsplotOrder   bbox  proj4string

What am I missing here?  Is Slot ID not a slot?  Can I export the ID's with 
the shapefiles to qGIS?  Can I rename the ID's when I bring them back into R?  
When is a slot not a slot()?

Thanks,

TIm




Tim Clark
Department of Zoology 
University of Hawaii

__
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] Finding minimum of time subset

2009-08-14 Thread Tim Clark
Jim,

That works great!  However, would you please explain what the '[' and the 1 do 
in the sapply function?  I understand that you are cutting x by quarter, then 
creating a list of x that is split based on those cuts.  I just don't 
understand what [ means in this contex, or what the number one at the end 
does.

Thanks for you help,

Tim



Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 8/14/09, jim holtman jholt...@gmail.com wrote:

 From: jim holtman jholt...@gmail.com
 Subject: Re: [R] Finding minimum of time subset
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Friday, August 14, 2009, 6:18 AM
 Here is one way to do it:
 
 
 mytime-c(12:00:00,12:00:05,12:15:05,12:15:06,12:20:00,12:30:01,12:45:01,13:00:00,13:15:02)
  # you might want a date on your data
  x - as.POSIXct(mytime, format=%H:%M:%S)
  # create quarter hour intervals for the data range
  quarter - seq(trunc(min(x), 'days'), trunc(max(x)
 + 86400, 'days'), by='15 min') # add 86400 to add a day for
 truncation
  # cut the data by quarter hours and then take the
 first value in each group
  x.s - sapply(split(x, cut(x, breaks=quarter),
 drop=TRUE), '[', 1)
  # lost the 'class' for some reason; put it back
  class(x.s) - c(POSIXt, POSIXct)
  # the answer
  x.s
       2009-08-14 12:00:00   
    2009-08-14 12:15:00   
    2009-08-14
 12:30:00       2009-08-14
 12:45:00       2009-08-14 13:00:00
 2009-08-14 12:00:00 EDT 2009-08-14 12:15:05 EDT
 2009-08-14
 12:30:01 EDT 2009-08-14 12:45:01 EDT 2009-08-14
 13:00:00 EDT
       2009-08-14 13:15:00
 2009-08-14 13:15:02 EDT
 
 
 
 On Thu, Aug 13, 2009 at 4:10 PM, Tim Clarkmudiver1...@yahoo.com
 wrote:
  Dear List,
 
  I have a data frame of data taken every few seconds.
  I would like to subset the data to retain only the data
 taken on the quarter hour, and as close to the quarter hour
 as possible.  So far I have figured out how to subset the
 data to the quarter hour, but not how to keep only the
 minimum time for each quarter hour.
 
  For example:
 
 mytime-c(12:00:00,12:00:05,12:15:05,12:15:06,12:20:00,12:30:01,12:45:01,13:00:00,13:15:02)
 
 subtime-grep(pattern=[[:digit:]]+[[:punct:]]00[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]15[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]30[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]45[[:punct:]][[:digit:]]+,mytime)
  mytime[subtime]
 
  [1] 12:00:00 12:00:05 12:15:05 12:15:06
 12:30:01 12:45:01 13:00:00 13:15:02
 
  This gives me the data taken at quarter hour intervals
 (removes 12:20:00) but I am still left with multiple values
 at the quarter hours.
 
  I would like to obtain:
 
  12:00:00 12:15:05 12:30:01 12:45:01 13:00:00
 13:15:02
 
  Thanks!
 
  Tim
 
 
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
  __
  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.
 
 
 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 




__
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] Finding minimum of time subset

2009-08-14 Thread Tim Clark
Jim,

Got it!  Thanks for the explanation and the example.  Always nice to learn new 
tricks on R.

Aloha,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 8/14/09, jim holtman jholt...@gmail.com wrote:

 From: jim holtman jholt...@gmail.com
 Subject: Re: [R] Finding minimum of time subset
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Friday, August 14, 2009, 7:51 AM
 sapply(mylist, '[', 1)
 
 is equivalent to
 
 sapply(mylist, function(x) x[1])  # select just the
 first element
 
 [ is an function that is called with a object and an
 index.  Using
 it the way I did in the email was a shorthand way of doing
 it.  Here
 is an example:
 
  x - list(1,2,3)
  x[1]
 [[1]]
 [1] 1
 
  `[`(x, 1)
 [[1]]
 [1] 1
 
 Notice the function call  `[`(x,1).  This is what
 is being done in the
 sapply and passing the 1 as the second parameter.
 
 On Fri, Aug 14, 2009 at 1:30 PM, Tim Clarkmudiver1...@yahoo.com
 wrote:
  Jim,
 
  That works great!  However, would you please explain
 what the '[' and the 1 do in the sapply function?  I
 understand that you are cutting x by quarter, then creating
 a list of x that is split based on those cuts.  I just
 don't understand what [ means in this contex, or what the
 number one at the end does.
 
  Thanks for you help,
 
  Tim
 
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
 
  --- On Fri, 8/14/09, jim holtman jholt...@gmail.com
 wrote:
 
  From: jim holtman jholt...@gmail.com
  Subject: Re: [R] Finding minimum of time subset
  To: Tim Clark mudiver1...@yahoo.com
  Cc: r-help@r-project.org
  Date: Friday, August 14, 2009, 6:18 AM
  Here is one way to do it:
 
  
 
 mytime-c(12:00:00,12:00:05,12:15:05,12:15:06,12:20:00,12:30:01,12:45:01,13:00:00,13:15:02)
   # you might want a date on your data
   x - as.POSIXct(mytime,
 format=%H:%M:%S)
   # create quarter hour intervals for the data
 range
   quarter - seq(trunc(min(x), 'days'),
 trunc(max(x)
  + 86400, 'days'), by='15 min') # add 86400 to add
 a day for
  truncation
   # cut the data by quarter hours and then take
 the
  first value in each group
   x.s - sapply(split(x, cut(x,
 breaks=quarter),
  drop=TRUE), '[', 1)
   # lost the 'class' for some reason; put it
 back
   class(x.s) - c(POSIXt, POSIXct)
   # the answer
   x.s
        2009-08-14 12:00:00
     2009-08-14 12:15:00
     2009-08-14
  12:30:00       2009-08-14
  12:45:00       2009-08-14 13:00:00
  2009-08-14 12:00:00 EDT 2009-08-14 12:15:05
 EDT
  2009-08-14
  12:30:01 EDT 2009-08-14 12:45:01 EDT
 2009-08-14
  13:00:00 EDT
        2009-08-14 13:15:00
  2009-08-14 13:15:02 EDT
  
 
 
  On Thu, Aug 13, 2009 at 4:10 PM, Tim Clarkmudiver1...@yahoo.com
  wrote:
   Dear List,
  
   I have a data frame of data taken every few
 seconds.
   I would like to subset the data to retain only
 the data
  taken on the quarter hour, and as close to the
 quarter hour
  as possible.  So far I have figured out how to
 subset the
  data to the quarter hour, but not how to keep only
 the
  minimum time for each quarter hour.
  
   For example:
  
 
 mytime-c(12:00:00,12:00:05,12:15:05,12:15:06,12:20:00,12:30:01,12:45:01,13:00:00,13:15:02)
  
 
 subtime-grep(pattern=[[:digit:]]+[[:punct:]]00[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]15[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]30[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]45[[:punct:]][[:digit:]]+,mytime)
   mytime[subtime]
  
   [1] 12:00:00 12:00:05 12:15:05
 12:15:06
  12:30:01 12:45:01 13:00:00 13:15:02
  
   This gives me the data taken at quarter hour
 intervals
  (removes 12:20:00) but I am still left with
 multiple values
  at the quarter hours.
  
   I would like to obtain:
  
   12:00:00 12:15:05 12:30:01 12:45:01
 13:00:00
  13:15:02
  
   Thanks!
  
   Tim
  
  
  
  
   Tim Clark
   Department of Zoology
   University of Hawaii
  
  
 __
   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.
  
 
 
 
  --
  Jim Holtman
  Cincinnati, OH
  +1 513 646 9390
 
  What is the problem that you are trying to solve?
 
 
 
 
 
 
 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 




__
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] Finding minimum of time subset

2009-08-14 Thread Tim Clark
Thanks for everyones help and for the alternate ways of doing this.  I am 
always amazed at how many solutions this list comes up with for things I get 
stuck on!  It really helps us non-programmers learn R!

Aloha,

Tim

Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 8/14/09, Henrique Dallazuanna www...@gmail.com wrote:

 From: Henrique Dallazuanna www...@gmail.com
 Subject: Re: [R] Finding minimum of time subset
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Friday, August 14, 2009, 7:19 AM
 Try this also:
 
 times - as.POSIXlt(mytime, format =
 %H:%M:%S)
 subTimes - times[times[['min']] %in%
 c(0,15,30,45)]
 format(subTimes[!duplicated(format(subTimes,
 %H:%M))], %H:%M:%S)
 
 
 On Thu, Aug 13, 2009 at 5:10 PM,
 Tim Clark mudiver1...@yahoo.com
 wrote:
 
 Dear List,
 
 
 
 I have a data frame of data taken every few seconds.  I
 would like to subset the data to retain only the data taken
 on the quarter hour, and as close to the quarter hour as
 possible.  So far I have figured out how to subset the data
 to the quarter hour, but not how to keep only the minimum
 time for each quarter hour.
 
 
 
 
 For example:
 
 mytime-c(12:00:00,12:00:05,12:15:05,12:15:06,12:20:00,12:30:01,12:45:01,13:00:00,13:15:02)
 
 subtime-grep(pattern=[[:digit:]]+[[:punct:]]00[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]15[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]30[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]45[[:punct:]][[:digit:]]+,mytime)
 
 
 mytime[subtime]
 
 
 
 [1] 12:00:00 12:00:05
 12:15:05 12:15:06
 12:30:01 12:45:01
 13:00:00 13:15:02
 
 
 
 This gives me the data taken at quarter hour intervals
 (removes 12:20:00) but I am still left with multiple values
 at the quarter hours.
 
 
 
 I would like to obtain:
 
 
 
 12:00:00 12:15:05
 12:30:01 12:45:01
 13:00:00 13:15:02
 
 
 
 Thanks!
 
 
 
 Tim
 
 
 
 
 
 
 
 
 
 Tim Clark
 
 Department of Zoology
 
 University of Hawaii
 
 
 
 __
 
 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.
 
 
 
 
 -- 
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O
 
 




__
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] Finding minimum of time subset

2009-08-13 Thread Tim Clark
Dear List,

I have a data frame of data taken every few seconds.  I would like to subset 
the data to retain only the data taken on the quarter hour, and as close to the 
quarter hour as possible.  So far I have figured out how to subset the data to 
the quarter hour, but not how to keep only the minimum time for each quarter 
hour.  

For example:
mytime-c(12:00:00,12:00:05,12:15:05,12:15:06,12:20:00,12:30:01,12:45:01,13:00:00,13:15:02)
subtime-grep(pattern=[[:digit:]]+[[:punct:]]00[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]15[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]30[[:punct:]][[:digit:]]+|[[:digit:]]+[[:punct:]]45[[:punct:]][[:digit:]]+,mytime)
mytime[subtime]

[1] 12:00:00 12:00:05 12:15:05 12:15:06 12:30:01 12:45:01 
13:00:00 13:15:02

This gives me the data taken at quarter hour intervals (removes 12:20:00) but I 
am still left with multiple values at the quarter hours.  

I would like to obtain:

12:00:00 12:15:05 12:30:01 12:45:01 13:00:00 13:15:02

Thanks!

Tim




Tim Clark
Department of Zoology 
University of Hawaii

__
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] Maximizing values in subsetted dataframe

2009-07-28 Thread Tim Clark

Dear List,

I am trying to sub-sample some data by taking a data point every x minutes.  
The data contains missing values, and I would like to take the sub-sample that 
maximizes the number of valid points in the sample.  I.e. minimizes the number 
of NA's in the data set.  

For example, given the following:

da-seq(Sys.time(),by=1,length.out=10)
x-c(1,2,NA,4,NA,6,NA,8,9,10)
mydata-data.frame(da,x)

If I wanted to take a subsample every 2 seconds, I would have the following two 
possible answers:

answer1: 2,4,NA,8
answer2: 1,NA,NA,7

I would like a function that would choose between these and obtain the one with 
the fewest missing values.

In my real dataset I have multiple variables collected every second and I would 
like to subsample it every 5, 10, and 15 minutes.

I appreciate your help.

Tim

Tim Clark
Department of Zoology 
University of Hawaii

__
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] Duplicated date values aren't duplicates

2009-07-24 Thread Tim Clark

Don and Jim,

Thanks!  I got it!  Duplicated is only returning one of the two duplicated 
dates (the second date).  It all makes sense now!

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 7/24/09, Don MacQueen m...@llnl.gov wrote:

 From: Don MacQueen m...@llnl.gov
 Subject: Re: [R] Duplicated date values aren't duplicates
 To: Tim Clark mudiver1...@yahoo.com, r-help@r-project.org
 Date: Friday, July 24, 2009, 4:00 AM
 Look at results of
 
    table( mydata$DateTime )
 
 and I think you will see that some are duplicated.
 Specifically, the 
 two in your dupes object.
 
 -Don
 
 At 5:50 PM -0700 7/23/09, Tim Clark wrote:
 Dear list,
 
 I just had a function (as.ltraj in Adehabitat) give me
 the following error:
 
 Error in as.ltraj(xy, id, date = da) : non unique
 dates for a given burst
 
 I checked my dates and got the following:
 
  
    dupes-mydata$DateTime[duplicated(mydata$DateTime)]
   dupes
 [1] (07/30/02 00:00:00) (08/06/03 17:45:00)
 
 Is there a reason different dates would come up as
 duplicate values? 
 I would prefer not to have to delete them if I don't
 have to.  Any 
 suggestions on how to get R to realize they are
 different?
 
 Thanks,
 
 Tim
 
 
 
 Tim Clark
 Department of Zoology
 University of Hawaii
 
 __
 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.
 
 
 -- 
 --
 Don MacQueen
 Environmental Protection Department
 Lawrence Livermore National Laboratory
 Livermore, CA, USA
 925-423-1062
 --
 




__
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] Duplicated date values aren't duplicates

2009-07-23 Thread Tim Clark

Dear list,

I just had a function (as.ltraj in Adehabitat) give me the following error:

Error in as.ltraj(xy, id, date = da) : non unique dates for a given burst

I checked my dates and got the following:

   dupes-mydata$DateTime[duplicated(mydata$DateTime)]
 dupes
[1] (07/30/02 00:00:00) (08/06/03 17:45:00)

Is there a reason different dates would come up as duplicate values?  I would 
prefer not to have to delete them if I don't have to.  Any suggestions on how 
to get R to realize they are different?

Thanks,

Tim



Tim Clark
Department of Zoology 
University of Hawaii

__
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] Calculating distance between spatial points

2009-06-25 Thread Tim Clark

Dear List,

I am trying to determine the speed an animal is traveling on each leg of a 
track.  My data is in longitude and latitude, so I am using the package rgdal 
to convert it into a spatial points data frame and transform it to UTM.  I 
would then like to find the difference between successive longitudes and 
latitudes, find the euclidean distance between points, and compute the speed of 
the animal on each leg.

My problem is that once I convert the lat and long into a spatial points data 
frame I can not access the lat and long individually.  As far as I know I need 
to convert them in order to transform the lat and long to UTM.  Is there a way 
I can call each variable separately in the sp dataframe?  My code with example 
data is below.  Any suggestions would be appreciated.

  library(rgdal) 
  date.diff-(20,30,10,30)
  Long-c(-156.0540 ,-156.0541 ,-156.0550 ,-156.0640)
  Lat-c(19.73733,19.73734,19.73743,19.73833) 
   
  SP-data.frame(Long,Lat)  
  SP-SpatialPoints(SP,proj4string=CRS(+proj=longlat +ellps=WGS84))
  SP.utm-spTransform(SP, CRS(+proj=utm +zone=4 +ellps=WGS84)) 
  
  long.diff-diff(SP.utm$Long)
  lat.diff-diff(SP.utm$Lat)
  
  d=(long.diff^2+lat.diff^2)^.5
  speed=d/date.diff


Aloha,

Tim



Tim Clark
Department of Zoology 
University of Hawaii

__
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] PBSmapping problems with importGSHHS

2009-05-27 Thread Tim Clark

Dear List,

I am trying to use the PBSmapping package to import and plot the shoreline of 
Hawaii.  I am having problems importing and plotting the specific regions that 
I would like to plot.  Specifically, I can't get it to import the range of x 
variables that I would like.  I think my problem is with a variable called 
xoff, but I have no idea what it is, what it does, or how I am supposed to use 
it.  It's default value is -360, but I have found examples in the PBSmapping 
web publication of it being set to zero as well.  The help files provides the 
following definitions:

xlim range of X-coordinates to clip. Range should match the transform xoff. 

xoff transform the X-coordinates by specified amount. 


I can import certain regions of GSHH, but I don't seem to be able to limit them 
like I want using xlim.  If I change xoff to something besides -360 I get 
different sizes of plots that are all the color I am using for land.  I have 
the following:

Hawaii.GSHH- importGSHHS(GSHHfile,
xlim=c(-156.3,-155.92), ylim=c(19.45,19.5), xoff=-360)

The GSHHS shoreline data is found at:
http://www.soest.hawaii.edu/wessel/gshhs/gshhs.html

Any suggestions on what is going on?

Thanks,

Tim




Tim Clark
Department of Zoology 
University of Hawaii

__
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] Need a faster function to replace missing data

2009-05-26 Thread Tim Clark

Many thanks to Jim, Bill, and Carl.  Using indexes instead of the for loop gave 
me my answer in minutes instead of hours!  Thanks for all of your great 
suggestions!

Aloha,

Tim

Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 5/22/09, jim holtman jholt...@gmail.com wrote:

 From: jim holtman jholt...@gmail.com
 Subject: Re: [R] Need a faster function to replace missing data
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Friday, May 22, 2009, 4:59 PM
 Here is a modification that should
 now find the closest:
  
 
 myvscan-data.frame(c(1,NA,1.5),as.POSIXct(c(12:00:00,12:14:00,12:20:00),
 + format=%H:%M:%S))
  # convert to numeric
  
 
 names(myvscan)-c(Latitude,DateTime)
 
  
  myvscan$tn - as.numeric(myvscan$DateTime)  #
 numeric for findInterval
  
 
 mygarmin-data.frame(c(20,30,40),as.POSIXct(c(12:00:00,12:10:00,12:15:00),
 
 + format=%H:%M:%S))
  
  
 
 names(mygarmin)-c(Latitude,DateTime)
  mygarmin$tn - as.numeric(mygarmin$DateTime)
  
  # use 'findInterval'
 
  na.indx - which(is.na(myvscan$Latitude))  # find
 NAs
  
  # create matrix of values to test the range
  indices -
 findInterval(myvscan$tn[na.indx],mygarmin$tn)
 
  x - cbind(indices,
 +    abs(myvscan$tn[na.indx] -
 mygarmin$tn[indices]), # lower
 +    abs(myvscan$tn[na.indx] -
 mygarmin$tn[indices + 1]))  #higher
  # now determine which index is closer
 
  closest - x[,1] + (x[,2]  x[,3])  # determine
 the proper index
  # replace with garmin latitude
  myvscan$Latitude[na.indx] -
 mygarmin$Latitude[closest]
  
  
  
  myvscan
 
   Latitude    DateTime
 tn
 1  1.0 2009-05-23 12:00:00 124308
 2 40.0 2009-05-23 12:14:00 1243080840
 3  1.5 2009-05-23 12:20:00 1243081200
  
 
 
 
 On Fri, May 22, 2009 at 7:39 PM,
 Tim Clark mudiver1...@yahoo.com
 wrote:
 
 
 Jim,
 
 Thanks!  I like the way you use indexing instead of the
 loops.  However, the find.Interval function does not give
 the right result.  I have been playing with it and it seems
 to give the closest number that is less than the one of
 interest.  In this case, the correct replacement should
 have been 40, not 30, since 12:15 from mygarmin is closer to
 12:14 in myvscan than 12:10.  Is there a way to get the
 function to find the closest in value instead of the next
 smaller value?  I was trying to use which.min to get the
 closet date but can't seem to get it to work right
 either.
 
 
 
 Aloha,
 
 Tim
 
 
 Tim Clark
 Department of Zoology
 University of Hawaii
 
 
 --- On Fri, 5/22/09, jim holtman jholt...@gmail.com
 wrote:
 
 
  From: jim holtman jholt...@gmail.com
  Subject: Re: [R] Need a faster function to replace
 missing data
  To: Tim Clark mudiver1...@yahoo.com
 
  Cc: r-help@r-project.org
  Date: Friday, May 22, 2009, 7:24 AM
 
 
 
  I think this does what you
  want.  It uses 'findInterval' to determine
 where a
  possible match is:
   
  
 
 myvscan-data.frame(c(1,NA,1.5),as.POSIXct(c(12:00:00,12:14:00,12:20:00),
 
  format=%H:%M:%S))
   # convert to numeric
  
 
 names(myvscan)-c(Latitude,DateTime)
 
   myvscan$tn - as.numeric(myvscan$DateTime) 
 #
 
  numeric for findInterval
  
 
 mygarmin-data.frame(c(20,30,40),as.POSIXct(c(12:00:00,12:10:00,12:15:00),
  format=%H:%M:%S))
 
  
 
 
 names(mygarmin)-c(Latitude,DateTime)
   mygarmin$tn - as.numeric(mygarmin$DateTime)
  
   # use 'findInterval'
   na.indx - which(is.na(myvscan$Latitude))  # find
 
  NAs
 
   # replace with garmin latitude
   myvscan$Latitude[na.indx] -
  mygarmin$Latitude[findInterval(myvscan$tn[na.indx],
  mygarmin$tn)]
  
  
   myvscan
 
    Latitude   
 DateTime
  tn
 
  1  1.0 2009-05-22 12:00:00 1243008000
  2 30.0 2009-05-22 12:14:00 1243008840
  3  1.5 2009-05-22 12:20:00 1243009200
  
 
 
 
 
  On Fri, May 22, 2009 at 12:45 AM,
  Tim Clark mudiver1...@yahoo.com
  wrote:
 
 
  Dear List,
 
  I need some help in coming up with a function that
 will
 
  take two data sets, determine if a value is missing in
 one,
  find a value in the second that was taken at about the
 same
  time, and substitute the second value in for where the
 first
  should have been.  My problem is from a fish
 tracking
 
  study.  We put acoustic tags in fish and track them
 for
  several days.  Location data is supposed to be
  automatically recorded every time we detect a
  ping from the fish.  Unfortunately the
 GPS had
 
  some problems and sometimes the fishes depth was
 recorded
  but not its location.  I fortunately had a back-up
 GPS that
  was taking location data every five minutes.  I would
 like
  to merge the two files, replacing the missing value in
 the
 
  vscan (automatic) file with the location from the
 garmin
  file.  Since we were getting vscan records every 1-2
  seconds and garmin records every 5 minutes, I need to
 find
  the right place in the vscan file to place the garmin
 record
 
  - i.e. the
 
   closest in time, but not greater than 5 minutes.  I
 have
  written a function

[R] Creating multiple graphs based on one variable

2009-05-26 Thread Tim Clark

Dear List,

I would like to create several graphs of similar data.  I have x and y values 
for several different individuals (in this case fish).  I would like to plot 
the x and y values for each fish separately.  I can do it using a for loop, but 
I think I should be using apply.  Please let me know what I am doing wrong, 
or if there is a better way to do this.  What I have is:

#Test data
dat-data.frame(c(rep(1:10,4)),c(rep(1:10,4)),c(rep(c(Tony,Mike,Vicky,Fred),each=10)))
names(dat)-c(x,y,Name) 

#Create function to plot x and y
myplot-function() plot(dat$x,dat$y)

#Apply the function to each of the names
par(mfcol=c(2,2))   
apply(dat,2,myplot,by=dat$Name) #Does not work - tried various versions

I would like separate plots for Tony, Mike, and Vicky.  What is the best way to 
do this?  

Thank!

Tim


Tim Clark
Department of Zoology 
University of Hawaii

__
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] Problem with fractional seconds

2009-05-26 Thread Tim Clark

Dear List,

I am having problems converting a file with fractional seconds to class 
POSIXct.  I have set my options to include digits.secs and my format to just 
time, but my output is the current date with my time lacking the fractions of a 
second.  For example:

options(digits.secs=3)  
t-c(06:00:00.100,06:00:01.231)
myt-as.POSIXct(t,format=%H:%M:%S)
myt

[1] 2009-05-26 06:00:00 HST 2009-05-26 06:00:01 HST

I would like the output to be just time with fractional seconds. I.e.

06:00:00.100,06:00:01.231

I have also tried Chron times() which did not work either.  Interestingly, 
Sys.time() does produce fractional seconds, so I know the options are working.

I would appreciate your help and suggestions.

Aloha,

Tim





Tim Clark
Department of Zoology 
University of Hawaii

__
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] Creating multiple graphs based on one variable

2009-05-26 Thread Tim Clark

Luc,

Thanks!  I was not aware of that package.  It looks a lot easier than what I 
have been trying to do!

Aloha,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Tue, 5/26/09, Luc Villandre villa...@dms.umontreal.ca wrote:

 From: Luc Villandre villa...@dms.umontreal.ca
 Subject: Re: [R] Creating multiple graphs based on one variable
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Tuesday, May 26, 2009, 4:01 AM
 Tim Clark wrote:
  Dear List,
  
  I would like to create several graphs of similar
 data.  I have x and y values for several different
 individuals (in this case fish).  I would like to plot
 the x and y values for each fish separately.  I can do
 it using a for loop, but I think I should be using
 apply.  Please let me know what I am doing wrong, or
 if there is a better way to do this.  What I have
 is:
  
  #Test data
 
 dat-data.frame(c(rep(1:10,4)),c(rep(1:10,4)),c(rep(c(Tony,Mike,Vicky,Fred),each=10)))
  names(dat)-c(x,y,Name) 
  #Create function to plot x and y
  myplot-function() plot(dat$x,dat$y)
  
  #Apply the function to each of the names
 
 par(mfcol=c(2,2))   apply(dat,2,myplot,by=dat$Name)
 #Does not work - tried various versions
  
  I would like separate plots for Tony, Mike, and
 Vicky.  What is the best way to do this?  
  Thank!
  
  Tim
  
  
  Tim Clark
  Department of Zoology University of Hawaii
  
  __
  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.
    
 
 Hi Tim,
 
 I'm now rather fond of Hadley Wickham's ggplot2 package.
 Its structure is most of the times intuitive and it does
 yield nice-looking output.
 
 In order to solve your problem, taking advantage of the
 ggplot2 framework, you can simply use the following:
  library(ggplot2) ;
  ## If you want all the curves to be on the same
 plotting grid ;
  
  p - ggplot(dat, aes(x=x,y=y, group=Name)) ;
  p + geom_line(aes(colour=Name)) ; ## Only one curve
 will be visible since they are all superposed.
  
  ## If you want the curves to be on separate plotting
 grids ;
  
  p - ggplot(dat, aes(x=x,y=y, group=Name)) ;
  p - p + geom_line(aes(colour=Name)) ;
  p+facet_grid(. ~ Name) ;
 Hope this helps,
 -- *Luc Villandré*
 /Biostatistician
 McGill University Health Center -
 Montreal Children's Hospital Research Institute/
 




__
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] Creating multiple graphs based on one variable

2009-05-26 Thread Tim Clark

Stefan,

Thanks for the suggestion.  Lattice works great.  You might also want to check 
out the ggplot2 package that Luc suggested.  They both seem to provide quite a 
few more options than the basic graphics package in R.

Aloha,

Tim

Tim Clark
Department of Zoology 
University of Hawaii


--- On Mon, 5/25/09, Stefan Grosse singularit...@gmx.net wrote:

 From: Stefan Grosse singularit...@gmx.net
 Subject: Re: [R] Creating multiple graphs based on one variable
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Monday, May 25, 2009, 11:55 PM
 On Tue, 26 May 2009 02:34:55 -0700
 (PDT) Tim Clark
 mudiver1...@yahoo.com
 wrote:
 
 TC I would like separate plots for Tony, Mike, and
 Vicky.  What is the
 TC best way to do this?  
 
 use the lattice package:
 
 library(lattice)
 xyplot(y~x|Name,data=dat)
 
 Mr. Sarkar (the author of the package) has written an
 excellent book on
 his package I recommend it.
 
 hth
 Stefan
 




__
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] Problem with fractional seconds

2009-05-26 Thread Tim Clark

Gabor,

Thanks, that worked.  However, is there is way to just get the time and not 
have the date added?  I assume the date is added since POSIX is based on 
seconds since 1970.  I can't seem to convert the POSIX value to Chron times(), 
and Chron won't take fractional seconds.  Are there other ways to deal with 
just time and not date?

Thanks,

Tim

Tim Clark
Department of Zoology 
University of Hawaii


--- On Tue, 5/26/09, Gabor Grothendieck ggrothendi...@gmail.com wrote:

 From: Gabor Grothendieck ggrothendi...@gmail.com
 Subject: Re: [R] Problem with fractional seconds
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Tuesday, May 26, 2009, 11:59 AM
 Try this:
 
  as.POSIXct(c(06:00:00.100,06:00:01.231), format =
 %H:%M:%S%OS)
 [1] 2009-05-26 06:00:00.100 EDT 2009-05-26 06:00:00.231
 EDT
 
 
 On Tue, May 26, 2009 at 5:52 PM, Tim Clark mudiver1...@yahoo.com
 wrote:
 
  Dear List,
 
  I am having problems converting a file with fractional
 seconds to class POSIXct.  I have set my options to include
 digits.secs and my format to just time, but my output is the
 current date with my time lacking the fractions of a second.
  For example:
 
  options(digits.secs=3)
  t-c(06:00:00.100,06:00:01.231)
  myt-as.POSIXct(t,format=%H:%M:%S)
  myt
 
  [1] 2009-05-26 06:00:00 HST 2009-05-26 06:00:01
 HST
 
  I would like the output to be just time with
 fractional seconds. I.e.
 
  06:00:00.100,06:00:01.231
 
  I have also tried Chron times() which did not work
 either.  Interestingly, Sys.time() does produce fractional
 seconds, so I know the options are working.
 
  I would appreciate your help and suggestions.
 
  Aloha,
 
  Tim
 
 
 
 
 
  Tim Clark
  Department of Zoology
  University of Hawaii
 
  __
  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-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] Need a faster function to replace missing data

2009-05-22 Thread Tim Clark

Jim,

Thanks!  I like the way you use indexing instead of the loops.  However, the 
find.Interval function does not give the right result.  I have been playing 
with it and it seems to give the closest number that is less than the one of 
interest.  In this case, the correct replacement should have been 40, not 30, 
since 12:15 from mygarmin is closer to 12:14 in myvscan than 12:10.  Is there a 
way to get the function to find the closest in value instead of the next 
smaller value?  I was trying to use which.min to get the closet date but can't 
seem to get it to work right either.

Aloha,

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 5/22/09, jim holtman jholt...@gmail.com wrote:

 From: jim holtman jholt...@gmail.com
 Subject: Re: [R] Need a faster function to replace missing data
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Friday, May 22, 2009, 7:24 AM
 I think this does what you
 want.  It uses 'findInterval' to determine where a
 possible match is:
  
 
 myvscan-data.frame(c(1,NA,1.5),as.POSIXct(c(12:00:00,12:14:00,12:20:00),
 format=%H:%M:%S))
  # convert to numeric
 
 names(myvscan)-c(Latitude,DateTime)
 
  myvscan$tn - as.numeric(myvscan$DateTime)  #
 numeric for findInterval
 
 mygarmin-data.frame(c(20,30,40),as.POSIXct(c(12:00:00,12:10:00,12:15:00),
 format=%H:%M:%S))
 
 
 names(mygarmin)-c(Latitude,DateTime)
  mygarmin$tn - as.numeric(mygarmin$DateTime)
  
  # use 'findInterval'
  na.indx - which(is.na(myvscan$Latitude))  # find
 NAs
 
  # replace with garmin latitude
  myvscan$Latitude[na.indx] -
 mygarmin$Latitude[findInterval(myvscan$tn[na.indx],
 mygarmin$tn)]
  
  
  myvscan
   Latitude    DateTime
 tn
 
 1  1.0 2009-05-22 12:00:00 1243008000
 2 30.0 2009-05-22 12:14:00 1243008840
 3  1.5 2009-05-22 12:20:00 1243009200
  
 
 
 
 On Fri, May 22, 2009 at 12:45 AM,
 Tim Clark mudiver1...@yahoo.com
 wrote:
 
 
 Dear List,
 
 I need some help in coming up with a function that will
 take two data sets, determine if a value is missing in one,
 find a value in the second that was taken at about the same
 time, and substitute the second value in for where the first
 should have been.  My problem is from a fish tracking
 study.  We put acoustic tags in fish and track them for
 several days.  Location data is supposed to be
 automatically recorded every time we detect a
 ping from the fish.  Unfortunately the GPS had
 some problems and sometimes the fishes depth was recorded
 but not its location.  I fortunately had a back-up GPS that
 was taking location data every five minutes.  I would like
 to merge the two files, replacing the missing value in the
 vscan (automatic) file with the location from the garmin
 file.  Since we were getting vscan records every 1-2
 seconds and garmin records every 5 minutes, I need to find
 the right place in the vscan file to place the garmin record
 - i.e. the
 
  closest in time, but not greater than 5 minutes.  I have
 written a function that does this. However, it works with my
 test data but locks up my computer with my real data.  I
 have several million vscan records and several thousand
 garmin records.  Is there a better way to do this?
 
 
 
 My function and test data:
 
 myvscan-data.frame(c(1,NA,1.5),times(c(12:00:00,12:14:00,12:20:00)))
 names(myvscan)-c(Latitude,DateTime)
 
 mygarmin-data.frame(c(20,30,40),times((12:00:00,12:10:00,12:15:00)))
 names(mygarmin)-c(Latitude,DateTime)
 
 minute.diff-1/24/12   #Time diff is in days, so this
 is 5 minutes
 
 for (k in 1:nrow(myvscan))
 {
 if (is.na(myvscan$Latitude[k]))
 {
 if ((min(abs(mygarmin$DateTime-myvscan$DateTime[k]))) 
 minute.diff )
 {
 index.min.date-which.min(abs(mygarmin$DateTime-myvscan$DateTime[k]))
 
 myvscan$Latitude[k]-mygarmin$Latitude[index.min.date]
 }}}
 
 I appreciate your help and advice.
 
 Aloha,
 
 Tim
 
 
 
 
 Tim Clark
 Department of Zoology
 University of Hawaii
 
 __
 
 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.
 
 
 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 
 




__
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] help with gsub and date pattern

2009-05-21 Thread Tim Clark

Dear List,

I am having a problem using gsub to remove dates from a date/time string.

For example:

x-c(5/31/2009 12:34:00,6/1/2009 1:14:00)

I would like to remove the date and have just the time.

I have tried:
gsub([0-9+]/[0-9+]/[0-9+],,x)

and various versions.  I think my problem is that the / is a special character 
and is telling it something that I don't mean.  I would appreciate any 
suggestions on how to proceed.

Thanks,

Tim



Tim Clark
Department of Zoology 
University of Hawaii

__
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] help with gsub and date pattern

2009-05-21 Thread Tim Clark

Thanks for the help and the various options!  Putting the + outside the 
brackets worked, but I like the strsplit option.  Always nice to learn new 
functions!

Aloha,

Tim



--- On Thu, 5/21/09, Marc Schwartz marc_schwa...@me.com wrote:

 From: Marc Schwartz marc_schwa...@me.com
 Subject: Re: [R] help with gsub and date pattern
 To: Tim Clark mudiver1...@yahoo.com
 Cc: r-help@r-project.org
 Date: Thursday, May 21, 2009, 11:34 AM
 On May 21, 2009, at 4:13 PM, Tim
 Clark wrote:
 
  
  Dear List,
  
  I am having a problem using gsub to remove dates from
 a date/time string.
  
  For example:
  
  x-c(5/31/2009 12:34:00,6/1/2009 1:14:00)
  
  I would like to remove the date and have just the
 time.
  
  I have tried:
  gsub([0-9+]/[0-9+]/[0-9+],,x)
  
  and various versions.  I think my problem is that
 the / is a special character and is telling it something
 that I don't mean.  I would appreciate any suggestions
 on how to proceed.
  
  Thanks,
  
  Tim
 
 
 
 Switch the '+' to outside the brackets:
 
  gsub([0-9]+/[0-9]+/[0-9]+ ,,x)
 [1] 12:34:00 1:14:00
 
 
 A few other options:
 
 # Use strsplit
  sapply(strsplit(x, split =  ), [, 2)
 [1] 12:34:00 1:14:00
 
 
 # Return the pattern contained within the parens
 # See ?regex
  gsub(^.* (.*)$, \\1, x)
 [1] 12:34:00 1:14:00
 
 
 # Replace the characters up to the space with an empty
 vector
  gsub(^.* , , x)
 [1] 12:34:00 1:14:00
 
 
 HTH,
 
 Marc Schwartz
 
 




__
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] Need a faster function to replace missing data

2009-05-21 Thread Tim Clark

Dear List,

I need some help in coming up with a function that will take two data sets, 
determine if a value is missing in one, find a value in the second that was 
taken at about the same time, and substitute the second value in for where the 
first should have been.  My problem is from a fish tracking study.  We put 
acoustic tags in fish and track them for several days.  Location data is 
supposed to be automatically recorded every time we detect a ping from the 
fish.  Unfortunately the GPS had some problems and sometimes the fishes depth 
was recorded but not its location.  I fortunately had a back-up GPS that was 
taking location data every five minutes.  I would like to merge the two files, 
replacing the missing value in the vscan (automatic) file with the location 
from the garmin file.  Since we were getting vscan records every 1-2 seconds 
and garmin records every 5 minutes, I need to find the right place in the vscan 
file to place the garmin record - i.e. the
 closest in time, but not greater than 5 minutes.  I have written a function 
that does this. However, it works with my test data but locks up my computer 
with my real data.  I have several million vscan records and several thousand 
garmin records.  Is there a better way to do this?


My function and test data:

myvscan-data.frame(c(1,NA,1.5),times(c(12:00:00,12:14:00,12:20:00)))
names(myvscan)-c(Latitude,DateTime)
mygarmin-data.frame(c(20,30,40),times((12:00:00,12:10:00,12:15:00)))
names(mygarmin)-c(Latitude,DateTime)

minute.diff-1/24/12   #Time diff is in days, so this is 5 minutes
for (k in 1:nrow(myvscan))  
{
if (is.na(myvscan$Latitude[k]))
{
if ((min(abs(mygarmin$DateTime-myvscan$DateTime[k])))  minute.diff )
{
index.min.date-which.min(abs(mygarmin$DateTime-myvscan$DateTime[k]))
myvscan$Latitude[k]-mygarmin$Latitude[index.min.date] 
}}}

I appreciate your help and advice.

Aloha,

Tim




Tim Clark
Department of Zoology 
University of Hawaii

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