of the features:
require(dprep)
data(diabetes)
outbox(diabetes,nclass=1)
"A big computer, a complex algorithm and a long time does not equal science." -- Robert Gentleman
lightdark <-function (color){
rgb <- col2rgb(color)/255
L <- c(0.2, 0.6, 0) %*% rgb
ifelse(L >= 0.2, "#000060", "#FFFFA0")
}
x <- sample(10:200,40)
y <- sample(20:100,40)
windows(width = max(x),height = max(y))
plot(x,y)
# try:
plot(x, y, asp = 1)
# or, better:
library(MASS)
eqscplot(x,y)
#or
library(lattice)
xyplot(y ~ x, aspect = "iso")
A = matrix(c("a","b","c","d","e","u","v",rep("x",3)),5,2,byrow=F)
unique(A[, 2])
$ R CMD BATCH [options] my_script.R [outfile]
$ nohup nice -n 14 R CMD BATCH myRfile.R &
##################################
#!/bin/sh
cd $PBS_O_WORKDIR
R CMD BATCH --no-save my_script.R
##################################
$ qsub my_script.sh
desc <- function(mydata) {
require(e1071)
quantls <- quantile(x=mydata, probs=seq(from=0, to=1, by=0.25))
themean <- mean(mydata)
thesd <- sd(mydata)
kurt <- kurtosis(mydata)
skew <- skewness(mydata)
retlist <- list(Quantiles=quantls, Mean=themean,
StandDev=thesd,Skewness=skew, Kurtosis=kurt)
return(retlist)
}
# example
exampledata <- rnorm(10000)
summary(exampledata)
desc(exampledata)
varname <- c("a", "b", "d")
get(varname[1]) + 2
assign(varname[1], 2 + 2)
eval(substitute(lm(y ~ x + variable), list(variable = as.name(varname[1]))
vars <- list(a = 1:10, b = rnorm(100), d = LETTERS) vars[["a"]]
mx <- matrix(rnorm(100,1:100),10,10) vec <- c(mx)or
vec <- c(as.matrix(mx))or
dim(mx) <- NULL
ar1 <- array(data=c(1:16),dim=c(4,4))
ar2 <- array(data=c(1,2,3,3,5:16),dim=c(4,4))
z<-ar1==ar2
ar1
[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 4 8 12 16
ar2
[,1] [,2] [,3] [,4]
[1,] 1 5 9 13
[2,] 2 6 10 14
[3,] 3 7 11 15
[4,] 3 8 12 16
z
[,1] [,2] [,3] [,4]
[1,] TRUE TRUE TRUE TRUE
[2,] TRUE TRUE TRUE TRUE
[3,] TRUE TRUE TRUE TRUE
[4,] FALSE TRUE TRUE TRUE
which(z==FALSE)
[1] 4
apply(ar1==ar2,1,all)
x <- rnorm(1000) hist(x, freq = FALSE, col = "grey") curve(dnorm, col = 2, add = TRUE)
library(lessR) # generate 100 random normal data values y <- rnorm(100) # normal curve and general density curves superimposed over histogram # all defaults color.density(y)
x <- c(0.0001, 0.0059, 0.0855, 0.9082)
y <- c(0.54, 0.813, 0.379, 0.35)
# create a two row matrix with x and y
height <- rbind(x, y)
# Use height and set 'beside = TRUE' to get pairs
# save the bar midpoints in 'mp'
# Set the bar pair labels to A:D
mp <- barplot(height, beside = TRUE,
ylim = c(0, 1), names.arg = LETTERS[1:4])
# Nel caso generale, i.e., che si usa di
# solito (height MUST be a matrix)
mp <- barplot(height, beside = TRUE)
# Draw the bar values above the bars
text(mp, height, labels = format(height, 4),
pos = 3, cex = .75)
v <- c(1,1,2,3,4,6)
binc <- function(x){
l <- sum(x)+1
y <- c(1,rep(0,l-1))
for (i in x) y <- y+c(rep(0,i),y)[1:l]
}
out <- lapply(1:length(v), function(i) binc(v[1:i]))
nout <- max(sapply(out, length))
sapply(out, function(x) c(x, rep(0, nout - length(x))))
# I have 4 tables like this: satu <- array(c(5,15,20,68,29,54,84,119), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond"))) dua <- array(c(50,105,30,8,29,25,84,9), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond"))) tiga <- array(c(9,16,26,68,12,4,84,12), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond"))) empat <- array(c(25,13,50,78,19,34,84,101), dim=c(2,4), dimnames=list(c("Negative", "Positive"), c("Black", "Brown", "Red", "Blond"))) # rbind() the tables together TAB <- rbind(satu, dua, tiga, empat) # Do the barplot and save the bar midpoints mp <- barplot(TAB, beside = TRUE, axisnames = FALSE) # Add the individual bar labels mtext(1, at = mp, text = c("N", "P"), line = 0, cex = 0.5) # Get the midpoints of each sequential pair of bars # within each of the four groups at <- t(sapply(seq(1, nrow(TAB), by = 2), function(x) colMeans(mp[c(x, x+1), ]))) # Add the group labels for each pair mtext(1, at = at, text = rep(c("satu", "dua", "tiga", "empat"), 4), line = 1, cex = 0.75) # Add the color labels for each group mtext(1, at = colMeans(mp), text = c("Black", "Brown", "Red", "Blond"), line = 2)
cls <- function() { require(rcom) wsh <- comCreateObject("Wscript.Shell") comInvoke(wsh, "SendKeys", "\014") invisible(wsh) } cls()or
# An R function to clear the screen on RGui: cls <- function() { if (.Platform$GUI[1] != "Rgui") return(invisible(FALSE)) if (!require(rcom, quietly = TRUE)) # Not shown any way! stop("Package rcom is required for 'cls()'") wsh <- comCreateObject("Wscript.Shell") if (is.null(wsh)) { return(invisible(FALSE)) } else { comInvoke(wsh, "SendKeys", "\014") return(invisible(TRUE)) } } cls()
V <- c(1,1,2,3,4,6)
binc <- function(x){
l <- sum(x)+1
y <- c(1,rep(0,l-1))
for (i in x) y <- y+c(rep(0,i),y)[1:l]
}
out <- lapply(1:length(v), function(i) binc(v[1:i]))
nout <- max(sapply(out, length))
sapply(out, function(x) c(x, rep(0, nout - length(x))))
lls <- function (pos = 1, pat = "")
{
dimx <- function(dd) if (is.null(dim(dd)))
length(dd)
else dim(dd)
lll <- ls(pos = pos, pat = pat)
cat(formatC("mode", 1, 15), formatC("class", 1, 18),
formatC("name",1, max(nchar(lll)) + 1), "size\n-----------------------------------------------------------------\n")
if (length(lll) > 0)
{
for (i in 1:length(lll))
{
cat(formatC(eval(parse(t = paste("mode(", lll[i],
")"))), 1, 15), formatC(paste(eval(parse(t = paste("class(",
lll[i], ")"))), collapse = " "), 1, 18), formatC(lll[i],
1, max(nchar(lll)) + 1), " ", eval(parse(t = paste("dimx(", lll[i], ")"))), "\n")
}
}
}