[R] mixing strings and numeric doubles in an array

Leigh E. Lommen
2010-08-03T15:34:27Z

I have an array called "stocks" which contains numeric dates, ticker
symbols,prices, etc.



> stocks[1:3,]

      DATE    TICKER PERMNO EXCHCD TSYMBOL TRDSTAT SHROUT      PRC
RET

1 19950131   EWST  10001             3         EWST       A
2224      -7.75000 -0.031250

2 19950228   EWST  10001             3         EWST       A
2224       7.54688 -0.026210

3 19950331   EWST  10001             3         EWST       A
2244       7.50000  0.006377



However when I call the part of the array dealing with the Ticker, I
get:



> stocks[2,2]

[1] EWST

16185 Levels:  A AA AAA AAAB AAABB AAB AABC AAC AACB AACC AACE AACI ...
ZVXI



Thus, when I reference this later, I get a numeric result and not the
symbol?  Is this because I need to change the format of stocks[,2] or
because it has these extra "levels".



For example:



# START FIRST PORTFOLIO

port1=matrix(0, ctr,3)#matrix for portfolio starting in June 30th 1995



c=0



# sort data at time t=1 (June 30th, 1995)

for (i in 1:T)

            {

              if (stocks[i,1]==19950630)

                        {

                          c=c+1

                          row=i

                          price = abs(stocks[i,8])



                          port1[c,1]=stocks[i,1] #put date in first
column

                          port1[c,2]=stocks[i,2] #ticker

                          port1[c,3]=price #price

                        }



            }



WHEN I TRY

> port1[1,2]

[1] 4934



I SHOULD GET

 [1] EWST

????????


	[[alternative HTML version deleted]]