[R] using underscore character in column names

partha_bagchi@hgsi.com partha_bagchi at hgsi.com
Mon Aug 30 20:55:15 CEST 1999


refer to the columns in the dataset as:
data$'pos_x'




                                                                                                               
                    "Terry Westley"                                                                            
                    <twestley at buffalo.ver        To:     "R-Help" <r-help at stat.math.ethz.ch>                   
                    idian.com>                   cc:                                                           
                    Sent by:                     Subject:     [R] using underscore character in column names   
                    owner-r-help at stat.mat                                                                      
                    h.ethz.ch                                                                                  
                                                                                                               
                                                                                                               
                    08/30/1999 01:08 PM                                                                        
                                                                                                               
                                                                                                               



Suppose you're reading data from a file in which the
column names contain underscore characters.  Example:

------ start of file -----
pos_x   pos_y
  1.0     0.0
  2.0     1.0
------ end of file -------

Using read.table, I can read this file just fine:

> data <- read.table (file="data", head=T)
> data
  pos_x pos_y
1     1     0
2     2     1
>

However, I can't refer to pox_x because the _ character
is an alternative to <- (assignment):

> data$pos_x
Error: Object "x" not found

I could use data[1], but I'd prefer to use the column
name.  Must I change all my column names to remove the
underscore character or is there way to force R to
recogize the whole column name?

Something like data${pos_x} or data$pos\_x  ???

--
Terry J. Westley, Software Systems Engineering Supervisor
Veridian Engineering, Calspan Operations
P.O. Box 400, Buffalo, NY 14225
twestley at buffalo.veridian.com    http://www.veridian.com

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list