Bluebird
Bluebird

Reputation: 531

R paste() command and vectors

Afternoon. After the disastrous question I made in recent time (~5 hours ago) I, unfortunately, have another one.

I have a line of code

summary.myData<<-summarySE(myData, measurevar=paste(tx.choice1), groupvars=paste(tx.choice2[order1[[ind1]][1]],tx.choice2[order1[[ind1]][2]]),conf.interval=as.numeric(tclvalue(intervalplot_confidenceinterval)),na.rm=TRUE,.drop=FALSE);

specifically:groupvars=paste(tx.choice2[order1[[ind1]][1]],tx.choice2[order1[[ind1]][2]])

Would look like this:

paste(tx.choice2[order1[[ind1]][1]],tx.choice2[order1[[ind1]][2]]) [1] "Group Subgroup"

I want it to look like this groupvars=c("Group","Subgroup")

I have tried "groupvars=paste(tx.choice2[order1[[ind1]]",",",[1]],"tx.choice2[order1[[ind1]][2]]") but it would seem that I have a gross misunderstanding about how R, paste() and quotation marks works.

Would someone please point me in the right direction?

Upvotes: 2

Views: 617

Answers (1)

Nick Kennedy
Nick Kennedy

Reputation: 12640

You're confusing paste which is designed to join together multiple strings into one with c which joins multiple elements into a single vector:

e.g.

paste("a", "b")
# a character vector length 1 with contents "a b"

c("a", "b")
# a character vector length 2 with contents "a", "b"

For your purposes you don't need paste at all, you want c. I.e.

summary.myData<<-summarySE(myData, measurevar=tx.choice1, groupvars=c(tx.choice2[order1[[ind1]][1]],tx.choice2[order1[[ind1]][2]]),conf.interval=as.numeric(tclvalue(intervalplot_confidenceinterval)),na.rm=TRUE,.drop=FALSE)

Note you also probably don't need to be using the <<- operator - the regular <- assignment operator is probably what you mean though it's hard to be sure without context.

Upvotes: 3

Related Questions