Re: [R] r data structures
To slightly correct what's been said: In general lists are linear objects, but a list can have dimension. An example is in Circle 8.1.8 of 'The R Inferno'. http://www.burns-stat.com/pages/Tutor/R_inferno.pdf Pat On 16/08/2012 21:50, Schumacher, Jay S wrote: are these correct/accurate/sensible statements: a vector is a one dimensional object. a matrix is a two dimensional object. a list is a one dimensional object. i'm working from this web page: http://www.agr.kuleuven.ac.be/vakken/statisticsbyR/someDataStructures.htm - On Aug 16, 2012, at 11:49 AM, Schumacher, Jay S wrote: hi, i'm trying to understand r data structures. i see that vectors, matrix, factors and arrays have a dimension. there seems to be no mention of dimensionality anywhere for lists or dataframes. can i consider lists and frames to be of fixed dimension 2? About half of what you have deduced is wrong. Matrices, arrays, and dataframes do have dimensions, at least in technical R parlance, namely they have an attribute which can be queried with dim(). By definition matrices and dataframes have 2 dimensions. Arrays and matrices can be redimensioned, but dataframes cannot. Factors, lists, and atomic vectors do not have dimensions, but they do have lengths. An appropriately structured list (one with vectors all the same length) can be coerced to a dataframe with as.data.frame(). -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@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.
[R] r data structures
hi, i'm trying to understand r data structures. i see that vectors, matrix, factors and arrays have a dimension. there seems to be no mention of dimensionality anywhere for lists or dataframes. can i consider lists and frames to be of fixed dimension 2? thanks, jay s __ R-help@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.
Re: [R] r data structures
Hi, On Thu, Aug 16, 2012 at 2:49 PM, Schumacher, Jay S j...@neo.tamu.edu wrote: hi, i'm trying to understand r data structures. i see that vectors, matrix, factors and arrays have a dimension. Out of curiosity, where do you see that vectors and factors have a dimension? I mean -- I guess they're one dimensional, but ... there seems to be no mention of dimensionality anywhere for lists or dataframes. can i consider lists and frames to be of fixed dimension 2? data.frames: sure, I guess lists: no What would you consider the dimension of this list to be: x = list(a=1:10, b='hello', c=matrix(1:100, nrow=10)) -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@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.
Re: [R] r data structures
On Aug 16, 2012, at 11:49 AM, Schumacher, Jay S wrote: hi, i'm trying to understand r data structures. i see that vectors, matrix, factors and arrays have a dimension. there seems to be no mention of dimensionality anywhere for lists or dataframes. can i consider lists and frames to be of fixed dimension 2? About half of what you have deduced is wrong. Matrices, arrays, and dataframes do have dimensions, at least in technical R parlance, namely they have an attribute which can be queried with dim(). By definition matrices and dataframes have 2 dimensions. Arrays and matrices can be redimensioned, but dataframes cannot. Factors, lists, and atomic vectors do not have dimensions, but they do have lengths. An appropriately structured list (one with vectors all the same length) can be coerced to a dataframe with as.data.frame(). -- David Winsemius, MD Alameda, CA, USA __ R-help@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.
Re: [R] r data structures
It would be helpful to distinguish between a formal dimension attribute, and a (personal) conceptual model of whether or not any particular R object, or type of object, has dimension. Mention of data frames having dimension can be found in the help page for the dim() function. foo - 1:10 is.vector(foo) [1] TRUE dim(foo) NULL attributes(foo) NULL str(foo) int [1:10] 1 2 3 4 5 6 7 8 9 10 length(foo) [1] 10 bah - matrix(1:10, nrow=2) is.vector(bah)[1] FALSE dim(bah) [1] 2 5 attributes(bah) $dim [1] 2 5 str(bah) int [1:2, 1:5] 1 2 3 4 5 6 7 8 9 10 length(bah) [1] 10 The vector does not have a formal dimension (dim) attribute, but the matrix does. Regarding data frames and lists: ## ## data frame ## junk - data.frame(a=1:3,b=1:3) str(junk) 'data.frame': 3 obs. of 2 variables: $ a: int 1 2 3 $ b: int 1 2 3 attributes(junk) $names [1] a b $row.names [1] 1 2 3 $class [1] data.frame dim(junk) [1] 3 2 ## ## list ## glug - list(a=1, b=letters[3]) str(glug) List of 2 $ a: num 1 $ b: chr c attributes(glug) $names [1] a b dim(glug) NULL length(glug) [1] 2 Conceptually, I would consider data frames to have two dimensions (rows and columns). They do not have a formal dim attribute, but the dim() function does return a value. I personally do not think of lists as having dimension -- I never ask myself, what is the dimension of a list? But I do often enquire as to the length of a list, so might, if forced to, admit that lists have one dimension, length. But I do not think it is helpful to think of lists as having dimension. Certainly, lists do not have two dimensions. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/16/12 11:49 AM, Schumacher, Jay S j...@neo.tamu.edu wrote: hi, i'm trying to understand r data structures. i see that vectors, matrix, factors and arrays have a dimension. there seems to be no mention of dimensionality anywhere for lists or dataframes. can i consider lists and frames to be of fixed dimension 2? thanks, jay s __ R-help@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. __ R-help@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.
Re: [R] r data structures
are these correct/accurate/sensible statements: a vector is a one dimensional object. a matrix is a two dimensional object. a list is a one dimensional object. i'm working from this web page: http://www.agr.kuleuven.ac.be/vakken/statisticsbyR/someDataStructures.htm - On Aug 16, 2012, at 11:49 AM, Schumacher, Jay S wrote: hi, i'm trying to understand r data structures. i see that vectors, matrix, factors and arrays have a dimension. there seems to be no mention of dimensionality anywhere for lists or dataframes. can i consider lists and frames to be of fixed dimension 2? About half of what you have deduced is wrong. Matrices, arrays, and dataframes do have dimensions, at least in technical R parlance, namely they have an attribute which can be queried with dim(). By definition matrices and dataframes have 2 dimensions. Arrays and matrices can be redimensioned, but dataframes cannot. Factors, lists, and atomic vectors do not have dimensions, but they do have lengths. An appropriately structured list (one with vectors all the same length) can be coerced to a dataframe with as.data.frame(). -- David Winsemius, MD Alameda, CA, USA __ R-help@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.
Re: [R] r data structures
On Thu, Aug 16, 2012 at 4:50 PM, Schumacher, Jay S j...@neo.tamu.edu wrote: are these correct/accurate/sensible statements: a vector is a one dimensional object. a matrix is a two dimensional object. a list is a one dimensional object. i'm working from this web page: http://www.agr.kuleuven.ac.be/vakken/statisticsbyR/someDataStructures.htm I would say not (personally) -- not everything has a dimension in R (everything does have a length though). To wit, x - 1:4 is.vector(x) # TRUE dim(x) # NULL length(dim(x)) # 0 Michael __ R-help@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.
Re: [R] r data structures
yes, thank you, conceptual model (rather than formal dimension attribute) is where i'm coming from at this point. It would be helpful to distinguish between a formal dimension attribute, and a (personal) conceptual model of whether or not any particular R object, or type of object, has dimension. Mention of data frames having dimension can be found in the help page for the dim() function. foo - 1:10 is.vector(foo) [1] TRUE dim(foo) NULL attributes(foo) NULL str(foo) int [1:10] 1 2 3 4 5 6 7 8 9 10 length(foo) [1] 10 bah - matrix(1:10, nrow=2) is.vector(bah)[1] FALSE dim(bah) [1] 2 5 attributes(bah) $dim [1] 2 5 str(bah) int [1:2, 1:5] 1 2 3 4 5 6 7 8 9 10 length(bah) [1] 10 The vector does not have a formal dimension (dim) attribute, but the matrix does. Regarding data frames and lists: ## ## data frame ## junk - data.frame(a=1:3,b=1:3) str(junk) 'data.frame': 3 obs. of 2 variables: $ a: int 1 2 3 $ b: int 1 2 3 attributes(junk) $names [1] a b $row.names [1] 1 2 3 $class [1] data.frame dim(junk) [1] 3 2 ## ## list ## glug - list(a=1, b=letters[3]) str(glug) List of 2 $ a: num 1 $ b: chr c attributes(glug) $names [1] a b dim(glug) NULL length(glug) [1] 2 Conceptually, I would consider data frames to have two dimensions (rows and columns). They do not have a formal dim attribute, but the dim() function does return a value. I personally do not think of lists as having dimension -- I never ask myself, what is the dimension of a list? But I do often enquire as to the length of a list, so might, if forced to, admit that lists have one dimension, length. But I do not think it is helpful to think of lists as having dimension. Certainly, lists do not have two dimensions. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/16/12 11:49 AM, Schumacher, Jay S j...@neo.tamu.edu wrote: hi, i'm trying to understand r data structures. i see that vectors, matrix, factors and arrays have a dimension. there seems to be no mention of dimensionality anywhere for lists or dataframes. can i consider lists and frames to be of fixed dimension 2? thanks, jay s __ R-help@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. __ R-help@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.
Re: [R] r data structures
On Aug 16, 2012, at 1:50 PM, Schumacher, Jay S wrote: are these correct/accurate/sensible statements: a vector is a one dimensional object. a matrix is a two dimensional object. a list is a one dimensional object. i'm working from this web page: http://www.agr.kuleuven.ac.be/vakken/statisticsbyR/someDataStructures.htm You can have as many personal representations of R structures as you want. If you are intent on communication with other useRs, I think you should restrict the use of dimension to objects that return a non-NULL value from dim(). And I think one should use 'length' for the dimension-like aspect for atomic vectors and lists. (I originally used the word attribute, but that is a specific function and applied to such structures would not return a length-value.) Dimensions is R can have other attributes such as names that often need to be accessed or manipulated One further source of confusion is length() applied to matrices or dataframes. It will return a value from matrices that is nrow()*ncol() and from dataframes (which are really lists under the hood) a value that is ncol(). The latter value is rather different than my naive expectation, which was that a dataframe's length would be the number of cases or rows. That webpage obviously has its own definition of dimension (and it's perfectly free to make up its own terms) but it is not one that is in accord with An Introduction to R or with typical R discourse. -- David. - On Aug 16, 2012, at 11:49 AM, Schumacher, Jay S wrote: hi, i'm trying to understand r data structures. i see that vectors, matrix, factors and arrays have a dimension. there seems to be no mention of dimensionality anywhere for lists or dataframes. can i consider lists and frames to be of fixed dimension 2? About half of what you have deduced is wrong. Matrices, arrays, and dataframes do have dimensions, at least in technical R parlance, namely they have an attribute which can be queried with dim(). By definition matrices and dataframes have 2 dimensions. Arrays and matrices can be redimensioned, but dataframes cannot. Factors, lists, and atomic vectors do not have dimensions, but they do have lengths. An appropriately structured list (one with vectors all the same length) can be coerced to a dataframe with as.data.frame(). -- David Winsemius, MD Alameda, CA, USA David Winsemius, MD Alameda, CA, USA __ R-help@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.
Re: [R] r data structures
I don't disagree with Michael, but I would add that to me it also depends. If one thinks in terms of subsetting an object (for objects that can be subsetted) To subset a vector, one supplies *one* value for the index: myvector[3] myvector[ 2:5 ] are valid statements. Similarly for a list mylist[4] mylist[ c(1,3) ] are valid statements. Whereas for a matrix or data frame, one must supply *two* index values (even if one of them may be omitted) mydf[ 1 , 3 ] mydf[ , 5 ] mymat[ 2:5 , ] mymat[ 3 , 4:6 ] are valid statements. So from that perspective, it's reasonable to think of vectors and lists having one dimension, and matrices and data frames as having two. Formally, it's a little different, since the underlying structure of a data frame is actually a list: junk - data.frame(a=1:3, b=letters[1:3] ) is.list(junk) [1] TRUE and lists do not, formally, have a dimension attribute. I would add that in everyday more or less casual work with R, matrices, arrays, and data frames are the only objects where I find it useful to think about their dimension. Otherwise it's length. Or maybe neither, for some objects. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/16/12 1:59 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: On Thu, Aug 16, 2012 at 4:50 PM, Schumacher, Jay S j...@neo.tamu.edu wrote: are these correct/accurate/sensible statements: a vector is a one dimensional object. a matrix is a two dimensional object. a list is a one dimensional object. i'm working from this web page: http://www.agr.kuleuven.ac.be/vakken/statisticsbyR/someDataStructures.htm I would say not (personally) -- not everything has a dimension in R (everything does have a length though). To wit, x - 1:4 is.vector(x) # TRUE dim(x) # NULL length(dim(x)) # 0 Michael __ R-help@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. __ R-help@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.
Re: [R] r data structures
On Thu, Aug 16, 2012 at 5:44 PM, MacQueen, Don macque...@llnl.gov wrote: Whereas for a matrix or data frame, one must supply *two* index values (even if one of them may be omitted) mydf[ 1 , 3 ] mydf[ , 5 ] mymat[ 2:5 , ] mymat[ 3 , 4:6 ] are valid statements. Not quite: x - matrix(rev(1:9), ncol = 3) x[5] x[2:6] x - data.frame(x) x[3] I understand this as meaning, when you don't use special 2D indexing, R falls back on 1D indexing behavior given by the relevant superclass: vector for matrix and list for data.frame. Cheers, RMW __ R-help@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.