Skip to content

Passing variable name

2 messages · Jim Lemon, Rui Barradas

#
Sorry, Bert, I also forgot to copy to the list.

Hi Seyet Ali,
If you have created the data frame, you probably know that "Gender",
"Hand" and "Gr" are the names of the vectors of values that are joined
in the data frame "MyData". You now wish to change those names. I
don't know why you would change the names to obscure ones like "V1",
but I suggest a look at the "names" function. The answer to your
question should now be clear to you.

Jim
On Mon, Dec 28, 2020 at 8:47 AM Jim Lemon <drjimlemon at gmail.com> wrote:
#
Hello,

Or maybe V1 and V2 are variables that hold column names?
If so see thess StackOverflow posts [1], [2]. The trick is to use [[, 
not $ to extractthe columns.


V1 <- "Gender"
V2 <- "Hand"

MyT2 <- table(MyData[[V1]], MyData[[V2]])


[1]: 
https://stackoverflow.com/questions/18222286/dynamically-select-data-frame-columns-using-and-a-vector-of-column-names

[2]: 
https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-el


Hope this helps,

Rui Barradas


?s 21:48 de 27/12/20, Jim Lemon escreveu: