First I have a matrix called stocks1:

 

> class(stocks1)

[1] "matrix"

 

Here are the first 5 rows of the last 4 columns:

> stocks1[1:5,2:5]

      [,1]  [,2]  [,3]  [,4] 

[1,] 80.73 31.95 25.4  25.69

[2,] 83.66 31.95 27.12 25.2 

[3,] 83.27 32.93 28.74 26.29

[4,] 83.9  34.07 29.77 26.6 

[5,] 82.74 35.18 30.24 27.41

 

Now, why can't I convert this into a dataframe?  It automatically
converts the columns into 1 long row??

> newdata.df<-data.frame(stocks1[1:5,2:5])

> newdata.df

   X1.1  X1.2  X1.3 X1.4  X1.5  X1.6  X1.7  X1.8  X1.9 X1.10 X1.11 X1.12


1 80.73 83.66 83.27 83.9 82.74 31.95 31.95 32.93 34.07 35.18  25.4 27.12

 

  X1.13 X1.14 X1.15 X1.16 X1.17 X1.18 X1.19 X1.20 

1 28.74 29.77 30.24 25.69  25.2 26.29  26.6 27.41

> 

 

Regards,

Leigh


	[[alternative HTML version deleted]]

