[R] Equivalent to Stata command

Michael Kubovy kubovy at virginia.edu
Sat Nov 4 17:25:23 CET 2006


On Nov 4, 2006, at 10:57 AM, Jon Minton wrote:

> Do any of you know if there's an equivalent function to the Stata  
> command:
>
> Use v1 v3 v5 v2 v7 using file.dat
>
> In R? (i.e. something that just selectively loads certain variables  
> from a
> file and not others)?

How about (assuming that columns in 'file.dat' are separated by white  
space)
data <- read.table("file.dat", header = T, sep = " ") # reads in the  
whole file
data <- data[, c(1, 3, 5, 2, 7)] # keeps the columns you need

For more, see http://finzi.psych.upenn.edu/R/doc/manual/R-data.html
_____________________________
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall
         McCormick Road    Charlottesville, VA 22903
Office:    B011    +1-434-982-4729
Lab:        B019    +1-434-982-4751
Fax:        +1-434-982-4766
WWW:    http://www.people.virginia.edu/~mk9y/



More information about the R-help mailing list