[R] SAS "datalines" or "cards" statement equivalent in R?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Mon Dec 7 17:43:14 CET 2009

On Mon, Dec 7, 2009 at 3:53 PM, Marshall Feldman <marsh at uri.edu> wrote:
> Regarding the various methods people have suggested, what if a typical
> tab-delimited data line looks like:
>     SMS11000000000000001 1990 M01 688.0
> and the SAS INPUT statement is
>   INPUT survey $ 1-2 seasonal $ 3 state $ 4-5 area $ 6-10 supersector $
> 11-12 @13 industry $8. datatype $ 21-22  year period $ value footnote $ ;
> Note that most data lines have no footnote item, as in the sample.
> Here (I think) we'd want all the character variables to be read as factors,
> possibly "year" as a date, and "value" as numeric.

 Actually I'm surprised that nobody has yet said what a clearly
bonkers thing it is to mix up your data and your analysis code in a
single file. Now suppose you have another set of data you want to
analyse with the same code? Are you going to create a new file and
paste the new data in? You've now got two copies of your analysis code
- good luck keeping corrections to that code synchronised.

 This just seems like horrendously bad practice, which is one reason
it's kludgy in R. If it was good practice, someone would surely have
written a way to do it neatly.

 Keep your data in data files, and your functions in .R function
files. You'll thank me later.


More information about the R-help mailing list