[R] importing spreadsheet data - linera regression - panel data

Stefan Grosse singularitaet at gmx.net
Sun Apr 19 16:34:00 CEST 2009


Cecilia Carmo schrieb:
> The objective of my work is to do linear regressions with the
> variables in the files or with other variables that I can obtain from
> those by doing some mathematical operations.  I’ve already tried to
> import this information to an array in R, but I’ve seen that the
> linear regressions functions need the data into a dataframe. So I’m
> asking: How to import this information to a dataframe in R, in a
> manner that I can easily do the mathematical operations between the
> variables and then use it to do the regressions?
>

Your question is probably misspecified. Or the pure import is not your
only problem. For the import of the txt you should easily find read.csv
your candidate. (please use search on the r-project.org page which leads
easily to this solution.)
firms<-read.csv("myfilename.txt",header=T,sep="\t")

see
?read.csv for help.

Then your data are maybe in the wrong order. Instead of
Firm Year1 Year2
A    100   101

it is sometimes better to

Firm Year Rev
A    1    100
A    1    101

the transformation is called reshape. See
?reshape
and
example(reshape)

Then you can do your "mathematical operations".

See eg.
?lm
example(lm)

hth
Stefan




More information about the R-help mailing list