Skip to content

read.table or read.csv without row index?

4 messages · tsunhin wong, Henrique Dallazuanna, Sarah Goslee +1 more

#
Hello all,

Probably my concepts about the data.frame and matrix and array in R
are not clear, I need some clarification to help me understand them
better.
gives me: M as

  M1 M2 M3 M4 M5 M6 M7 M8 M9 M10
1  9 11 14 15 18 20 20 20 20  20
2  3  4  8  9 11 12 14 15 15  15
3  4  5  8  8  9  9  9  9  9   9
4  4  5  7  8  8  8  8  8  8   9

1. How can I read the csv file to:

  M1 M2 M3 M4 M5 M6 M7 M8 M9 M10
[1,]  9 11 14 15 18 20 20 20 20  20
[2,]  3  4  8  9 11 12 14 15 15  15
[3,]  4  5  8  8  9  9  9  9  9   9
[4,]  4  5  7  8  8  8  8  8  8   9

2. or how can convert the above M to a format with [1,],[2,] etc
instead of 1,2,etc?

3. How can I read a text file so that I can get:
  [,1] [,2] [,3] [,4] [,5]
[1,]  9 11 14 15 18
[2,]  3  4  8  9 11
[3,]  4  5  8  8  9
[4,]  4  5  7  8  8

(instead of having the columns names V1 to V5?)

Thank you for your help!

Regards,

      John
#
Really, this depends on what you are trying to do. What's the underlying
problem you are solving? You can save a data frame to a file without
the names, if that's the real question, but I can't think of any reason to
not want names within R.

A matrix does not have to have row and column names, but a dataframe
is required to have them. If none are specified, sequential values will be
assigned.
[,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9
X1 X2 X3
1  1  4  7
2  2  5  8
3  3  6  9


Sarah
On Wed, Apr 22, 2009 at 10:00 AM, tsunhin wong <thjwong at gmail.com> wrote:

  
    
#
You need to convert to a matrix and remove names:
+ 1  9 11 14 15 18 20 20 20 20  20
+ 2  3  4  8  9 11 12 14 15 15  15
+ 3  4  5  8  8  9  9  9  9  9   9
+ 4  4  5  7  8  8  8  8  8  8   9"), header=TRUE)
M1 M2 M3 M4 M5 M6 M7 M8 M9 M10
1  9 11 14 15 18 20 20 20 20  20
2  3  4  8  9 11 12 14 15 15  15
3  4  5  8  8  9  9  9  9  9   9
4  4  5  7  8  8  8  8  8  8   9
M1 M2 M3 M4 M5 M6 M7 M8 M9 M10
1  9 11 14 15 18 20 20 20 20  20
2  3  4  8  9 11 12 14 15 15  15
3  4  5  8  8  9  9  9  9  9   9
4  4  5  7  8  8  8  8  8  8   9
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    9   11   14   15   18   20   20   20   20    20
[2,]    3    4    8    9   11   12   14   15   15    15
[3,]    4    5    8    8    9    9    9    9    9     9
[4,]    4    5    7    8    8    8    8    8    8     9

        
On Wed, Apr 22, 2009 at 10:00 AM, tsunhin wong <thjwong at gmail.com> wrote: