2

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?

Bluebird
  • 531
  • 1
  • 5
  • 18
  • Please make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output. We really have no idea what's in your variables so it's not clear what's going on. – MrFlick Jul 29 '15 at 18:27
  • 1
    maybe just add a `c`, ie `paste(c(1,2))` instead of `paste(1, 2)` – Rorschach Jul 29 '15 at 18:28
  • It worked thanks. Funny how I was missing three letters. I wanted to ask why didn't it work outside of paste()? As in `c(paste(...))` I have tried that, but no luck there. – Bluebird Jul 29 '15 at 18:30
  • 1
    For your future sanity, I strongly recommend stepping through the creation of your indexes so you can immediately identify how you did it in the past. – Brandon Bertelsen Jul 29 '15 at 18:31
  • Don't think I quite got that, this is how I understand it. I should keep track of all of the steps that I did to try to solve the problem on my own, and note it when I ask a question? Or are you referring to the tx.choice things? – Bluebird Jul 29 '15 at 18:33
  • Doing too much in one line can create confusion. Assign some of those expressions to variables. At least in the beginning to follow the logic of your code. You can optimize speed and memory once the code works. – Pierre L Jul 29 '15 at 18:38
  • I think I understand. Like this? `test<-paste(tx.choice2[order1[[ind1]][1]],tx.choice2[order1[[ind1]][2]])` then `some_command(...groupvars=test...)` – Bluebird Jul 29 '15 at 18:40

1 Answers1

3

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.

Nick Kennedy
  • 12,510
  • 2
  • 30
  • 52
  • I apologize for the confusion. the <<- is required because it would be modifying (what I come to understand as) a 'global variable' within the GUI I am working on. I have tried to post with more context, but to very messy results. Namely [here](https://stackoverflow.com/questions/31704713/r-command-grammar-or-perhaps-another-word) – Bluebird Jul 30 '15 at 02:09