[R] Documentation General Comments

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Apr 22 09:45:54 CEST 2008


On Mon, 2008-04-21 at 18:55 -0400, esmail bonakdarian wrote:
> > I realize the R developers are probably overwhelmed and have little time
> > for this, but the documentation really needs some serious reorganizaton.
> > A good through description of basic variable types would help a lot,
> > e.g. the difference between lists, arrays, matrices and frames. 
> 
> Agreed, esp since I am right now at this moment struggling with the
> differences of lists, arrays and vectors. (I have two vectors that I am
> trying to return from a function as an array of two rows - for some reason 
> that's not working)

Do you really mean an array - a 2D array in R is a matrix, and a matrix
is just a vector with a dim attribute?

Is this what you want?

> vec1 <- rnorm(10)
> vec2 <- rnorm(10)
> rbind(vec1, vec2)
          [,1]      [,2]       [,3]        [,4]       [,5]       [,6]
vec1 0.3168558 -1.932740 -0.3733405 -0.07928693 -1.8374269  1.6805874
vec2 1.0034995 -1.363651 -1.0013652 -0.42121839  0.3873921 -0.2290361
            [,7]      [,8]       [,9]      [,10]
vec1 -0.90785669 0.7075952  1.7158890 -0.8835566
vec2 -0.08870023 0.5470181 -0.7427756  0.6563215
> class(rbind(vec1, vec2))
[1] "matrix"
> # or explicitly coerce to array, but still matrix
> as.array(rbind(vec1, vec2))
          [,1]      [,2]       [,3]        [,4]       [,5]       [,6]
vec1 0.3168558 -1.932740 -0.3733405 -0.07928693 -1.8374269  1.6805874
vec2 1.0034995 -1.363651 -1.0013652 -0.42121839  0.3873921 -0.2290361
            [,7]      [,8]       [,9]      [,10]
vec1 -0.90785669 0.7075952  1.7158890 -0.8835566
vec2 -0.08870023 0.5470181 -0.7427756  0.6563215
> class(as.array(rbind(vec1, vec2)))
[1] "matrix"

The use of rbind/cbind is in section 5.8 of An Introduction to R, the
manual for R.

G

> 
> I just started with the R last week , and I am trying to get up to
> speed with this language. And while I have many years
> of experience with various programming languages, many which
> I have learned on my own, I am encountering a number of things
> that are slowing me down. I have downloaded the various intro/reference
> materials.
> 
> I am super-happy to have found this list though, everyone seems
> friendly and helpful, and I am learning a lot from it. Any new/additional
> documentation would be much welcome.
> 
> _________________________________________________________________
> 
> 
> esh_getintouch_042008
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org 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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list