Re: [R] code reduction (if anyone feels like it)

From: jim holtman <jholtman_at_gmail.com>
Date: Tue, 15 Jul 2008 18:10:31 -0400

I am reasonably sure that it could be more efficient, but it would be very helpfulto have some comments in the code and a description of "what is the problem you are trying to solve". It looks like you can setup some lists and process them more compactly.

On Tue, Jul 15, 2008 at 3:21 PM, stephen sefick <ssefick_at_gmail.com> wrote:
> # I am sure that I could be more efficient than this but how? Thanks in
> advance.
>
> #GPS in Decimal Degrees in the form longitude latitude
> RM215 <- matrix(c(-82.1461363, 33.5959109), nrow=1)
> SC <- matrix(c(-82.025888, 33.606454), nrow=1)
> RM202 <- matrix(c(-81.9906723, 33.5027653), nrow=1)
> RM198 <- matrix(c(-81.926823, 33.4634678), nrow=1)
> HC <- matrix(c(-81.920505, 33.46192), nrow=1)
> RM190 <- matrix(c(-81.9317347, 33.3839097), nrow=1)
> BC <- matrix(c(-81.948189, 33.373043), nrow=1)
> RM185 <- matrix(c(-81.941, 33.3453), nrow=1)
> RM179 <- matrix(c(-81.890929, 33.317914), nrow=1)
> RM148 <- matrix(c(-81.7547337, 33.1514072), nrow=1)
> RM119 <- matrix(c(-81.501919, 32.94038), nrow=1)
> RM61 <- matrix(c(-81.262388, 32.524739), nrow=1)
>
> RM215.sp <- SpatialPoints(RM215, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> d060101 <- as.POSIXct("2006-01-01", tz="EST")
> study_seq <- seq(from=d060101, length.out=761, by="days")
> up.215 <- sunriset(RM215.sp, study_seq, direction="sunrise",
> POSIXct.out=TRUE)
> down.215 <- sunriset(RM215.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> SC.sp <- SpatialPoints(SC, proj4string=CRS("+proj=longlat +datum=WGS84"))
> up.SC <- sunriset(SC.sp, study_seq, direction="sunrise", POSIXct.out=TRUE)
> down.SC <- sunriset(SC.sp, study_seq, direction="sunset", POSIXct.out=TRUE)
>
> RM202.sp <- SpatialPoints(RM202, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> up.202 <- sunriset(RM202.sp, study_seq, direction="sunrise",
> POSIXct.out=TRUE)
> down.202 <- sunriset(RM202.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> RM198.sp <- SpatialPoints(RM198, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> up.198 <- sunriset(RM198.sp, study_seq, direction="sunrise",
> POSIXct.out=TRUE)
> down.198 <- sunriset(RM198.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> HC.sp <- SpatialPoints(HC, proj4string=CRS("+proj=longlat +datum=WGS84"))
> up.HC <- sunriset(HC.sp, study_seq, direction="sunrise", POSIXct.out=TRUE)
> down.HC <- sunriset(HC.sp, study_seq, direction="sunset", POSIXct.out=TRUE)
>
> RM190.sp <- SpatialPoints(RM190, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> up.190 <- sunriset(RM190.sp, study_seq, direction="sunrise",
> POSIXct.out=TRUE)
> down.190 <- sunriset(RM190.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> BC.sp <- SpatialPoints(BC, proj4string=CRS("+proj=longlat +datum=WGS84"))
> up.BC <- sunriset(BC.sp, study_seq, direction="sunrise", POSIXct.out=TRUE)
> down.BC <- sunriset(BC.sp, study_seq, direction="sunset", POSIXct.out=TRUE)
>
> RM185.sp <- SpatialPoints(RM185, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> up.185 <- sunriset(RM185.sp, study_seq, direction="sunrise",
> POSIXct.out=TRUE)
> down.185 <- sunriset(RM185.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> RM179.sp <- SpatialPoints(RM179, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> up.179 <- sunriset(RM179.sp, study_seq, direction="sunrise",
> POSIXct.out=TRUE)
> down.179 <- sunriset(RM179.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> RM148.sp <- SpatialPoints(RM148, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> up.148 <- sunriset(RM148.sp, study_seq, direction="sunrise",
> POSIXct.out=TRUE)
> down.148 <- sunriset(RM148.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> RM119.sp <- SpatialPoints(RM119, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> up.119 <- sunriset(RM119.sp, study_seq, direction="sunrise",
> POSIXct.out=TRUE)
> down.119 <- sunriset(RM119.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> RM61.sp <- SpatialPoints(RM61, proj4string=CRS("+proj=longlat
> +datum=WGS84"))
> up.61 <- sunriset(RM61.sp, study_seq, direction="sunrise", POSIXct.out=TRUE)
> down.61 <- sunriset(RM61.sp, study_seq, direction="sunset",
> POSIXct.out=TRUE)
>
> sunriseset <- cbind(as.data.frame(up.215$time),
> as.data.frame(down.215$time), as.data.frame(up.SC$time),
> as.data.frame(down.SC$time),
> as.data.frame(up.202$time), as.data.frame(down.202$time),
> as.data.frame(up.198$time), as.data.frame(down.198$time),
> as.data.frame(up.HC$time), as.data.frame(down.HC$time),
> as.data.frame(up.190$time), as.data.frame(down.190$time),
> as.data.frame(up.BC$time),
> as.data.frame(down.BC$time), as.data.frame(up.185$time),
> as.data.frame(down.185$time),
> as.data.frame(up.179$time), as.data.frame(down.179$time),
> as.data.frame(up.148$time), as.data.frame(down.148$time),
> as.data.frame(up.119$time), as.data.frame(down.119$time),
> as.data.frame(up.61$time), as.data.frame(down.61$time))
> colnames(sunriseset) <- c("RM215sr", "RM215ss","SCsr", "SCss","RM202sr",
> "RM202ss" ,"RM198sr", "RM198sr",
> "HCsr", "HCsr", "RM190sr", "RM190ss","BCsr","BCss","RM185sr",
> "RM185ss","RM179sr", "RM179sss",
> "RM148sr", "RM148ss","RM119sr", "RM119ss","RM61sr", "RM61sr")
>
> --
> Let's not spend our time and resources thinking about things that are so
> little or so large that all they really do for us is puff us up and make us
> feel like gods. We are mammals, and have not exhausted the annoying little
> problems of being mammals.
>
> -K. Mullis
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 15 Jul 2008 - 22:23:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Jul 2008 - 00:32:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive