lapply(1:10, function(i) (dataframe[ ,-i])
set.seed(13)
x <- sample(1:100, 15)
y <- sapply(seq_along(x), function(i) mean(x[-i]))
y
# this gives us a vector of means for x as
# each element is removed from the vector
set.seed(15)
dat <- data.frame(matrix(sample(0:1, 25, TRUE), 5, 5))
rownames(dat) <- 1:5; names(dat) <- paste("item", 1:5, sep="")
require(CTT)
CTT2 <- reliability(dat)
DF <- data.frame(item.num = paste("item", 1:5, sep=""),
adj_cron_alpha = CTT2$alpha.if.deleted,
adj_tot_cor = CTT2$pbis)
names(CTT2)#gives lots of goodies but not the scale mean or sd if deleted for each item
#FIX (first create function(s) that feeds the data set gets the sd & mean stats)
mean.if.deleted <- function(x){
y <- reliability(x)
c(y$scale.mean)
}
sd.if.deleted <- function(x){
y <- reliability(x)
c(y$scale.sd)
}
#now the use of negative indexing to copute a new data set with out each item and feed it to the functions
DF$mean.if.delete <- sapply(1:length(dat), function(x) mean.if.deleted(dat[, -x]))
DF$sd.if.delete <- sapply(1:length(dat), function(x) sd.if.deleted(dat[, -x]))
DF
> (groupA <- rnorm(5))
[1] -0.9445818 0.9587041 -0.5147924 -0.9498970 -0.5534835
> (groupB <- rnorm(5))
[1] 0.08415508 0.14757817 -1.29038128 0.74918147 0.04405623
> stack(list(A = groupA, B = groupB))
values ind
1 -0.94458179 A
2 0.95870412 A
3 -0.51479240 A
4 -0.94989702 A
5 -0.55348354 A
6 0.08415508 B
7 0.14757817 B
8 -1.29038128 B
9 0.74918147 B
10 0.04405623 B
## Making babies - or fake data... I forget.
j <- lapply(1:10, rnorm, n=4)
## My typical way of flattening into
## a matrix/dataframe
do.call(rbind, j)
## Can do this with plyr relatively easily too
library(plyr)
## Either using I
ldply(j, I)
## or just returning the vector...
ldply(j, function(x){x})
## Making babies - or fake data... I forget.
j <- lapply(1:10, rnorm, n=4)
# This one?
do.call(rbind, j)[,1]
# Or this guy.
sapply(j, function(x){x[1]})
install.packages("PATH/TO/THE/.tar.gz/FILE/LIKE:/SVGAnnotation.tar.gz", repos=NULL, type="source")
install.packages("PATH/TO/THE/.tar.gz/FILE/LIKE:/SVGAnnotation.tar.gz", repos=NULL, type="source")