[R] data.frame with a column containing an array
Georg Kindermann
Georg@K|nderm@nn @end|ng |rom gmx@@t
Fri May 26 16:23:37 CEST 2023
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