[R] points3d and ordirgl
Hello all, I have been using the function ordirgl to plot 3D dynamic ordinations. The ordirgl function works just fine. IN fact, I was even able to write a function that allows me to identify points in the 3D plot: identify.rgl<-function(env_var,ord,dim1,dim2,dim3) { tmp<-select3d(button="left") tmp.keep<-tmp(ord[,dim1],ord[,dim2],ord[,dim3]) env_var[tmp.keep=="TRUE"] } where env_var = a variable to be identified (e.g. plot IDs as in > row.names(dataframe)) ord = ordination points or scores created using a function such as metaMDS or nmds) that is recognized by points or scores dim1 = dimension 1 (e.g., 1) dim2 = dimension 2 (e.g., 2) dim 3 = dimension 3 (e.g, 3 e.g., > identify.rgl(row.names(vegmat),veg_nmds$points,1,2,3) My issue is that I would like to use the points3d function to add points of different colors and sizes to the dynamic 3D plot created by using ordirgl. In my case the different colored and sized points represent different clusters from the results of the Partitioning Around Mediods (pam) clustering function (from library cluster). I have used this with success in the past (two years back), but can't get it to work properly now. An example of the code I have used in the past is: > points3d(veg_nmds$points[,1],veg_nmds$points[,2],veg_nmds$points[,3],display = "sites",veg_pam12$clustering=="1",col=2,size=3) The code above is intended to add the points from cluster 1 to the nmds plot in the color red and size 3. Anyone have an ideas? Thanks, Aaron [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] function output with for loop and if statement
ular leddecLedum_decumbens Evergreen_Shrubs Vascular picgla Picea_glauca Evergreen_Tree Vascular picmar Picea_mariana Evergreen_Tree Vascular arcuvaArctostaphylos_uva-ursi Evergreen_Shrubs Vascular zygele Zygadenus_elegansForbs Vascular epiangEpilobium_angustifoliumForbs Vascular calpur Calamagrostis_purpurascens Grasses Vascular poaarcPoa_arctica Grasses Vascular pelaph Peltigera_aphthosa Lichens Non-Vascular flacucFlavocetraria_cucullata Lichens Non-Vascular tomnit Tomentypnum_nitens Mosses Non-Vascular hylspl Hylocomium_splendens Mosses Non-Vascular carvag Carex_vaginata Sedges Vascular caraqu Carex_aquatilis_aquatilis Sedges Vascular calcan Calamagrostis_canadensis Grasses Vascular carsaxCarex_saxatilis Sedges Vascular > Subject: Re: [R] function output with for loop and if statement > From: gavin.simp...@ucl.ac.uk > To: awell...@hotmail.com > CC: r-help@r-project.org > Date: Thu, 23 Apr 2009 09:18:17 +0100 > > On Wed, 2009-04-22 at 15:51 -0400, aaron wells wrote: >> Hello all, turns out i'm having a bad R week. I am at my wits end >> with a function that I am trying to write. When I run the lines of >> code outside of a function, I get the desired output. When I wrap the >> lines of code into a function it doesn't work as expected. Not sure >> what is going on here. I suspected that the syntax of the if >> statement with the for loop was the culprit, but when I only ran the >> part of the code with the for loop with no if statement I still had >> the above problem (works outside function, fails when wrapped into a >> function). Below is the code and example output. Please help! > > It would help a lot if you spaced your code out a bit around key > operators and structural elements. > > Anyway, you didn't enclose the if/else blocks in {} in such cases, only > the line following the if(...) is run if the clause is TRUE - the lines > after that, but the code you provided doesn't even load into R - the > lone else is a syntax error. So it is a bit difficult to see what is > going on and you don;t provide an example any of us can reproduce as we > don't have your data objects. > > I edited your functions below to do what I think you intended and to > clean it up a bit. Perhaps we can use this as starting point if the > function here: > > `concov.test` <- function(vegetation, specieslist) > { > test.veg <- vegetation > names(test.veg) <- specieslist$LifeForm > nams <- unique(names(test.veg)) > tmp <- matrix(nrow = nrow(test.veg), ncol = length(nams)) > for (i in nams) { > test.out <- apply(test.veg[, names(test.veg)==i], 1, sum) > tmp.match <- nams[nams==i] > tmp.col <- match(tmp.match, nams) > tmp[1:nrow(test.veg), tmp.col] <- test.out > tmp.out <- data.frame(row.names(test.veg), tmp, row.names = 1) > names(tmp.out) <- nams > ## do you need this or is this for debugging? > print(tmp.out) > tmp.out.sort <- tmp.out[, order(names(tmp.out))] > } > if(table(names(tmp.out))[i] == 1) { > nams.srt <- names(tmp.out.sort) > tmp.match2 <- nams.srt[nams.srt == i] > tmp.col2 <- match(tmp.match2, names.srt) > tmp.out.sort[1:nrow(test.veg), tmp.col2] <- > test.veg[, names(test.veg)==i] > return(tmp.out.sort) > } else { > return(tmp.out.sort) > } > } > > doesn't do what you want. Please provide a small, reproducible example > (that means with data, dummy or otherwise) so we can run the code and > test changes against your data. > > HTH > > G > >> >> >> Thanks, >> >> Aaron >> >> >> >> concov.test<-function(vegetation,specieslist) >> { >> test.veg<-vegetation >> names(test.veg)<-specieslist$LifeForm >> tmp<-matrix(nrow=nrow(test.veg),ncol=length(unique(names(test.veg >> for (i in unique(names(test.veg))) >> {test.out<-apply(test.veg[,names(test.veg)==i],1,sum) >> tmp.match<-unique(names(test.veg))[unique(names(test.veg))==i] >> tmp.col<-match(tmp.match,unique(names(test.veg))) >> tmp[1:nrow(test.veg),tmp.col]<-test.out >> tmp.out<-data.frame(row.names(test.veg),tmp,row.names=1);names(tmp.out)<-unique(names(test.veg)) >> tmp.out >> tmp.out.sort<-tmp.out[,order(names(tmp.out))] >> } >> if(table(names(tmp.out))[i]==1) >> tmp.match2<-names(tmp.out.sort)[names(tmp.out.sort)==i] >> tmp.col2<-match(tmp.match2,names(tmp.out.sort)) >>
Re: [R] function output with for loop and if statement
Mark, thanks for the suggestions. Unfortunately that did not fix the problem. I have experimented (with no success) with placing braces in different locations around the if/else statements and removing them all together. Thanks again, Aaron Date: Wed, 22 Apr 2009 15:24:24 -0500 From: markle...@verizon.net To: awell...@hotmail.com Subject: Re: [R] function output with for loop and if statement Hi Aaron: i just looked quickly because I have to go but try wrapping braces around the last if else like below and see if that helps. if you have multiple statements in an if else, i think you need them so I'm actually a little surpised that your function didn't give messages when you tried to run it ? Also, braces in R can have some strange behavior ( because , if code is run at the prompt, and a statement can complete and there's no brace on that line then that statement is executed regardless f there's a brace later. that probably doesn't make much sense but it's kind of hard to explain ) but I'm hoping that below fixes the problem. good luck. function ( ) { # brace for beginning of function . . . if (table(names(tmp.out))[i]==1) { tmp.match2<-names(tmp.out.sort)[names(tmp.out.sort)==i] tmp.col2<-match(tmp.match2,names(tmp.out.sort)) tmp.out.sort[1:nrow(test.veg),tmp.col2]<-test.veg[,names(test.veg)==i] return(tmp.out.sort) } else { return(tmp.out.sort) } } # brace for end of function On Apr 22, 2009, aaron wells wrote: Hello all, turns out i'm having a bad R week. I am at my wits end with a function that I am trying to write. When I run the lines of code outside of a function, I get the desired output. When I wrap the lines of code into a function it doesn't work as expected. Not sure what is going on here. I suspected that the syntax of the if statement with the for loop was the culprit, but when I only ran the part of the code with the for loop with no if statement I still had the above problem (works outside function, fails when wrapped into a function). Below is the code and example output. Please help! Thanks, Aaron concov.test<-function(vegetation,specieslist) { test.veg<-vegetation names(test.veg)<-specieslist$LifeForm tmp<-matrix(nrow=nrow(test.veg),ncol=length(unique(names(test.veg for (i in unique(names(test.veg))) {test.out<-apply(test.veg[,names(test.veg)==i],1,sum) tmp.match<-unique(names(test.veg))[unique(names(test.veg))==i] tmp.col<-match(tmp.match,unique(names(test.veg))) tmp[1:nrow(test.veg),tmp.col]<-test.out tmp.out<-data.frame(row.names(test.veg),tmp,row.names=1);names(tmp.out)<-unique(names(test.veg)) tmp.out tmp.out.sort<-tmp.out[,order(names(tmp.out))] } if(table(names(tmp.out))[i]==1) tmp.match2<-names(tmp.out.sort)[names(tmp.out.sort)==i] tmp.col2<-match(tmp.match2,names(tmp.out.sort)) tmp.out.sort[1:nrow(test.veg),tmp.col2]<-test.veg[,names(test.veg)==i] return(tmp.out.sort) else return(tmp.out.sort) } Incorrect output when run as function- > test<-concov.test(ansveg_all,spplist.class) > test Bare_Ground Deciduous_Shrubs Deciduous_Tree Evergreen_Shrubs Evergreen_Tree Forbs Grasses Lichens Mosses Sedges ANSG_T01_01_2008 NA NA NA NA NA NA NA NA 95.0 NA ANSG_T01_02_2008 NA NA NA NA NA NA NA NA 16.0 NA ANSG_T01_03_2008 NA NA NA NA NA NA NA NA 71.0 NA ANSG_T01_04_2008 NA NA NA NA NA NA NA NA 10.0 NA ANSG_T02_01_2008 NA NA NA NA NA NA NA NA 92.2 NA ANSG_T02_02_2008 NA NA NA NA NA NA NA NA 14.0 NA . . . Correct output when code is run outside of a function > test.veg<-ansveg_all > names(test.veg)<-spplist.class$LifeForm > tmp<-matrix(nrow=nrow(test.veg),ncol=length(unique(names(test.veg > > for (i in unique(names(test.veg))) > {test.out<-apply(test.veg[,names(test.veg)==i],1,sum) + tmp.match<-unique(names(test.veg))[unique(names(test.veg))==i] + tmp.col<-match(tmp.match,unique(names(test.veg))) + tmp[1:nrow(test.veg),tmp.col]<-test.out + tmp.out<-data.frame(row.names(test.veg),tmp,row.names=1);names(tmp.out)<-unique(names(test.veg)) + tmp.out + tmp.out.sort<-tmp.out[,order(names(tmp.out))] + } > if(table(names(tmp.out))[i]==1) + tmp.match2<-names(tmp.out.sort)[names(tmp.out.sort)==i] > tmp.col2<-match(tmp.match2,names(tmp.out.sort)) > tmp.out.sort[1:nrow(test.veg),tmp.col2]<-test.veg[,names(test.veg)==i] > return(tmp.out.sort) > else return(tmp.out.sort) > > > tmp.out.sort Bare_Ground Deciduous_Shrubs Deciduous_Tree Evergreen_Shrubs Evergreen_Tree Forbs Grasses Lichens Mosses Sedges ANSG_T01_01_2008 0 57.0 1.0 40.0 35.0 22.0 5.0 35.0 95.0 1.1 ANSG_T01_02_2008 0 0.0 0.0 0.0 0.0 34.0 0.0 0.0 16.0 24.0 ANSG_T01_03_2008 0 31.0 0.0 47.0 1.0 9.1 3.0 3.0 71.0 14.0 ANSG_T01_04_2008 0 0.0 0.0 12.0 0.0 13.2 0.0 0.0 10.0 16.0 ANSG_T02_01_2008 0 15.0 1.0 22.0
[R] function output with for loop and if statement
Hello all, turns out i'm having a bad R week. I am at my wits end with a function that I am trying to write. When I run the lines of code outside of a function, I get the desired output. When I wrap the lines of code into a function it doesn't work as expected. Not sure what is going on here. I suspected that the syntax of the if statement with the for loop was the culprit, but when I only ran the part of the code with the for loop with no if statement I still had the above problem (works outside function, fails when wrapped into a function). Below is the code and example output. Please help! Thanks, Aaron concov.test<-function(vegetation,specieslist) { test.veg<-vegetation names(test.veg)<-specieslist$LifeForm tmp<-matrix(nrow=nrow(test.veg),ncol=length(unique(names(test.veg for (i in unique(names(test.veg))) {test.out<-apply(test.veg[,names(test.veg)==i],1,sum) tmp.match<-unique(names(test.veg))[unique(names(test.veg))==i] tmp.col<-match(tmp.match,unique(names(test.veg))) tmp[1:nrow(test.veg),tmp.col]<-test.out tmp.out<-data.frame(row.names(test.veg),tmp,row.names=1);names(tmp.out)<-unique(names(test.veg)) tmp.out tmp.out.sort<-tmp.out[,order(names(tmp.out))] } if(table(names(tmp.out))[i]==1) tmp.match2<-names(tmp.out.sort)[names(tmp.out.sort)==i] tmp.col2<-match(tmp.match2,names(tmp.out.sort)) tmp.out.sort[1:nrow(test.veg),tmp.col2]<-test.veg[,names(test.veg)==i] return(tmp.out.sort) else return(tmp.out.sort) } Incorrect output when run as function- > test<-concov.test(ansveg_all,spplist.class) > test Bare_Ground Deciduous_Shrubs Deciduous_Tree Evergreen_Shrubs Evergreen_Tree Forbs Grasses Lichens Mosses Sedges ANSG_T01_01_2008 NA NA NA NA NANA NA NA 95.0 NA ANSG_T01_02_2008 NA NA NA NA NANA NA NA 16.0 NA ANSG_T01_03_2008 NA NA NA NA NANA NA NA 71.0 NA ANSG_T01_04_2008 NA NA NA NA NANA NA NA 10.0 NA ANSG_T02_01_2008 NA NA NA NA NANA NA NA 92.2 NA ANSG_T02_02_2008 NA NA NA NA NANA NA NA 14.0 NA . . . Correct output when code is run outside of a function > test.veg<-ansveg_all > names(test.veg)<-spplist.class$LifeForm > tmp<-matrix(nrow=nrow(test.veg),ncol=length(unique(names(test.veg > > for (i in unique(names(test.veg))) > {test.out<-apply(test.veg[,names(test.veg)==i],1,sum) + tmp.match<-unique(names(test.veg))[unique(names(test.veg))==i] + tmp.col<-match(tmp.match,unique(names(test.veg))) + tmp[1:nrow(test.veg),tmp.col]<-test.out + tmp.out<-data.frame(row.names(test.veg),tmp,row.names=1);names(tmp.out)<-unique(names(test.veg)) + tmp.out + tmp.out.sort<-tmp.out[,order(names(tmp.out))] + } > if(table(names(tmp.out))[i]==1) + tmp.match2<-names(tmp.out.sort)[names(tmp.out.sort)==i] > tmp.col2<-match(tmp.match2,names(tmp.out.sort)) > tmp.out.sort[1:nrow(test.veg),tmp.col2]<-test.veg[,names(test.veg)==i] > return(tmp.out.sort) > else return(tmp.out.sort) > > > tmp.out.sort Bare_Ground Deciduous_Shrubs Deciduous_Tree Evergreen_Shrubs Evergreen_Tree Forbs Grasses Lichens Mosses Sedges ANSG_T01_01_2008 0 57.01.0 40.0 35.0 22.0 5.035.0 95.01.1 ANSG_T01_02_2008 0 0.00.0 0.0 0.0 34.0 0.0 0.0 16.0 24.0 ANSG_T01_03_2008 0 31.00.0 47.0 1.0 9.1 3.0 3.0 71.0 14.0 ANSG_T01_04_2008 0 0.00.0 12.0 0.0 13.2 0.0 0.0 10.0 16.0 ANSG_T02_01_2008 0 15.01.0 22.0 36.0 9.2 2.038.0 92.20.1 ANSG_T02_02_2008 0 33.0 66.0 23.0 2.0 5.0 0.0 3.0 14.00.0 . . . _ Rediscover HotmailĀ®: Get quick friend updates right in your inbox. Updates2_042009 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] deleting/removing previous warning message in loop
William, The function keepWarnings that you wrote did the trick. Thanks for the help! Aaron > Subject: Re: [R] deleting/removing previous warning message in loop > Date: Fri, 27 Mar 2009 13:33:51 -0700 > From: wdun...@tibco.com > To: awell...@hotmail.com > > You try a using function like the following (based > on suppressWarnings): > keepWarnings <- function(expr) { > localWarnings <- list() > value <- withCallingHandlers(expr, > warning = function(w) { > localWarnings[[length(localWarnings)+1]] <<- w > invokeRestart("muffleWarning") > }) > list(value=value, warnings=localWarnings) > } > It returns a 2-element list, the first being the value > of the expression given to it and the second being a > list of all the warnings. Your code can look through > the list of warnings and decide which to omit. E.g., > > > d<-data.frame(x=1:10, y=rep(c(FALSE,TRUE),c(4,6))) > > z <- keepWarnings(glm(y~x, data=d, family=binomial)) > > z$value > > Call: glm(formula = y ~ x, family = binomial, data = d) > > Coefficients: > (Intercept) x > -200.37 44.52 > > Degrees of Freedom: 9 Total (i.e. Null); 8 Residual > Null Deviance: 13.46 > Residual Deviance: 8.604e-10 AIC: 4 > > z$warnings > [[1]] > start, etastart = etastart, mustart = mustart, offset = offset, > family = family, control = control, intercept = attr(mt, > "intercept") > 0): algorithm did not converge> > > [[2]] > start, etastart = etastart, mustart = mustart, offset = offset, > family = family, control = control, intercept = attr(mt, > "intercept") > 0): fitted probabilities numerically 0 or 1 occurred> > > > str(z$warnings[[1]]) > List of 2 > $ message: chr "algorithm did not converge" > $ call : language glm.fit(x = X, y = Y, weights = weights, start = > start, etastart = etastart, mustart = mustart, offset = offset, > family = family, control = control, ... > - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition" > > sapply(z$warnings, function(w)w$message) > [1] "algorithm did not converge" > [2] "fitted probabilities numerically 0 or 1 occurred" > > You can filter out the ones you don't want to hear about > and recall warning() with the interesting ones or present > them in some other way. > > > Bill Dunlap > TIBCO Software Inc - Spotfire Division > wdunlap tibco.com > > --- > I am having difficulty deleting the last warning message in a loop so > that the only warning that is produced is that from the most recent line > of code. I have tried options(warn=1), rm(last.warning), and resetting > the last.warning using something like: ... _ [[elided Hotmail spam]] plorer 8. [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] deleting/removing previous warning message in loop
Hello R Users, I am having difficulty deleting the last warning message in a loop so that the only warning that is produced is that from the most recent line of code. I have tried options(warn=1), rm(last.warning), and resetting the last.warning using something like: > warning("Resetting warning message") This problem has been addressed in a previous listserve string, however I do not follow the advice given. See the below web link. Any help would be greatly appreciated. Thanks! Aaron Wells https://stat.ethz.ch/pipermail/r-help/2008-October/176765.html A general example is first, followed by an example with the loop. - Example 1: > demo.glm<-glm(test.data[,1]~c(1:38)+I(c(1:38)^2),family=binomial) ### > Generalized linear model run on the first column of my example data > warnings() ### no warnings reported NULL > demo.glm<-glm(test.data[,9]~c(1:38)+I(c(1:38)^2),family=binomial) ### > Generalized linear model run on the 9th column of my example data Warning messages: 1: In glm.fit(x = X, y = Y, weights = weights, start = start, etastart = etastart, : algorithm did not converge 2: In glm.fit(x = X, y = Y, weights = weights, start = start, etastart = etastart, : fitted probabilities numerically 0 or 1 occurred > warnings()### the model with column 9 as data produces warnings Warning messages: 1: In glm.fit(x = X, y = Y, weights = weights, start = start, ... : algorithm did not converge 2: In glm.fit(x = X, y = Y, weights = weights, start = start, ... : fitted probabilities numerically 0 or 1 occurred > demo.glm<-glm(test.data[,1]~c(1:38)+I(c(1:38)^2),family=binomial) ### Re-run > the model with column 1 as data > warnings() ### reports the same warnings from the column 9 model, ideally > it would report the actual warning message for the column 1 model ("NULL") as > above Warning messages: 1: In glm.fit(x = X, y = Y, weights = weights, start = start, ... : algorithm did not converge 2: In glm.fit(x = X, y = Y, weights = weights, start = start, ... : fitted probabilities numerically 0 or 1 occurred -- Example 2: Loop ###In the below example I have reset warnings() before each iteration by using warning("Resetting warning message"). I would like the warnings to somehow be consolidated into a list that I could later examine to determine which model iterations ran with and without warnings. The below code doesn't work because the functions are being run in the loop environment, and not the base environment. > test.warn<-rep(0,ncol(test.data));test.warn<-as.list(test.warn) > > > for (i in 1:ncol(test.data)) {warn.reset<-warning("Resetting warning message") + demo.glm<-glm(test.data[,i]~c(1:38)+I(c(1:38)^2),family=binomial) + warn.new<-warnings() + cbind.warn<-cbind(warn.reset,warn.new) + test.warn[[i]]<-cbind.warn + test.warn + } There were 38 warnings (use warnings() to see them) > test.warn [[1]] warn.reset warn.new Resetting warning message "Resetting warning message" NULL [[2]] warn.reset warn.new Resetting warning message "Resetting warning message" NULL . . . Aaron F. Wells, PhD Senior Scientist ABR, Inc. 2842 Goldstream Road Fairbanks, AK 99709 _ [[elided Hotmail spam]] plorer 8. [[elided Hotmail spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ordering
Thanks Peter, that did the trick. I'll modify my function so that the numeric conversion is done automatically thus saving me the extra step of converting later on. Aaron Wells > Subject: RE: [R] ordering > Date: Wed, 11 Mar 2009 08:41:50 +1300 > From: palsp...@hortresearch.co.nz > To: awell...@hotmail.com; r-help@r-project.org > > Kia ora Aaron > > As you have identified, test[,2] is not numeric - it is probably factor. > Your function must have made the conversion, so you may want to modify > that. Alternative, try: > > test[order(as.numeric(as.character(test[,2]))),] > > BTW, str(test) is a good way to find out more about the structure of > your object. > > HTH > > Peter Alspach > > > > > > -Original Message- > > From: r-help-boun...@r-project.org > > [mailto:r-help-boun...@r-project.org] On Behalf Of aaron wells > > Sent: Wednesday, 11 March 2009 8:30 a.m. > > To: r-help@r-project.org > > Subject: [R] ordering > > > > > > Hello, I would like to order a matrix by a specific column. > > For instance: > > > > > > > > > test > > [,1] [,2] [,3] > > [1,] 1 100 21 > > [2,] 2 3 22 > > [3,] 3 100 23 > > [4,] 4 60 24 > > [5,] 5 55 25 > > [6,] 6 45 26 > > [7,] 7 75 27 > > [8,] 8 12 28 > > [9,] 9 10 29 > > [10,] 10 22 30 > > > > > > > test[order(test[,2]),] > > [,1] [,2] [,3] > > [1,] 2 3 22 > > [2,] 9 10 29 > > [3,] 8 12 28 > > [4,] 10 22 30 > > [5,] 6 45 26 > > [6,] 5 55 25 > > [7,] 4 60 24 > > [8,] 7 75 27 > > [9,] 1 100 21 > > [10,] 3 100 23 > > > > > > This works well and good in the above example matrix. > > However in the matrix that I actually want to sort (derived > > from a function that I wrote) I get something like this: > > > > > > > > > test[order(as.numeric(test[,2])),] ### First column is row.names > > > > > > f con f.1 cov f.2 minimum f.3 maximum f.4 cl > > asahi * 100 * 1 * 0.1 * 2 * test > > castet * 100 * 2 * 0.1 * 5 * test > > clado * 100 * 1 * 0.7 * 2 * test > > aulac * 33 * 0 * 0.1 * 0.1 * test > > buell * 33 * 0 * 0.1 * 0.1 * test > > camlas * 33 * 0 * 0.1 * 0.1 * test > > carbig * 33 * 1 * 1 * 1 * test > > poaarc * 67 * 0 * 0.1 * 0.1 * test > > polviv * 67 * 0 * 0.1 * 0.1 * test > > > > > > > > > > where R interprets 100 to be the lowest value and orders > > increasing from there. > > > > > > > > > is.numeric(test[,2]) > > [1] FALSE > > > is.double(test[,2]) > > [1] FALSE > > > is.integer(test[,2]) > > [1] FALSE > > > is.real(test[,2]) > > [1] FALSE > > > > > > > > > > My questions are: Why is this happening? and How do I fix it? > > > > > > > > Thanks in advance! > > > > > > > > Aaron Wells > > > > _ > > > > > > cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009 > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > The contents of this e-mail are confidential and may be subject to legal > privilege. > If you are not the intended recipient you must not use, disseminate, > distribute or > reproduce all or any part of this e-mail or attachments. If you have received > this > e-mail in error, please notify the sender and delete all material pertaining > to this > e-mail. Any opinion or views expressed in this e-mail are those of the > individual > sender and may not represent those of The New Zealand Institute for Plant and > Food Research Limited. _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] ordering
Hello, I would like to order a matrix by a specific column. For instance: > test [,1] [,2] [,3] [1,]1 100 21 [2,]23 22 [3,]3 100 23 [4,]4 60 24 [5,]5 55 25 [6,]6 45 26 [7,]7 75 27 [8,]8 12 28 [9,]9 10 29 [10,] 10 22 30 > test[order(test[,2]),] [,1] [,2] [,3] [1,]23 22 [2,]9 10 29 [3,]8 12 28 [4,] 10 22 30 [5,]6 45 26 [6,]5 55 25 [7,]4 60 24 [8,]7 75 27 [9,]1 100 21 [10,]3 100 23 This works well and good in the above example matrix. However in the matrix that I actually want to sort (derived from a function that I wrote) I get something like this: > test[order(as.numeric(test[,2])),] ### First column is row.names f con f.1 cov f.2 minimum f.3 maximum f.4 cl asahi* 100 * 1 * 0.1 * 2 * test castet * 100 * 2 * 0.1 * 5 * test clado* 100 * 1 * 0.7 * 2 * test aulac* 33 * 0 * 0.1 * 0.1 * test buell* 33 * 0 * 0.1 * 0.1 * test camlas * 33 * 0 * 0.1 * 0.1 * test carbig * 33 * 1 * 1 * 1 * test poaarc * 67 * 0 * 0.1 * 0.1 * test polviv * 67 * 0 * 0.1 * 0.1 * test where R interprets 100 to be the lowest value and orders increasing from there. > is.numeric(test[,2]) [1] FALSE > is.double(test[,2]) [1] FALSE > is.integer(test[,2]) [1] FALSE > is.real(test[,2]) [1] FALSE My questions are: Why is this happening? and How do I fix it? Thanks in advance! Aaron Wells _ cns!503D1D86EBB2B53C!2285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.