Thank you for help with the first part. The second part I do not understand. 
All I get is "3" "3". Presumably this is the factor that you refer to. Is there 
no simple way of extracting the text alone


----- Forwarded Message ----
From: Peter Alspach <[EMAIL PROTECTED]>
To: Jabez Wilson <[EMAIL PROTECTED]>
Sent: Tuesday, 7 November, 2006 7:46:02 PM
Subject: RE: [R] data frames re-ordering and naming columns


Jabez

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Jabez Wilson
> Sent: Wednesday, 8 November 2006 4:25 a.m.
> To: r-help@stat.math.ethz.ch
> Subject: [R] data frames re-ordering and naming columns
>
> Dear all, I have read in a table using read.table(). The data
> frame looks like this:
>   > my_table
>      V1   V2
> 1     3  320
> 2     2  230
> 3     3  300
> 4     2  220
> 5     3  320
> 6     2  210
> 7  freq size
> 8     0    0
> 9     2  220
> 10    2  210
> 11    2  220
> 12    1  110
> 13    2  240
> 14    1  110
> I then remove the duplicate lines with unique(my_table) and get this:
>        V1   V2
> 1     3  320
> 2     2  230
> 3     3  300
> 4     2  220
> 6     2  210
> 7  freq size
> 8     0    0
> 12    1  110
> 13    2  240
> I have two questions:
>   1. what is the purpose of the numbers on the LHS, and how
> can I reorder them so that they read in ascending order?

They are row names.  They seem to be in ascending order to me.  See
?order for sorting.  Row names can be set, for example by:

row.names(myTable) <- 1:nrow(myTable)

>   2. how can I extract the line "freq size" and make it the
> column names?

If your original had the headings on the first line this could have been
easily effected by the header=TRUE argument to read.table().  Now, you
could try:

names(myTable) <- myTable[6,] # or it may need to be
as.character(myTable[6,])
myTable <- myTable[-6,]

Note the columns of myTable are likely to be factors due to the presence
of the 'freq, size' line in the input file.

HTH .........

Peter Alspach

______________________________________________________

The contents of this e-mail are privileged and/or confidenti...{{dropped}}

______________________________________________
R-help@stat.math.ethz.ch 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.

Reply via email to