Re: [R] indexing names for looping across computations done on pairs of matrices

2014-04-16 Thread Cade, Brian
A.K. Wonderful - thank you. The last set of code using sapply(), seq_along(), and get() worked like a charm and was what I was missing. Brian Brian S. Cade, PhD U. S. Geological Survey Fort Collins Science Center 2150 Centre Ave., Bldg. C Fort Collins, CO 80526-8818 email: ca...@usgs.gov t

Re: [R] indexing names for looping across computations done on pairs of matrices

2014-04-15 Thread arun
Hi, If the two pairs of matrices are in a list: set.seed(42) lst1 <- lapply(1:11, function(x) matrix(sample(40, 20, replace=TRUE), 5,4)) names(lst1) <- paste0("gs", paste0("4.",seq(0,100,by=10))) set.seed(585) lst2 <- lapply(1:11, function(x) matrix(sample(40, 20, replace=TRUE), 5,4)) names

[R] indexing names for looping across computations done on pairs of matrices

2014-04-15 Thread Cade, Brian
So I know I must be missing something simple and obvious for the following data manipulation where I have (in this example) 11 pairs of matrices (gs4.0 to gs4.100 and ps1.0 to ps1.100) from some population simulations (all with same dimensions) where I want to get some summary statistics on the pro

Re: [R] Indexing within by statement - different coloured lines in abline wanted..

2013-05-27 Thread Blaser Nello
abline(lm(Response1~Predictor,data=Site),col=colours[as.numeric(Site[1,1 ])]) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tom Wilding Sent: Montag, 27. Mai 2013 12:40 To: r-help@r-project.org Subject: [R] Indexing within by

Re: [R] Indexing within by statement - different coloured lines in abline wanted..

2013-05-27 Thread John Kane
; -Original Message- > From: tom.wild...@sams.ac.uk > Sent: Mon, 27 May 2013 10:39:58 + > To: r-help@r-project.org > Subject: [R] Indexing within by statement - different coloured lines in > abline wanted.. > > Dear R-list > > I'm trying to get

[R] Indexing within by statement - different coloured lines in abline wanted..

2013-05-27 Thread Tom Wilding
Dear R-list I'm trying to get each regression line, plotted using abline, to be of a different colour as the following code illustrates. I'm hoping there is a simple indexing solution. Many thanks. ## code from here colours=c("black","red","blue","green","pink") Mean=500;Sd=10;NosSites=5;Xaxi

Re: [R] indexing operation based upon a sequence

2013-02-07 Thread John Smith
j.brae...@uvt.nl > Sent: Thu, 7 Feb 2013 16:41:49 + > To: r-help@r-project.org > Subject: [R] indexing operation based upon a sequence > > Dear R-list, > > > We stumbled upon some weird problem when performing a simple indexing > operation. > Below some example code t

Re: [R] indexing operation based upon a sequence

2013-02-07 Thread Berend Hasselman
R-FAQ 7.31 Berend On 07-02-2013, at 17:41, "J. Braeken" wrote: > Dear R-list, > > > We stumbled upon some weird problem when performing a simple indexing > operation. > Below some example code to illustrate the issue > > #FAILS TO FIND .55 Oo > huh1 = seq(.1,.7,.15);huh1 > # [1] 0.10 0.25

[R] indexing operation based upon a sequence

2013-02-07 Thread J. Braeken
Dear R-list, We stumbled upon some weird problem when performing a simple indexing operation. Below some example code to illustrate the issue #FAILS TO FIND .55 Oo huh1 = seq(.1,.7,.15);huh1 # [1] 0.10 0.25 0.40 0.55 0.70 huh1 == .25 # [1] FALSE TRUE FALSE FALSE FALSE huh1 == .55 # [1] FALSE FA

Re: [R] indexing for Wilcoxon test (take 2)

2012-11-14 Thread arun
07 #[8] 0.45993107 0.39590760 A.K. - Original Message - From: Jeffrey Stratford To: Rui Barradas Cc: r-help@r-project.org Sent: Wednesday, November 14, 2012 1:01 PM Subject: Re: [R] indexing for Wilcoxon test (take 2) Hi everyone, I've been asked to run a number of Wilcoxon tests on some

Re: [R] indexing for Wilcoxon test (take 2)

2012-11-14 Thread Jeffrey Stratford
Hi everyone, I've been asked to run a number of Wilcoxon tests on some behavioral data (below is a sample). They want me to compare each trial to the first trial, considered the control trial. I know I can use brackets to index and select, for example, trial 1 vs. trial 4 (not exactly sure how to

Re: [R] indexing for Wilcoxon test (take 2)

