Skip to content
Prev 177445 / 398506 Next

Separating variables in read.table

Patrick -
    There's no simple way to do what you want, because
R discourages you from having lots of separate
related objects.  Instead, you are encouraged to store
your objects in an organized form, such as a list, 
data frame  or matrix.  For your example, I'm assuming 
you are using the word "table" to describe a data.frame. 
If this is the case , you can refer to the individual
columns of test as

test[,1]
test[,2]
   etc.

or

test$x1
test$x2
   etc.

or

test[,'x1']
test[,'x2']

Also remember that R has functions that can operate on
each row or column of a matrix or data frame.  So if you 
wanted the means of each column of test, you could write

     apply(test,2,mean)
                                        - Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu
On Fri, 17 Apr 2009, Richardson, Patrick wrote: