addTrans <- function(color,trans)
{
# This function adds transparancy to a color.
# Define transparancy with an integer between 0 and 255
# 0 being fully transparant and 255 being fully visable
# Works with either color and trans a vector of equal length,
# or one of the two of length 1.
if (length(color)!=length(trans)&!any(c(length(color),length(trans))==1)) stop("Vector lengths not correct")
if (length(color)==1 & length(trans)>1) color <- rep(color,length(trans))
if (length(trans)==1 & length(color)>1) trans <- rep(trans,length(color))
num2hex <- function(x)
{
hex <- unlist(strsplit("0123456789ABCDEF",split=""))
return(paste(hex[(x-x%%16)/16+1],hex[x%%16+1],sep=""))
}
rgb <- rbind(col2rgb(color),trans)
res <- paste("#",apply(apply(rgb,2,num2hex),2,paste,collapse=""),sep="")
return(res)
}
dat <- list(A=1, B=2, C=3, D=4)
lapply(1:length(dat), function(i) {
assign(names(dat)[i], dat[[i]],envir=.GlobalEnv)
})
A
rm(A)
A
list2env(dat, .GlobalEnv)
A
! ./fcn1.f90
! A test function for trying out .Fortran in R:
! $gfortran -shared -o fcn1.dll fcn1.f90
! $ R
! Should give approx 2.7182818284590451
! Not the most exciting example but gives an idea
subroutine fcn(x,f1)
double precision x
double precision f1
f1 = exp(x)
end
dyn.load("./fcn1.dll")
is.loaded("fcn")
.Fortran("fcn", x=as.double(1.0), f=as.double(1.0))
lapply(res, sample, 5)
lapply(res, Vectorize(sample), 5)
lapply(res, sample, 5)
lapply(res, Vectorize(sample), 5)
> mydf <- data.frame(letters = letters, LETTERS = LETTERS)
> res <- list(mydf, mydf)
> lapply(res, Vectorize(sample), 5)
[[1]]
letters LETTERS
[1,] "e" "I"
[2,] "g" "C"
[3,] "y" "R"
[4,] "s" "S"
[5,] "t" "M"
[[2]]
letters LETTERS
[1,] "h" "O"
[2,] "e" "T"
[3,] "o" "Y"
[4,] "x" "Q"
[5,] "f" "U"
lapply(res, function(x) mapply(sample, x, 5))
lapply(lapply(res,unlist), sample, 5)