Displaying 10 results from an estimated 10 matches for "shanabrook".
2010 Jan 04
4
function in aggregate applied to specific columns only
I want to use aggregate with the mean function on specific columns
gender <- factor(c("m", "m", "f", "f", "m"))
student <- c(0001, 0002, 0003, 0003, 0001)
score <- c(50, 60, 70, 65, 60)
basicSub <- data.frame(student, gender, score)
basicSubMean <- aggregate(basicSub, by=list(basicSub$student), FUN=mean, na.rm=TRUE)
This
2010 Jun 15
4
shifted window of string
basically I need to create a sliding window in a string. a way to explain this is:
> v <-
2010 Aug 09
2
efficient matrix element comparison
It is a simple problem in that I simply want to convert the For loop to a more efficient method. It simply loops through a large vector checking if the numeric element is not equal to the index of that element. The following example demonstrates a simplified example:
> rows <- 10
> collusionM <- Matrix(0,10,10,sparse=TRUE)
> matchM <- matrix(c(1,2,3,4,4,6,7,9,9,10))
>
>
2010 Jan 30
2
aggregate by factor
I have a data frame with two columns, a factor and a numeric. I want to create data frame with the factor, its frequency and the median of the numeric column
> head(motifList)
events score
1 aeijm -0.25000000
2 begjm -0.25000000
3 afgjm -0.25000000
4 afhjm -0.25000000
5 aeijm -0.25000000
6 aehjm 0.08333333
To get the frequency table of events:
> motifTable <-
2009 Apr 04
2
data.frame, converting row data to columns
...ith reshaping the data frame
I think I had some success with the melt
x
=
melt
.data
.frame(bsub,id.vars=c("name","nLevel","emot"),measure.vars=c("wrist"))
But I can't figure out the cast to get the wrist values in the rows.
Thanks
ds
David H. Shanabrook
dhshanab@acad.umass.edu
256-1019 (home)
[[alternative HTML version deleted]]
2010 Aug 08
2
subset of string by index
How can I get a substring based on the index into the string?
strM <- c("abcde", "cdefg")
ind <- c(1,3,5)
I want to use ind to index into the strings so the result is:
strMind <- c("ace", "ceg")
2010 Mar 06
1
color2D.matplot not giving colors
I am using color2D.matplot to plot a matrix about 400 by 200.
The values in the matrix are 0:5 and NA. The resulting plot is not color, but shaded b/w. I tried to figure out how to add colors, I would like something like c(blue, green, red, cyan, green)
#example
motifx <- matrix(NA, nrow=100,ncol=20)
motifx[,1:5] <- 1
motifx[,6:10] <- 2
motifx[,11:15] <- 3
motifx[,15:19] <- 4
2010 Aug 22
1
spare matrix replacing values efficiently
I am working with a large sparse matrix trying replace all 1 values with 0. The normal method doesn't work. Here is a small example:
> x <- Matrix(0,nrow=10,ncol=10,sparse=TRUE)
> x[,1] <- 1:2
> x
10 x 10 sparse Matrix of class "dgCMatrix"
[1,] 1 . . . . . . . . .
[2,] 2 . . . . . . . . .
[3,] 1 . . . . . . . . .
[4,] 2 . . . . . . . . .
[5,] 1 . . . . . . . . .
2010 Jul 13
2
Checking for duplicate rows in data frame efficiently
I wrote something to check for duplicate rows in a data frame, but it is too inefficient. Is there a way to do this without the nested loops?
This code correctly indicates rows 1-7, 1-8, 2-9 and 7-8 are duplicates.
> m <- matrix(c(1,1,1,1,1, 2,2,2,2,2, 6,6,6,6,6, 3,3,3,3,3, 4,4,4,4,4, 5,5,5,5,5, 1,1,1,1,1, 1,1,1,1,1, 2,2,2,2,2, 7,7,7,7,7), ncol=5, byrow=TRUE)
> df <- data.frame(m)
2010 Aug 14
1
incrementing matrix elements more efficiently
I need to increment cells of a matrix (collusionM). The indexes to increment are in an index (matchIndex). This is some of the code
for (j in 1:(rows-1)) matchIndex[[j]] <- which(mx[j]==mx)
for (j in 1:(rows-1)) collisionM[j,matchIndex[[j]]] <- collisionM[j,matchIndex[[j]]] + 1
I could put them in the same loop but this is slower. The first for statement is fine. It finds the matches