l <- c("a", "b", "c", "d")
a <- factor(c("a", "c", "d"), levels = l, ordered = TRUE)
b <- factor(c("c", "b", "a"), levels = l, ordered = TRUE)
pmax(a, b)
## convert back and forth between -180/180 and 0/360 systems | |
to_lon_360 <- function(lon_180) { | |
(lon_180 + 360) %% 360 | |
} | |
to_lon_180 <- function(lon_360) { | |
((lon_360 + 180) %% 360) - 180 | |
} |
srctxt <- "http://data.giss.nasa.gov/gistemp/tabledata_v3/GLB.Ts+dSST.txt" | |
# Import as a character vector first so can get info about length etc. | |
aslines <- readLines(srctxt) | |
# Store the first occurrence of the header row as a character vector | |
header <- strsplit(aslines[8], "\\s+")[[1]] | |
# Count the lines of data (any lines starting with 4 digits) | |
nlines <- length(grep("^\\d{4}", aslines)) |
col2hex <- function(colour) { | |
col_rgb <- t(col2rgb(colour)) | |
rgb2hex(red = col_rgb[,1], green = col_rgb[,2], blue = col_rgb[,3]) | |
} | |
rgb2hex <- function(red, green, blue, rgbvec = NULL) { | |
if ((missing(red) || missing(green) || missing(blue)) && is.null(rgbvec)) { | |
stop("You must supply red, green, and blue OR rgbvec") | |
} |
#'Fill gaps in a date sequence | |
#' | |
#'Given a dataframe with one column as a date sequence, fill gaps in the dat sequence. | |
#' @param df Dataframe | |
#' @param date_col the column containing dates | |
#' @param interval The interval in the date sequence. If \code{NULL}, calculated automatically. | |
#' @param fill_cols Columns to fill with the value in the column (should be columns where value is same in every row, such as an ID.) | |
#' @export | |
#' @return dataframe with filled in dates | |
#' @examples \dontrun{ |
#' Populate the boilerplate roxygen template at the top of the function. | |
#' | |
#' Inspired by Karthik Ram's RTools Sublime Text 2 plugin: | |
#' https://github.com/karthik/Rtools | |
#' @param funfile path to the .R file containing the function | |
#' @param func the name of the function you want to document | |
#' @param export Is the function exported (default \code{TRUE})? If \code{FALSE} | |
#' keyword 'internal' is added | |
#' @export | |
#' @return nothing, but adds the roxygen template to the top of the file |
gawk -F, ' | |
BEGIN { OFS = ","; | |
print "id,name,date_time,val,val2,val3"} | |
{ | |
$3=gensub(/(^[0-9]{2})([A-Z]{3})([0-9]{4}):([0-9]{2}:[0-9]{2}:[0-9]{2})$/, | |
"\\3-\\2-\\1 \\4 PST","g",$3) | |
print $0 | |
}' testfile.csv |
```r | |
l <- c("a", "b", "c", "d") | |
a <- factor(c("a", "c", "d"), levels = l, ordered = TRUE) | |
b <- factor(c("c", "b", "a"), levels = l, ordered = TRUE) | |
pmax(a, b) | |
``` | |
``` |
l <- c("a", "b", "c", "d")
a <- factor(c("a", "c", "d"), levels = l, ordered = TRUE)
b <- factor(c("c", "b", "a"), levels = l, ordered = TRUE)
pmax(a, b)
## Makes a random animal deliver the error message | |
## Fun to put in a .Rprofile :) | |
# devtools::install_github("sckott/cowsay") | |
library("cowsay", quietly = TRUE) | |
options(error = function() { | |
animal <- say("", by = "random", type = "string") | |
## remove the top "-------" message delimiter from the cowsay character | |
message(strsplit(animal, "\n\\s*-{5,20}\\s*\n\\s*\n")[[1]][2]) | |
}) |
flengths <- system('exiftool -T -r -FocalLength -ext .NEF "."', intern=TRUE) | |
flengths.num <- as.numeric(strsplit(flengths, split=" mm")) | |
hist(flengths.num,breaks=20, main="Frequency of focal lengths used by Andy\nfor 1631 photos in the Galapagos Islands", xlab="Focal Length") |