Hi: 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)? Thanks Jon Minton [[alternative HTML version deleted]]
On Sat, 2006-11-04 at 15:57 +0000, Jon Minton wrote:> Hi:> 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)?See ?read.table and note the 'colClasses' argument, which allows you to set a "NULL" value to columns that should be skipped. Alternatively, you can do a post import column selection using ?subset. The appropriate solution may be dependent upon whether you are RAM constrained and/or whether the columns to be skipped are easier to define than the columns to be selected. HTH, Marc Schwartz
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/