2012-11-14 Thread Rui Barradas
Hello, Thanks for the data example. Try the following. sp <- split(dat, dat$trial) control <- sp[[1]] lapply(sp[-1], function(x) wilcox.test(control[["removed"]], x[["removed"]])) Hope this helps, Rui Barradas Em 14-11-2012 18:01, Jeffrey Stratford escreveu: Hi everyone, I've been asked t

Re: [R] indexing for Wilcoxon test

2012-11-14 Thread Rui Barradas
Hello, Use ?dput to post data, like this it's unreadable. For instance, dput(Mydata) # paste the output of this in a post. Hope this helps, Rui Barradas Em 14-11-2012 15:58, Jeffrey Stratford escreveu: Hi everyone, I've been asked to run a number of Wilcoxon tests on some behavioral data (b

[R] indexing for Wilcoxon test

2012-11-14 Thread Jeffrey Stratford
Hi everyone, I've been asked to run a number of Wilcoxon tests on some behavioral data (below is a sample). They want me to compare each trial to the first trial, considered the control trial. I know I can use brackets to index and select, for example, trial 1 vs. trial 4 (not exactly sure how to

Re: [R] indexing in data frames

2012-08-10 Thread peter dalgaard
ware > wdunlap tibco.com > > >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On >> Behalf >> Of R. Michael Weylandt >> Sent: Thursday, August 09, 2012 4:22 PM >> To: arun >> Cc: R help;

Re: [R] indexing in data frames

2012-08-09 Thread William Dunlap
tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of R. Michael Weylandt > Sent: Thursday, August 09, 2012 4:22 PM > To: arun > Cc: R help; jimi adams > Subject: Re: [R] indexing in data frames >

Re: [R] indexing in data frames

2012-08-09 Thread R. Michael Weylandt
On Thu, Aug 9, 2012 at 5:30 PM, arun wrote: > > lapply(1:length(a$c),function(x) a$b[x]-a$c[[x]]) Arun, I've seen you use this idiom a few times lately and I'd just like to note that seq_along() is an (underutilized) primitive and a safer and faster alternative (avoiding the pathological leng

Re: [R] indexing in data frames

2012-08-09 Thread arun
ab <- data.frame(ab, diff=ab$year-ab$d) >> new <- split(ab$diff, ab$group) >> new > $G1988 > [1] 3 6 4 > > $G1989 > [1] 1 9 > > -- > David L Carlson > Associate Professor of Anthropology > Texas A&M Univer

Re: [R] indexing in data frames

2012-08-09 Thread jimi adams
- > From: jimi adams > To: r-help@r-project.org > Cc: > Sent: Thursday, August 9, 2012 4:42 PM > Subject: [R] indexing in data frames > > I'm still not fully understanding exactly how R is handling data frames, but > am getting closer. Any help with this one will likel

Re: [R] indexing in data frames

2012-08-09 Thread arun
HI, In the reply I sent, I forgot to add, anew<-list()#before, for(i in 1:length(b1)){  anew[[i]]<-list()  anew[[i]]<-b1[[i]]-c[[i]]  } A.K. - Original Message - From: jimi adams To: r-help@r-project.org Cc: Sent: Thursday, August 9, 2012 4:42 PM Subject: [R] indexing in da

Re: [R] indexing in data frames

2012-08-09 Thread arun
-2 -6 A.K. - Original Message - From: jimi adams To: r-help@r-project.org Cc: Sent: Thursday, August 9, 2012 4:42 PM Subject: [R] indexing in data frames I'm still not fully understanding exactly how R is handling data frames, but am getting closer. Any help with this one will likely

Re: [R] indexing in data frames

2012-08-09 Thread arun
ge - From: jimi adams To: arun Cc: R help Sent: Thursday, August 9, 2012 5:42 PM Subject: Re: [R] indexing in data frames Thanks. Yes, I got it to work with loops for small data. I was just hoping, given the size of the data.frame (hundreds of thousands) and the length of the lists (varying

Re: [R] indexing in data frames

2012-08-09 Thread David L Carlson
> -Original Message- > From: David Winsemius [mailto:dwinsem...@comcast.net] > Sent: Thursday, August 09, 2012 5:17 PM > To: dcarl...@tamu.edu > Cc: 'jimi adams'; r-help@r-project.org > Subject: Re: [R] indexing in data frames > > > On Aug 9, 2012, at 2:43 PM, D

Re: [R] indexing in data frames

2012-08-09 Thread David Winsemius
$year-ab$d) new <- split(ab$diff, ab$group) new $G1988 [1] 3 6 4 $G1989 [1] 1 9 -- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project

Re: [R] indexing in data frames

2012-08-09 Thread David L Carlson
p) > new $G1988 [1] 3 6 4 $G1989 [1] 1 9 -- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- >

[R] indexing in data frames

2012-08-09 Thread jimi adams
I'm still not fully understanding exactly how R is handling data frames, but am getting closer. Any help with this one will likely go a long way in getting me there. Let's say I have a data frame, let's call it "a". Within that data frame i have two variables, let's call them "b" and "c", where

Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there "faster alternatives"?

2012-06-26 Thread Søren Højsgaard
2012 01:20 To: Duncan Murdoch Cc: r-help@r-project.org Subject: Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there "faster alternatives"? Dear Duncan Thanks for your suggestion, but I really need sparse matrices: I have implemented various gr

Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there "faster alternatives"?

2012-06-26 Thread Søren Højsgaard
), columns=c("test", "replications", "elapsed", "relative"), replications=5) ---- -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: 25. juni 2012 11:27 To: Søren Hø

