[Rd] transform
Gabor Grothendieck
ggrothend|eck @end|ng |rom gm@||@com
Sat Aug 24 16:41:57 CEST 2024
One oddity in transform that I recently noticed. It seems that to include
a one-column data frame in the arguments one must name it even though the
name is ignored. If the data frame has more than one column then it must
also be named but in that case it is not ignored and the names are made up of
a combination of that name and the data frame's names. I would have thought
that if we did not want a combination of names we would just not name the
argument.
# ignores second argument returning BOD unchanged
transform(BOD, data.frame(y = 1:6)) |> names()
## [1] "Time" "demand"
# ignores second argument returning BOD unchanged
transform(BOD, data.frame(y = 1:6, z = 6:1)) |> names()
## [1] "Time" "demand"
# with one column in data frame it adds the column and names it y ignoring x
transform(BOD, x = data.frame(y = 1:6)) |> names()
## [1] "Time" "demand" "y"
# with multiple columns in data frame it uses x.y and x.z as names
transform(BOD, data.frame(y = 1:6, z = 6:1)) |> names()
## [1] "Time" "demand" "x.y" "x.z"
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-devel
mailing list