of dynamism.
Be that as it may I think the requester has enough info and we can
move on.
-Original Message-
From: Jeff Newmiller
Sent: Friday, July 2, 2021 1:03 AM
To: Avi Gross ; Avi Gross via R-help
; R-help@r-project.org
Subject: Re: [R] concatenating columns in data.frame
I use pa
vi Gross ; Avi Gross via R-help
; R-help@r-project.org
Subject: Re: [R] concatenating columns in data.frame
I use parts of the tidyverse frequently, but this post is the best argument I
can imagine for learning base R techniques.
On July 1, 2021 8:41:06 PM PDT, Avi Gross via R-help
wro
as it may I think the requester has enough info and we can move on.
-Original Message-
From: Jeff Newmiller
Sent: Friday, July 2, 2021 1:03 AM
To: Avi Gross ; Avi Gross via R-help
; R-help@r-project.org
Subject: Re: [R] concatenating columns in data.frame
I use parts of the tidyverse f
ollowing needs newish features:
>
> "{colnew}" := SOMETHING
>
>The colon-equals operator in newer R/dplyr can be sort of used in an
>odd way that allows the name of the variable to be in quotes and in
>brackets akin to the way glue() does it. The variable colnew is
gle argument
that is either a vector or another kind of vector called a list. The trick is
to convert the vector into symbols then use "!!!" to convert something like
'c("alpha", "beta", "gamma")' into something more like ' "alpha",
Lovely one-liner Bert. Chapeau
On Thu, Jul 1, 2021 at 10:16 PM Berry, Charles
wrote:
>
>
> > On Jul 1, 2021, at 11:24 AM, Bert Gunter wrote:
> >
> > Why not simply:
> >
> > ## reprex
> > set.seed(123)
> > df = data.frame("A"=sample(letters, 10), "B"=sample(letters, 10),
> >"C"=s
> On Jul 1, 2021, at 11:24 AM, Bert Gunter wrote:
>
> Why not simply:
>
> ## reprex
> set.seed(123)
> df = data.frame("A"=sample(letters, 10), "B"=sample(letters, 10),
>"C"=sample(letters,10), "D"=sample(letters, 10))
> df
> use_columns = c("D", "B")
>
> ## one liner
> df$com
Why not simply:
## reprex
set.seed(123)
df = data.frame("A"=sample(letters, 10), "B"=sample(letters, 10),
"C"=sample(letters,10), "D"=sample(letters, 10))
df
use_columns = c("D", "B")
## one liner
df$combo_col <- do.call(paste,c(df[,use_columns], sep = "_"))
df
In case you are wo
> On Jul 1, 2021, at 7:36 AM, Micha Silver wrote:
>
> I need to create a new data.frame column as a concatenation of existing
> character columns. But the number and name of the columns to concatenate
> needs to be passed in dynamically. The code below does what I want, but seems
> very clu
You can do the same steps but without so much intermediate saving to
shorten it
f <- function(x) {
do.call(rbind,lapply(1:nrow(x),
function(r) {paste(x[r,], collapse="_")}))
}
df_combo <- cbind(df,Combo=f(df[,c(4,2)]))
HTH,
Eric
On Thu, Jul 1, 2021 at 5:37 PM Micha Sil
I need to create a new data.frame column as a concatenation of existing
character columns. But the number and name of the columns to concatenate
needs to be passed in dynamically. The code below does what I want, but
seems very clumsy. Any suggestions how to improve?
df = data.frame("A"=sampl
11 matches
Mail list logo