[R] Matrix/Data.Frame questions
Thomas Lumley
tlumley at u.washington.edu
Tue Oct 30 18:04:13 CET 2001
On Tue, 30 Oct 2001, Laura Gross wrote:
> Dear list
>
> Thanks to all who answered my query yesterday regarding the maximum size
> of a matrix in R.
>
> I have a couple more questions to ask with being new to R!
>
> 1. Having imported my data into R from SPSS, I have a data.frame
> consisting of several variables. I am wanting to store my response
> variable, Y, and four explanatory variables, X, in vectors/matrices. How
> can I do this in R?
I don't think you really do want to do this, but if you do, and your
dataframe is called df, with columns called Y, X1,X2,X3,X4
Y<-df$Y
X1<-df$X1
X2<-df$X2
etc
You could also do
attach(df)
and then the columns of the data frame would behave like separate
variables called Y, X1,...,X4.
A lot of the modelling and some of the graphics functions in R are
designed to work on data frames, so it's usually easier to keep your data
frame together rather than separating out the variables.
> 2. If I have say a 4x4 matrix, A, and I want to extract part of this
> matrix to create a submatrix, B, (say row 1:3 and column 1:3) how can I
> do this?
> Could it be done something like: B<-A[1:3,1:3] ?
Yes, exactly.
-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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