[R] data.frame with a column containing an array

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Fri May 26 21:05:44 CEST 2023


Please refer to Jeff Newmiller's response. I believe that your further
exploration of indexing a data frame containing an array column
demonstrates his point: don't do it!

As this discussion could now devolve into a morass of personal opinion
(such as the above), if you or others care to continue, please do so
**offlist**. However, I have nothing further to say in any case.

Cheers,
Bert

On Fri, May 26, 2023 at 7:23 AM Georg Kindermann
<Georg.Kindermann using gmx.at> wrote:
>
> Dear Bert!
>
> Thanks for the answer.
> Just let me summarize the current (4.3.0) behavior.
>
>
> DF <- data.frame(id = 1:2)
> DF[["ar"]] <- array(1:8, c(2,2,2))
>
> #Converts array to vector
> #Removes dim and takes selected elements from first column
> DF[1,]
> #  id ar
> #1  1  1
>
> str(DF[1,])
> #'data.frame':   1 obs. of  2 variables:
> # $ id: int 1
> # $ ar: int 1
>
>
> #Converts array to vector
> #Removes dim and takes selected elements
> DF[c(TRUE, FALSE),]
> #  id ar
> #1  1  1
> #Warning message:
> #In format.data.frame(if (omit) x[seq_len(n0), , drop = FALSE] else x,  :
> #  corrupt data frame: columns will be truncated or padded with NAs
>
> str(DF[c(TRUE, FALSE),])
> #'data.frame':   1 obs. of  2 variables:
> # $ id: int 1
> # $ ar: int  1 3 5 7
>
>
> #Converts array to vector
> #Removes dim and takes selected elements from first column and
> #adds all elements form the remaining data
> DF[-2,]
> #  id ar
> #1  1  1
> #Warning message:
> #In format.data.frame(if (omit) x[seq_len(n0), , drop = FALSE] else x,  :
> #  corrupt data frame: columns will be truncated or padded with NAs
>
> str(DF[-2,])
> #'data.frame':   1 obs. of  2 variables:
> # $ id: int 1
> # $ ar: int  1 3 4 5 6 7 8
>
>
> #Converts array to vector
> #Removes dim but keeps all elements
> DF[TRUE,]
> #  id ar
> #1  1  1
> #2  2  2
> #Warning message:
> #In format.data.frame(if (omit) x[seq_len(n0), , drop = FALSE] else x,  :
> #  corrupt data frame: columns will be truncated or padded with NAs
>
> str(DF[TRUE,])
> #'data.frame':   2 obs. of  2 variables:
> # $ id: int  1 2
> # $ ar: int  1 2 3 4 5 6 7 8
>
>
> Kind regards,
> Georg
>
>
> Gesendet: Donnerstag, 25. Mai 2023 um 19:15 Uhr
> Von: "Bert Gunter" <bgunter.4567 using gmail.com>
> An: "Georg Kindermann" <Georg.Kindermann using gmx.at>
> Cc: "Rui Barradas" <ruipbarradas using sapo.pt>, r-help using r-project.org
> Betreff: Re: Re: [R] data.frame with a column containing an array
>
> I really don't know. I would call it a request for extended capabilities of [.data.frame, rather than a feature or bug. But maybe wiser heads than mine who monitor this list can sort it out.
>
> -- Bert



More information about the R-help mailing list