[R] importing selected rows and columns from text

Chuck Cleland ccleland at optonline.net
Sun Jan 21 12:30:14 CET 2007


James Root wrote:
> I read through the import/export manual a few times and did not see this
> mentioned and checked the archives as well.  I am dealing with data sheets
> generated by Eprime (a software package for generating experimental
> psychology paradigms) that output subject responses in a proprietary Edat
> file format.  All individual subject response spread sheets can be merged to
> form one long file of all subjects.  As an example, if an experiment has 240
> responses per subject (120 for each condition, say), each subject will
> generate a spreadsheet with 240 rows.  After merging 10 subjects then, a
> merged spreadsheet will have 2400 rows, with each subject's responses
> starting every 240 rows.  Formally being an SPSS user, I would do a datalist
> command that would pick out the columns and rows of interest, and using a
> rows command, indicate how many rows were equal to one subject.

  You might just read the entire file and then use subset() to select
the rows and columns you need.  If you are reading the data with
read.table(), then the colClasses argument can be used to skip one or
more columns.

> Is there an equivalent way to do this directly from a text file to import
> into R?  That is, give R one long spread sheet composed of all subjects'
> responses, tell R how many rows make up a subject, which rows make up a
> discrete condition, and import and flag only the data that I need, and then
> organize these as discrete variables so that each subject will have 240
> columns of responses and only one row (instead of 240 rows and one column as
> in the original text file).  Sorry for the long-winded email, and thanks in
> advance for any help on this.

  Have a look at reshape() in package stats and cast() and melt() in
package reshape by Hadley Wickham for ways to reorganize the data.

> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list