s-news
[Top] [All Lists]

Re: accessing a column of a matrix using strings

To: "Leeds, Mark" <mleeds@mlp.com>
Subject: Re: accessing a column of a matrix using strings
From: Spencer Graves <spencer.graves@PDF.COM>
Date: Sun, 27 Jul 2003 17:13:19 -0700
Cc: s-news@wubios.wustl.edu
References: <C497480353EF904FBF7A8B0851E5422C9F7B67@MAIL002.AD.MLP.COM>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02
I get the following from S-Plus 6.1 under Windows 2000:
> (d2x2 <- matrix(1:4, 2, dimnames = list(c("9", "8"), c("3", "4"))))
  3 4
9 1 3
8 2 4
> d2x2[, "3"]
 9 8
 1 2
> d2x2["9",  , drop = F]
  3 4
9 1 3

hope this helps.  spencer graves

Leeds, Mark wrote:
I think this question is pretty basic but i have been stuck for a while.
i have a matrix whose columns are strings such as "8344", "8312" etc. later on, in a program, i have a variable called ticker1 which is a string
such as the above. so , i want to access the column corresponding
to whatever string ticker1 is.
i tried matrix[,ticker1] : this gives me back weird stuff which i kind
of expected.
i tried matrix[,get(ticker1)] : this gives me back "object "8344" not found. does anyone know how to do this ? i'm gonna play
around some more but thanks in advance.
mark



<Prev in Thread] Current Thread [Next in Thread>