Re: [R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there "faster alternatives"?

2012-06-25 Thread Duncan Murdoch
On 12-06-24 4:50 PM, Søren Højsgaard wrote: Dear all, Indexing matrices from the Matrix package with [i,j] seems to be very slow. For example: library(rbenchmark) library(Matrix) mm<- matrix(c(1,0,0,0,0,0,0,0), nr=20, nc=20) MM<- as(mm, "Matrix") lookup<- function(mat){ for (i in

[R] Indexing matrices from the Matrix package with [i, j] seems to be very slow. Are there "faster alternatives"?

2012-06-24 Thread Søren Højsgaard
Dear all, Indexing matrices from the Matrix package with [i,j] seems to be very slow. For example: library(rbenchmark) library(Matrix) mm <- matrix(c(1,0,0,0,0,0,0,0), nr=20, nc=20) MM <- as(mm, "Matrix") lookup <- function(mat){ for (i in 1:nrow(mat)){ for (j in 1:ncol(mat)){

Re: [R] Indexing Grouped Data

2012-06-13 Thread William Dunlap
> Behalf > Of Peter Maclean > Sent: Wednesday, June 13, 2012 7:15 AM > To: R mailing list > Subject: Re: [R] Indexing Grouped Data > > I need help in indexing grouped data. In this excample (df1 data), the first > child had a > first immunization at age 2. The second c

Re: [R] Indexing Grouped Data

2012-06-13 Thread Peter Maclean
I need help in indexing grouped data. In this excample (df1 data), the first child had a first immunization at age 2. The second child had the first, second and third immunization at age 5,10, and 12, the third child had first and second immunization at age 4 and 6 and the fourth child had the f

[R] Indexing in summaryBy

2012-05-15 Thread Julian Wucherpfennig
I'm trying to use a self-written function with the summaryBy function (doBy package). I have lots of data from Monte Carlo experiments comparing different estimators across different (combinations of) parameter values, similar to the following form: colnames(mydata) <- c("X", "b0", "b1", # parame

Re: [R] indexing in a function doesn't work?

2012-04-06 Thread Benjamin Caldwell
Josh Apologies I haven't responded earlier. This looks great - I ended up doing what I needed done piece-by-piece because of a looming deadline, but understanding this code and your suggestions below will be a weekend project. Many thanks for all your help. * * Best Ben On Tue, Apr 3, 2012 at 8

Re: [R] indexing data.frame columns

2012-04-05 Thread Milan Bouchet-Valat
Le jeudi 05 avril 2012 à 12:40 -0700, Peter Meilstrup a écrit : > Consider the data.frame: > > df <- data.frame(A = c(1,4,2,6,7,3,6), B= c(3,7,2,7,3,5,4), C = > c(2,7,5,2,7,4,5), index = c("A","B","A","C","B","B","C")) > > I want to select the column specified in 'index' for every row of 'df', to

Re: [R] indexing data.frame columns

2012-04-05 Thread ilai
On Thu, Apr 5, 2012 at 1:40 PM, Peter Meilstrup wrote: > Consider the data.frame: > > df <- data.frame(A = c(1,4,2,6,7,3,6), B= c(3,7,2,7,3,5,4), C = > c(2,7,5,2,7,4,5), index = c("A","B","A","C","B","B","C")) > > I want to select the column specified in 'index' for every row of 'df', to > get > >

[R] indexing data.frame columns

2012-04-05 Thread Peter Meilstrup
Consider the data.frame: df <- data.frame(A = c(1,4,2,6,7,3,6), B= c(3,7,2,7,3,5,4), C = c(2,7,5,2,7,4,5), index = c("A","B","A","C","B","B","C")) I want to select the column specified in 'index' for every row of 'df', to get goal <- c(1, 7, 2, 2, 3, 5, 5) This sounds a lot like the indexing-by

Re: [R] indexing in a function doesn't work?

2012-04-03 Thread Joshua Wiley
Hi Benjamin, You seem to have the right basic ideas, but a lot of your code had typos and some logic flaws that I guess came from trying to move from just code to in a function. I attached the changes I made. What I would strongly encourage you to do, is work through each of the little functions

Re: [R] indexing in a function doesn't work?

2012-04-02 Thread Benjamin Caldwell
Petr, You can get an example dataset at http://dl.dropbox.com/u/3845242/torhelp.csv. I'll look at the rest of your suggestions in the morning, thanks for taking a look at it. Ben * * On Mon, Apr 2, 2012 at 10:33 PM, Petr PIKAL wrote: > Hi > > There is some mismatch in curly braces in your plo

Re: [R] indexing in a function doesn't work?

2012-04-02 Thread Petr PIKAL
Hi There is some mismatch in curly braces in your plotter function but when I try to use it I get > plotter(10,3,fram=rwb,framvec=rwb$prcnt.char.depth,obj=prcnt.char.depth,form1= + post.f.crwn.length~shigo.av,form2=post.f.crwn.length~shigo.av-1, + form3=leaf.area~(1/exp(shigo.av*x))*n,type=2,xl

Re: [R] indexing in a function doesn't work?

2012-04-01 Thread Benjamin Caldwell
Josh, Many thanks - here's a subset of the data and a couple examples: plotter(10,3,fram=rwb,framvec=rwb$prcnt.char.depth,obj=prcnt.char.depth,form1= post.f.crwn.length~shigo.av,form2=post.f.crwn.length~shigo.av-1, form3=leaf.area~(1/exp(shigo.av*x))*n,type=2,xlm=70,ylm=35) plotter(10,3,fram=rwb

Re: [R] indexing in a function doesn't work?

2012-04-01 Thread Joshua Wiley
Hi, Glancing through your code it was not immediately obvious to me why it does not work, but I can see a lot of things that could be simplified. It would really help if you could give us a reproducible example. Find/upload/create (in R) some data, and examples of how you would use the function.

[R] indexing in a function doesn't work?

2012-04-01 Thread Benjamin Caldwell
Hello, I've written a small function that's supposed to save me some time, and it's ending up killing it- the intention is to iteratively subset a dataset fram on framevec, fit a model (either lm or nls depending on type) and return the r2 or AIC from the model, respectively. Although as far as I

Re: [R] indexing??

2012-02-29 Thread helin_susam
Thanks, Dear Petr Savick. Your help is enough to solve my problem. With your help I've dealt with the problem. Many thanks for your effort, Sincerely, Helin -- View this message in context: http://r.789695.n4.nabble.com/indexing-tp4428210p4431168.html Sent from the R help mailing list archiv

Re: [R] indexing??

2012-02-29 Thread Petr Savicky
On Tue, Feb 28, 2012 at 11:42:32AM -0800, helin_susam wrote: > Dear Petr Savicky, > > Actually, this is based on jackknife after bootstrap algorithm. In summary, > > I have a data set, and I want to compute some values by using this > algorithm. > > Firstly, using bootstrap, I create some bootst

Re: [R] indexing??

2012-02-28 Thread helin_susam
Dear Petr Savicky, Actually, this is based on jackknife after bootstrap algorithm. In summary, I have a data set, and I want to compute some values by using this algorithm. Firstly, using bootstrap, I create some bootstrap re-samples. This step O.K. Then, for each data point within these re-samp

Re: [R] indexing??

2012-02-28 Thread Petr Savicky
On Tue, Feb 28, 2012 at 08:50:45AM -0800, helin_susam wrote: > Dear Petr Pikal and Petr Savicky thank you for your replies.. > > If the y vector contains different elements my algorithm gives this result; > y <- c(1,2,3,4,5,6,7,8,9,10) > x <- c(1,0,0,1,1,0,0,1,1,0) > > n <- length(x) > > t <-

Re: [R] indexing??

2012-02-28 Thread Petr Savicky
On Tue, Feb 28, 2012 at 08:50:45AM -0800, helin_susam wrote: > Dear Petr Pikal and Petr Savicky thank you for your replies.. > > If the y vector contains different elements my algorithm gives this result; > y <- c(1,2,3,4,5,6,7,8,9,10) > x <- c(1,0,0,1,1,0,0,1,1,0) > > n <- length(x) > > t <-

Re: [R] indexing??

2012-02-28 Thread helin_susam
Dear Petr Pikal and Petr Savicky thank you for your replies.. If the y vector contains different elements my algorithm gives this result; y <- c(1,2,3,4,5,6,7,8,9,10) x <- c(1,0,0,1,1,0,0,1,1,0) n <- length(x) t <- matrix(cbind(y,x), ncol=2) z = x+y for(j in 1:length(x)) { out <- vector(

Re: [R] indexing??

2012-02-28 Thread Petr Savicky
On Tue, Feb 28, 2012 at 05:59:24AM -0800, helin_susam wrote: > Hello All, > > My algorithm as follows; > y <- c(1,1,1,0,0,1,0,1,0,0) > x <- c(1,0,0,1,1,0,0,1,1,0) > > n <- length(x) > > t <- matrix(cbind(y,x), ncol=2) > > z = x+y > > for(j in 1:length(x)) { > out <- vector("list", ) > > for(i

Re: [R] indexing??

2012-02-28 Thread Petr PIKAL
Hi > > My algorithm as follows; > y <- c(1,1,1,0,0,1,0,1,0,0) > x <- c(1,0,0,1,1,0,0,1,1,0) > > n <- length(x) > > t <- matrix(cbind(y,x), ncol=2) Do not use t, it is a function for transposing matrix and after you redefine it you can get nasty surprise in future. tt <- cbind(y,x) is enough

[R] indexing??

2012-02-28 Thread helin_susam
Hello All, My algorithm as follows; y <- c(1,1,1,0,0,1,0,1,0,0) x <- c(1,0,0,1,1,0,0,1,1,0) n <- length(x) t <- matrix(cbind(y,x), ncol=2) z = x+y for(j in 1:length(x)) { out <- vector("list", ) for(i in 1:10) { t.s <- t[sample(n,n,replace=T),] y.s <- t.s[,1] x.s <- t.s[,2] z.s <- y.s+x.s

Re: [R] indexing by empty string (was RE: Error in predict.randomForest ... subscript out of bounds with NULL name in X)

2012-02-01 Thread Liaw, Andy
help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Ista Zahn > Sent: Wednesday, February 01, 2012 5:45 AM > To: r-help@r-project.org > Subject: Re: [R] indexing by empty string (was RE: Error in > predict.randomForest ... subscript out of bounds with NULL

Re: [R] indexing by empty string (was RE: Error in predict.randomForest ... subscript out of bounds with NULL name in X)

2012-02-01 Thread Ista Zahn
Hi Andy, On Tuesday, January 31, 2012 08:44:13 AM Liaw, Andy wrote: > I'm not exactly sure if this is a problem with indexing by name; i.e., is > the following behavior by design? The problem is that names or dimnames > that are empty seem to be treated differently, and one can't index by them: >

[R] indexing by empty string (was RE: Error in predict.randomForest ... subscript out of bounds with NULL name in X)

2012-01-31 Thread Liaw, Andy
I'm not exactly sure if this is a problem with indexing by name; i.e., is the following behavior by design? The problem is that names or dimnames that are empty seem to be treated differently, and one can't index by them: R> junk = 1:3 R> names(junk) = c("a", "b", "") R> junk a b 1 2 3 R> j

Re: [R] Indexing multi-dimensional table

2011-12-22 Thread David A Vavra
>From: William Dunlap [mailto:wdun...@tibco.com] >You can build the 2nd argument to do.call with alist() instead. >alist() produces a list that you can use c() and subscripting on >to add or modify arguments. It is usually better to encapsulate >this sort of thing in a function like extract() tha

Re: [R] Indexing multi-dimensional table

2011-12-22 Thread William Dunlap
nction like extract() that has a convenient interface. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of davavra > Sent: Thursday, December 22, 2011 10:31 AM >

Re: [R] Indexing multi-dimensional table

2011-12-22 Thread davavra
>From help("[", package="base"): "An index value of NULL is treated as > if it were integer(0).". Yeah, I should have read it better. >I don't think there is an easy way to achieve: > y[,2:3,1,drop=FALSE] > using do.call("[") without explicitly specify the indices for that > "missing" dimensio

Re: [R] Indexing multi-dimensional table

2011-12-22 Thread David A Vavra
> (This does imply you knew the number of dimensions was 3.) Yes, at run time. >It looks as though the Nulls became 0's. So if you wanted to use >do.call(`[` then this succeeds: > do.call(`[`, list(tbl, x, 1:dim(tbl)[2], 1:dim(tbl)[3]) ) ... >As does this using the "empty comma" approach: >

Re: [R] Indexing multi-dimensional table

2011-12-22 Thread David Winsemius
On Dec 21, 2011, at 10:34 PM, David A Vavra wrote: I want to take slices of a multi-dimensional table (or array) without knowing the number of dimensions in advance. As a test I tried using (in this example a 3d table): do.call(`[`, list(tbl, x,NULL,NULL)] Surely that was meant to be:

Re: [R] Indexing multi-dimensional table

2011-12-22 Thread Henrik Bengtsson
On Thu, Dec 22, 2011 at 4:34 AM, David A Vavra wrote: > I want to take slices of a multi-dimensional table (or array) without > knowing the number of dimensions in advance. > > > > As a test I tried using (in this example a 3d table): > > > >     do.call(`[`, list(tbl, x,NULL,NULL)] > > > > where

[R] Indexing multi-dimensional table

2011-12-22 Thread David A Vavra
I want to take slices of a multi-dimensional table (or array) without knowing the number of dimensions in advance. As a test I tried using (in this example a 3d table): do.call(`[`, list(tbl, x,NULL,NULL)] where I built the list on the fly. It works great as long as I only want th

[R] Indexing Permutation Values

2011-08-15 Thread Edward Patzelt
R-help - This code iterates over a function with 2 free parameters to find a list of values (which are the number of incorrect predictions for a computational model). I want to find the values of i,e when there is the minimum number of incorrect predictions. In other words, the value of "i" and

Re: [R] Indexing problem with matrix

2011-07-22 Thread Bogaso Christofer
Thanks Joshua and Berton for your pointers. Yes it was typo as I wanted to mean to select few columns. -Original Message- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: 22 July 2011 22:02 To: Bogaso Christofer Cc: r-help@r-project.org Subject: Re: [R] Indexing problem with

Re: [R] Indexing problem with matrix

2011-07-22 Thread Bert Gunter
See the "drop" argument (and link) in ?"[" -- Bert On Fri, Jul 22, 2011 at 9:46 AM, Bogaso Christofer wrote: > Dear all, assume I have a matrix with just 1 row. Now suppose I want to > fetch 1st few rows from that matrix, however resulting object becomes > vector. Here is 1 such example: > > >

Re: [R] Indexing problem with matrix

2011-07-22 Thread Joshua Wiley
On Fri, Jul 22, 2011 at 9:46 AM, Bogaso Christofer wrote: > Dear all, assume I have a matrix with just 1 row. Now suppose I want to > fetch 1st few rows from that matrix, however resulting object becomes I'm assuming you mean the first few columns. The place to look is ?"[" where you would find

[R] Indexing problem with matrix

2011-07-22 Thread Bogaso Christofer
Dear all, assume I have a matrix with just 1 row. Now suppose I want to fetch 1st few rows from that matrix, however resulting object becomes vector. Here is 1 such example: > matrix(1:5, 1) [,1] [,2] [,3] [,4] [,5] [1,]12345 > > matrix(1:5, 1)[,-1] [1] 2 3 4 5

Re: [R] Indexing to insert values from a dataframe into a matrix

2011-06-29 Thread Sarah Goslee
Hi Daisy, You've got a conceptual problem and a couple of practical ones, I think. On Tue, Jun 28, 2011 at 9:29 PM, Daisy Englert Duursma wrote: > Hello, > > I think this is a simple problem but I am not coming up with a simple > solution. I think it just an indexing problem. > > I can easily re

Re: [R] Indexing to Insert values from a dataframe into a matrix

2011-06-28 Thread Daisy Englert Duursma
Thanks, that worked like a charm. Daisy On Wed, Jun 29, 2011 at 11:47 AM, David Winsemius wrote: > > On Jun 28, 2011, at 9:18 PM, Daisy Englert Duursma wrote: > >> Hello, >> >> I think this is a simple problem but I am not coming up with a simple >> solution. I think it just an indexing problem.

Re: [R] Indexing to insert values from a dataframe into a matrix

2011-06-28 Thread Jeff Newmiller
A) Relying on floating point numbers for predictable indexing is a recipe for failure. Convert your floating point numbers to integers before using them to index. B) Row and column labels are strings, and you are giving numerics to the brackets. You would need to use as.character() on ddr$x and

Re: [R] Indexing to Insert values from a dataframe into a matrix

2011-06-28 Thread David Winsemius
On Jun 28, 2011, at 9:18 PM, Daisy Englert Duursma wrote: Hello, I think this is a simple problem but I am not coming up with a simple solution. I think it just an indexing problem. I can easily replace values in a matrix from a dataframe when the dataframe has row and column numbers. In the

[R] Indexing to insert values from a dataframe into a matrix

2011-06-28 Thread Daisy Englert Duursma
Hello, I think this is a simple problem but I am not coming up with a simple solution. I think it just an indexing problem. I can easily replace values in a matrix from a dataframe when the dataframe has row and column numbers. In the example below I use row and column names and  I can not get it

[R] Indexing to Insert values from a dataframe into a matrix

2011-06-28 Thread Daisy Englert Duursma
Hello, I think this is a simple problem but I am not coming up with a simple solution. I think it just an indexing problem. I can easily replace values in a matrix from a dataframe when the dataframe has row and column numbers. In the example below I use row and column names and I can not get it

[R] indexing with which, logical indexing, and missing values

2011-06-28 Thread Juliet Hannah
I have a data frame in which missing values exist, and I need to recode the string "missing" to a missing value. For the example, let's assume I cannot do this while reading it in. Even though this has been discussed extensively, I'm still a little confused about when to index with "which" and when

[R] indexing an array of lists: any nicer way?

2011-05-20 Thread Marius Hofert
Dear expeRts, I'm struggling a bit with arrays of lists. The nice thing about arrays is that one can easily access subsets. For example: arr. <- array(1:24, dim=c(2,3,4), dimnames=list(a=c("a1","a2"), b=c("b1","b2","b3"), c=c("c1","c2","c3","c4"))) arr.[,,4] me

Re: [R] indexing into a data.frame using another data.frame that also contains values for replacement

2011-05-01 Thread David Winsemius
On Apr 30, 2011, at 4:18 PM, Alice Wines wrote: Hello all, I have a quandry I have been scratching my head about for a while. I've searched the manual and the web and have not been able to find an acceptable result, so I am hoping for some help. I have two data frames and I want to in

Re: [R] indexing into a data.frame using another data.frame that also contains values for replacement

2011-04-30 Thread Dennis Murphy
Hi: Here are two possibilities: df1 <- data.frame(rows=c("A","B","C", "B", "C", "A"), columns=c("21_2", "22_2", "23_2", "21_2", "22_2", "23_2"), values=c(3.3, 2.5, 67.2, 44.3, 53, 66)) with(df1, xtabs(values ~ rows + columns)) columns rows 21_2 22_2 23_2 A 3.3 0.0 66.0 B 44.3 2.

Re: [R] indexing into a data.frame using another data.frame that also contains values for replacement

2011-04-30 Thread Berend Hasselman
Alice Wines wrote: > > Hello all, > > I have a quandry I have been scratching my head about for a > while. I've searched the manual and the web and have not been able to > find an acceptable result, so I am hoping for some help. > > I have two data frames and I want to index into the

[R] indexing into a data.frame using another data.frame that also contains values for replacement

2011-04-30 Thread Alice Wines
Hello all, I have a quandry I have been scratching my head about for a while. I've searched the manual and the web and have not been able to find an acceptable result, so I am hoping for some help. I have two data frames and I want to index into the first using the second, and replace t

Re: [R] indexing list elements with lapply?

2011-04-22 Thread Jorge Ivan Velez
Dear Simon, Try any of the following: sapply(r, function(l) l[,2] / l[1, 2]) lapply(r, function(l) l[,2] / l[1, 2]) HTH, Jorge On Fri, Apr 22, 2011 at 5:52 PM, Simon Kiss <> wrote: > Dear colleagues, > I have a list that looks like what the code below produces. I need a > function to go thr

[R] indexing list elements with lapply?

2011-04-22 Thread Simon Kiss
Dear colleagues, I have a list that looks like what the code below produces. I need a function to go through each list element and work on the second column of each list element (the first column is irrelevant to me...if the proposed function works on the first column as a consequence of a wri

Re: [R] Indexing from two variables

2011-02-02 Thread Sarah Goslee
That's kind of hard to follow without example data, but have you looked at merge() ? On Wed, Feb 2, 2011 at 1:31 PM, Ross Dunne wrote: > Hello, thank you all for your patience and time > > I am essentially trying to get disorganised data into long form for linear > modelling. > > I have 2 datafr

[R] Indexing from two variables

2011-02-02 Thread Ross Dunne
Hello, thank you all for your patience and time I am essentially trying to get disorganised data into long form for linear modelling. I have 2 dataframes "rec" and "book" Each row in "book" needs to be pasted onto the end of several of the rows of "rec" according to two variables in the row:"

Re: [R] Indexing from two variables

2011-02-02 Thread Ista Zahn
Hard to know exactly without seeing the structrure of rec and book, but I would start with ?merge Best, Ista On Wed, Feb 2, 2011 at 2:06 PM, dunner wrote: > > Hello, thank you all for your patience and time > > I am essentially trying to get disorganised data into long form for linear > modellin

[R] Indexing from two variables

2011-02-02 Thread dunner
Hello, thank you all for your patience and time I am essentially trying to get disorganised data into long form for linear modelling. I have 2 dataframes "rec" and "book" Each row in "book" needs to be pasted onto the end of several of the rows of "rec" according to two variables in the row:" M

Re: [R] indexing lists

2010-11-15 Thread David Winsemius
On Nov 15, 2010, at 7:58 PM, Chris Carleton wrote: Thanks for the suggestions, but 'cat' is not causing name space conflicts for me install.packages( library(fortunes) fortune("dog") and since I'm not packaging the code for anyone else to use, I'm less than concerned about potential confl

Re: [R] indexing lists

2010-11-15 Thread Chris Carleton
Thanks for the suggestions, but 'cat' is not causing name space conflicts for me and since I'm not packaging the code for anyone else to use, I'm less than concerned about potential conflicts. I did type that too quickly, and I have resolved my problem using a workaround that does not involve findi

Re: [R] indexing lists

2010-11-15 Thread David Winsemius
On Nov 15, 2010, at 5:07 PM, Chris Carleton wrote: Thanks for the suggestions. The issue for me is that the top level index is also like a database key so it might be a bit annoying to coerce it to char() so that I can reference it with a $ and then I would have to still be able to find out

Re: [R] indexing lists

2010-11-15 Thread Chris Carleton
Thanks for the suggestions. The issue for me is that the top level index is also like a database key so it might be a bit annoying to coerce it to char() so that I can reference it with a $ and then I would have to still be able to find out what the name was automatically. I've got a function right

Re: [R] indexing lists

2010-11-15 Thread David Winsemius
On Nov 15, 2010, at 4:24 PM, Chris Carleton wrote: Hi List, I'm trying to work out how to use which(), or another function, to find the top-level index of a list item based on a condition. An example will clarify my question. a <- list(c(1,2),c(3,4)) a [[1]] [1] 1 2 [[2]] [1] 3 4 I wan

Re: [R] indexing lists

2010-11-15 Thread Joshua Wiley
Hi Chris, Does this do what you're after? It just compares each element of a (i.e., a[[1]] and a[[2]]) to c(1, 2) and determines if they are identical or not. which(sapply(a, identical, y = c(1, 2))) There were too many 1s floating around for me to figure out if you wanted to find elements of a

Re: [R] indexing lists

2010-11-15 Thread Erik Iverson
Chris, Well, the 'answer' could be: which(sapply(a, function(x) all(x == c(1,2 But I wonder how these elements of 'a' in your actual application are coming to be? If you're constructing them, you can give the elements of the list names, and then it doesn't matter what numerical index they

[R] indexing lists

2010-11-15 Thread Chris Carleton
Hi List, I'm trying to work out how to use which(), or another function, to find the top-level index of a list item based on a condition. An example will clarify my question. a <- list(c(1,2),c(3,4)) a [[1]] [1] 1 2 [[2]] [1] 3 4 I want to find the top level index of c(1,2), which should return

Re: [R] Indexing sublists inside lists.

2010-09-21 Thread Dennis Murphy
Hi: Is this what you were looking for? frd <- rep('fred', 5) bigfred <- lapply(frd, get) On Tue, Sep 21, 2010 at 5:04 AM, Alaios wrote: > I would like to thank you very much for your reply. > Actually I would like to ask you if there is > a small list called fred: > fred <- list(happy = 1:10,

[R] Indexing sublists inside lists.

2010-09-21 Thread Alaios
I would like to thank you very much for your reply. Actually I would like to ask you if there is a small list called fred: fred <- list(happy = 1:10, name = "squash") and a big list called bigfred that included fred list 5 times bigfred <- rep(fred,5) Is it possible somehow to index all these sub

Re: [R] Indexing by logical vectors

2010-07-20 Thread Kingsford Jones
t;Z" However, given the long history of S/R, there must be logical or philosophical obstacles to this...? best, Kingsford Jones >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On >> Behalf Of Christian Raschke >&g

Re: [R] Indexing by logical vectors

2010-07-20 Thread David Winsemius
d it all happens, no questions asled. (I can see a generic function emerging here, perhaps...) W. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Christian Raschke Sent: Tuesday, 20 July 2010 9:16 AM To: r-help@r-project.org Subj

Re: [R] Indexing by logical vectors

2010-07-19 Thread Christian Raschke
appens, no questions asled. (I can see a generic function > emerging here, perhaps...) > > W. > > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Christian Raschke > Sent: Tuesday, 20 July 2010 9:

Re: [R] Indexing by logical vectors

2010-07-19 Thread Christian Raschke
On Mon, 2010-07-19 at 19:46 -0400, David Winsemius wrote: > On Jul 19, 2010, at 7:16 PM, Christian Raschke wrote: > > > Dear R-Listers, > > > > My question concerns indexing vectors by logical vectors that are > > based on the original vector. Consider the following simple example > > to hopef

Re: [R] Indexing by logical vectors

2010-07-19 Thread Bill.Venables
questions asled. (I can see a generic function emerging here, perhaps...) W. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Christian Raschke Sent: Tuesday, 20 July 2010 9:16 AM To: r-help@r-project.org Subject: [R] Indexing b

  1   2   >