[R] Passing variable name
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Sun Dec 27 22:08:23 CET 2020
This is a *plain text* list. As you can see from the included text that I
received, the HTML version that you sent was somewhat mangled by the
server. I do not know whether or not enough got through for you to get a
helpful reply, but if not, re-send *to the list, not me* in *plain text*.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sun, Dec 27, 2020 at 12:25 PM Seyit Ali KAYIS <seyitali.kayis using ibu.edu.tr>
wrote:
> Dear R users,
>
> �
>
> I have a data frame as below. In part 1, I have created a table for Gender
> and Hand, performed Chi-Square test and made graph using ggplot.
>
> �
>
> I want to replace the original variable names (Gender and Hand) with V1
> and V2 and to be able to perform those things again as in #part 2. Is there
> a way to be able to replace the original names?
>
> �
>
> Any help is deeply appreciated
>
> �
>
> Kind Regards
>
> �
>
> Seyit Ali
>
> �
>
>
> #############################################################################
>
> �
>
> MyData<-data.frame("Gender" = c("F", "F", "F", "F",
> "M", "M", "M", "M", "M", "M", "F",
> "F"),
>
> "Hand" = c("R", "R", "L", "L",
> "R", "R", "L", "L", "R",
> "R", "L", "L"),
>
> "Gr" = c(1, 2, 1, 2,
> 1, 2, 1, 2, 1, 2,
> 1, 2) )
>
>
>
> MyData <- within(MyData, {
>
> Gender <- factor(Gender)
>
> Hand <- factor(Hand)
>
> Gr <- factor(Gr)
>
> }
>
> )
>
> �
>
> str(MyData)
>
> �
>
> library(ggplot2)
>
> �
>
> ################# Part 1 #########################################
>
> �
>
> MyT <- table(MyData$Gender, MyData$Hand)
>
> print(MyT)
>
> �
>
> MyChi<- chisq.test(MyT)
>
> print(MyChi)
>
> dMyT <- data.frame(as.table(as.matrix(table(MyData$Gender, MyData$Hand,
> useNA = "ifany"))))
>
> name2<- c("Gender", "Hand", "Frequency")
>
>
> names(dMyT) <- name2
>
> �
>
> ggplot(data = na.omit(dMyT), aes(fill=Hand, y=Frequency, x=Gender)) +
>
> geom_bar(position="dodge", stat="identity")
>
> �
>
> ################# Part 2 ################
>
> �
>
> # I want to be able to pass Gender and Hand as V1 and V2 , respectively to
>
> # table, Chi-Square test and ggplot
>
> �
>
> V1 <- "Gender"
>
> V2 <- "Hand"
>
> �
>
> MyT2 <- table(MyData$V1, MyData$V2)
>
> �
>
> print(MyT)
>
> �
>
> MyChi<- chisq.test(MyT)
>
> print(MyChi)
>
> dMyT <- data.frame(as.table(as.matrix(table(MyData$V1, MyData$V2, useNA =
> "ifany"))))
>
> name2<- c(V1, V2, "Frequency")
>
> names(dMyT) <- name2
>
> �
>
> ggplot(data = na.omit(dMyT), aes(fill=V2, y=Frequency, x=V1)) +
>
> geom_bar(position="dodge", stat="identity")
>
> �
>
> �
>
> �
>
> �
>
> ----------------------------------------------------
>
> Dr. Seyit Ali KAYIS
>
> Bolu Abant Izzet Baysal University, Faculty of Medicine
>
> Department of Biostatistics and Medical Informatics
>
> Bolu, Turkey
>
>
>
> <mailto:s_a_kayis using yahoo.com> s_a_kayis using yahoo.com, <mailto:
> s_a_kayis using hotmail.com> s_a_kayis using hotmail.com
>
> Tel: +90 374 254 30 32 Mobile: +90 535 587 1139
>
>
>
> Greetings from Bolu, Turkey
>
> ------------------------------------------------------
>
> �
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list