Re: [R] Easy 'apply' question

2011-03-11 Thread Aaron Polhamus
ply(tf, 2, class)) > > ## using lapply() > (test <- lapply(tf, function(x) { > if(is.numeric(x)) mean(x) else unique(x)[1]})) > > > Hope this helps, > > Josh > > On Thu, Mar 10, 2011 at 5:11 PM, Aaron Polhamus > wrote: > > Dear list, > > > > I co

[R] Easy 'apply' question

2011-03-10 Thread Aaron Polhamus
Dear list, I couldn't find a solution for this problem online, as simple as it seems. Here's the problem: #Construct test dataframe tf <- data.frame(1:3,4:6,c("A","A","A")) #Try the apply function I'm trying to use test <- apply(tf,2,function(x) if(is.numeric(x)) mean(x) else unique(x)[1]) #Lo

[R] Difficult with round() function

2011-01-17 Thread Aaron Polhamus
(I am sure there is a far more elegant way to regrid data in R) or a simple fix for this rounding error. Many thanks in advance, Aaron -- Aaron Polhamus Statistical consultant, Revolution Analytics MSc Applied Statistics, The University of Oxford, 2009 838a NW 52nd St, Seattle, WA 98107 Cell: +1 (206) 3

Re: [R] Arrange elements on a matrix according to rowSums + short 'apply' Q

2010-12-02 Thread Aaron Polhamus
way to do your first step, but it works: > > MAT2 <- cbind(MAT, rowSums(MAT)) > > MAT[order(MAT2[,6], decreasing=TRUE),] > > > > For the second, I don't know! > > > > HTH, > > Ivan > > > > > > Le 12/2/2010 09:46, Aaron Po

[R] Arrange elements on a matrix according to rowSums + short 'apply' Q

2010-12-02 Thread Aaron Polhamus
Greetings, My goal is to create a Markov transition matrix (probability of moving from one state to another) with the 'highest traffic' portion of the matrix occupying the top-left section. Consider the following sample: inputData <- c( c(5, 3, 1, 6, 7), c(9, 7, 3, 10, 11), c(1, 2, 3,