Gundala Viswanath
2008-Jun-11 10:34 UTC
[R] Finding Coordinate of Max/Min Value in a Data Frame
Hi, Suppose I have the following data frame. __BEGIN__> library(MASS) > data(crabs) > crab.pca <- prcomp(crabs[,4:8],retx=TRUE) > crab.pca$rotationPC1 PC2 PC3 PC4 PC5 FL 0.2889810 0.3232500 -0.5071698 0.7342907 0.1248816 RW 0.1972824 0.8647159 0.4141356 -0.1483092 -0.1408623 CL 0.5993986 -0.1982263 -0.1753299 -0.1435941 -0.7416656 CW 0.6616550 -0.2879790 0.4913755 0.1256282 0.4712202 BD 0.2837317 0.1598447 -0.5468821 -0.6343657 0.4386868 __END__ Is there a way to identify the "coordinate" of a max/min value of all the points above. For example the coord of maximum value is (RW,PC2) = 0.865, and coord of min value is (CW,PC2) = - 0.288. -- Gundala Viswanath
Henrique Dallazuanna
2008-Jun-11 11:57 UTC
[R] Finding Coordinate of Max/Min Value in a Data Frame
Try this: which(pca == min(pca), arr.ind = TRUE) which(pca == max(pca), arr.ind = TRUE) On Wed, Jun 11, 2008 at 7:34 AM, Gundala Viswanath <gundalav@gmail.com> wrote:> Hi, > > Suppose I have the following data frame. > > __BEGIN__ > > > library(MASS) > > data(crabs) > > crab.pca <- prcomp(crabs[,4:8],retx=TRUE) > > crab.pca$rotation > PC1 PC2 PC3 PC4 PC5 > FL 0.2889810 0.3232500 -0.5071698 0.7342907 0.1248816 > RW 0.1972824 0.8647159 0.4141356 -0.1483092 -0.1408623 > CL 0.5993986 -0.1982263 -0.1753299 -0.1435941 -0.7416656 > CW 0.6616550 -0.2879790 0.4913755 0.1256282 0.4712202 > BD 0.2837317 0.1598447 -0.5468821 -0.6343657 0.4386868 > > __END__ > > Is there a way to identify the "coordinate" of a max/min value of all the > points above. > > For example the coord of maximum value is (RW,PC2) = 0.865, > and coord of min value is (CW,PC2) = - 0.288. > > -- > Gundala Viswanath > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Petr PIKAL
2008-Jun-11 11:59 UTC
[R] Odp: Finding Coordinate of Max/Min Value in a Data Frame
Hi r-help-bounces at r-project.org napsal dne 11.06.2008 12:34:47:> Hi, > > Suppose I have the following data frame. > > __BEGIN__ > > > library(MASS) > > data(crabs) > > crab.pca <- prcomp(crabs[,4:8],retx=TRUE) > > crab.pca$rotation > PC1 PC2 PC3 PC4 PC5 > FL 0.2889810 0.3232500 -0.5071698 0.7342907 0.1248816 > RW 0.1972824 0.8647159 0.4141356 -0.1483092 -0.1408623 > CL 0.5993986 -0.1982263 -0.1753299 -0.1435941 -0.7416656 > CW 0.6616550 -0.2879790 0.4913755 0.1256282 0.4712202 > BD 0.2837317 0.1598447 -0.5468821 -0.6343657 0.4386868 > > __END__ > > Is there a way to identify the "coordinate" of a max/min value of allthe> points above. >which(crab.pca$rotation==min(crab.pca$rotation), arr.ind=T) which(crab.pca$rotation==max(crab.pca$rotation), arr.ind=T) Regards Petr> For example the coord of maximum value is (RW,PC2) = 0.865, > and coord of min value is (CW,PC2) = - 0.288. > > -- > Gundala Viswanath > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Firstly surely (CL,PC5) = -0.7416656 is the minima? I think something like this should work, though I'm not sure library(MASS) data(crabs) crab.pca <- prcomp(crabs[,4:8],retx=TRUE) x<- crab.pca$rotation c.len = length(x[,1]) r.len = length(x[1,]) maxy = which(x == min(x)) x.co <- ceiling(maxy/c.len) y.co <- maxy-(x.co-1)*c.len Though I'm sure their is a more simple solution to your problem, Best, David U Bristol Edward Wijaya-2 wrote:> > Hi, > > Suppose I have the following data frame. > > __BEGIN__ > >> library(MASS) >> data(crabs) >> crab.pca <- prcomp(crabs[,4:8],retx=TRUE) >> crab.pca$rotation > PC1 PC2 PC3 PC4 PC5 > FL 0.2889810 0.3232500 -0.5071698 0.7342907 0.1248816 > RW 0.1972824 0.8647159 0.4141356 -0.1483092 -0.1408623 > CL 0.5993986 -0.1982263 -0.1753299 -0.1435941 -0.7416656 > CW 0.6616550 -0.2879790 0.4913755 0.1256282 0.4712202 > BD 0.2837317 0.1598447 -0.5468821 -0.6343657 0.4386868 > > __END__ > > Is there a way to identify the "coordinate" of a max/min value of all the > points above. > > For example the coord of maximum value is (RW,PC2) = 0.865, > and coord of min value is (CW,PC2) = - 0.288. > > -- > Gundala Viswanath > > ______________________________________________ > R-help at 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. > >-- View this message in context: http://www.nabble.com/Finding-Coordinate-of-Max-Min-Value-in-a-Data-Frame-tp17775656p17776020.html Sent from the R help mailing list archive at Nabble.com.