[R] accessing information in data.frame
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Nov 27 15:07:20 CET 2001
Uwe Ligges <ligges at statistik.uni-dortmund.de> writes:
> "Dr. Berthold Kramm" wrote:
> >
> > After reading a data.frame using, such as a <- read.spss("data.sav")
> > I want to give the column index 'i', or a[i] to a function, which after
> > some calculation, should print out the results to the standard output.
> >
> > I am struggling how to access the data itself, as e.g. sum(a[i])
>
> sum(a[,i])
Or sum(a[[i]]) or a$age ? Notice that read.spss() gives a list,
not a data frame so a[i,j]-indexing is not going to work without
a <- as.data.frame(read.spss("data.sav"))
Also notice the attach() function.
>
> > does
> > not work in this context. In addition I need to know the name of the
> > variable within the function in order to generate a meaningful output,
> > and have not found any way to obtain the name of the variable.
>
> deparse(substitute(x))
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list