Re: [R] assigning dimnames to arrays

2017-03-21 Thread Jeff Newmiller
Thanks, Bill. Sooo... taking the error literally, temp1 = array(NA, c(3,2,1)) dimnames(temp1)[[3]] = list( "test" ) works, even though mode( dimnames(temp1)[[3]] ) yields "character". Setting all the dimension names simultaneously still feels way better. -- Sent from my phone. Please excu

Re: [R] assigning dimnames to arrays

2017-03-21 Thread William Dunlap via R-help
It happens because dimnames(originalArray) is NULL and when [[<- extends NULL it turns it into a list if the size of the new element is not one but into a vector with the type of new element if the new element's size is one. > str( `[[<-`(NULL, 3, value="One") ) chr [1:3] NA NA "One" > str(

Re: [R] assigning dimnames to arrays

2017-03-21 Thread Jeff Newmiller
While I generally agree that it is better to design code that sets all of the dimension names simultaneously, the discrepancy between behavior when the dimensions are longer than 1 and when they are equal to 1 seems irregular. Someone went to some lengths to make it possible to set dimnames indi

Re: [R] assigning dimnames to arrays

2017-03-21 Thread David Winsemius
> On Mar 20, 2017, at 4:46 PM, Douglas Ezra Morrison > wrote: > > Dear R-Help readers, > > I am writing to ask about some behavior of base::dimnames() that surprised > me. If I create an array with one of its dimensions = 1, and then try to > assign names to that dimension, I get an error unle

[R] assigning dimnames to arrays

2017-03-20 Thread Douglas Ezra Morrison
Dear R-Help readers, I am writing to ask about some behavior of base::dimnames() that surprised me. If I create an array with one of its dimensions = 1, and then try to assign names to that dimension, I get an error unless I name one of the other dimensions first. For example: > temp1 = array(NA,