Re: [R] Replace double slashes with single backslash

2020-12-28 Thread Anbu A
Thank you, Jim. That clarifies. I am trying to pass this path in a loop and
read the files  associated with the path.
Yes the length is 26 where double quotes are counted as single quotes. Let
me try to read the files using the collected path.

Really appreciate it.

Thanks,
Anbu

On Mon, Dec 28, 2020 at 6:27 PM jim holtman  wrote:

> Why do you want to replace '\\' with '\' in the file names?  They are
> actually single '\' in the character string, but are printing out as '\\'.
> see example below:
>
> > x <- 'a\\b'
> > x
> [1] "a\\b"
> > nchar(x)
> [1] 3
>
> Jim Holtman
> *Data Munger Guru*
>
>
> *What is the problem that you are trying to solve?Tell me what you want to
> do, not how you want to do it.*
>
>
> On Mon, Dec 28, 2020 at 1:20 PM Bert Gunter 
> wrote:
>
>> "\" is an escape in R. See ?Quotes for details.
>>
>> 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 Mon, Dec 28, 2020 at 12:56 PM Anbu A  wrote:
>>
>> > Hi All,
>> > I am able to replace "r" with "x" for the word "Users" just for a test
>> run.
>> > *Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x"))  *- this
>> > works fine
>> > But when I try to replace "\\" with "\".
>> > *newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
>> > prompt ">" to complete the code. Not working. There is something on
>> > backslashes to be "masked".
>> > Any help would be appreciated.
>> >
>> >fpath new_col
>> > 1 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> > 2 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> > 3 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> > 4 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> > 5 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>> >
>> > Thanks,
>> > Anbu.
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@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]]
>>
>> __
>> R-help@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]]

__
R-help@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.


Re: [R] Error: Discrete value supplied to continuous variable

2020-12-28 Thread jim holtman
You setup your X & Y axis incorrectly.  in your call to ggplot you have:

g <-df %>%
  ggplot(aes(x=reorder(job,-span), y=span, fill=factor(job))) +

but in your call to geom_rect you are using a completely different set
of variables that is causing the error:

 geom_rect(aes(xmin = ID - w/2,
xmax = ID + w/2,
ymin = ymin,
ymax = ymax,
fill = factor(job)), alpha=0.25)

I changed the call to ggplot to at least have the same variables types
and got a plot out of it; is this what you were expecting:

  ggplot(aes(x=ID, y=ymin, fill=factor(job))) +



Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Dec 28, 2020 at 4:33 PM King, Barry  wrote:
>
> I am attempting to convert an original schedule to longest operating time 
> next schedule then create waterfall plot. I am having trouble with the plot. 
> I get an Error: Discrete vale supplied to continuous variable message. My 
> example code appears below.
>
> library(tidyverse)
> library(ggplot2)
>
> # original schedule of four jobs
> df <- data.frame(job=c("A","B","C","D"),
>  original_begin=c("2021-01-05 07:00:00", "2021-05-01 
> 08:30:00",
>  "2021-05-01 10:30:00", "2021-05-01 
> 14:00:00"),
>  original_end=c("2021-01-05 08:30:00", "2021-05-01 10:30:00",
>"2021-05-01 14:00:00", "2021-05-01 16:00:00"))
>
> # represent date/times as POSIXct objects
> df$original_begin <- as.POSIXct(df$original_begin)
> df$original_end <- as.POSIXct(df$original_end)
>
> # calculate span, length of time each job takes
> df$span <- as.numeric(difftime(df$original_end,df$original_begin))
>
> # sort by span descending
> df <- arrange(df,-span)
>
> # assign ID now that df is correcly sorted
> df$ID <- as.numeric(rownames(df))
>
> # calculate ymin and ymax
> df$ymin[1] <- min(df$original_begin)
> for (i in 1:(nrow(df)-1)) {
>   df$ymax[i] <- df$ymin[i] + df$span[i]
>   df$ymin[i+1] <- df$ymax[i]
> }
> df$ymax[nrow(df)] <- df$ymin[nrow(df)] +
>   df$span[nrow(df)]
>
> # following is loosely based on tutorial found at
> # https://www.stomperusa.com/2019/05/27/basic-waterfall-graphs-in-r/
>
> # set up plot canvas, longest job first (see x=reorder(job,-span))
> g <-df %>%
>   ggplot(aes(x=reorder(job,-span), y=span, fill=factor(job))) +
>   theme_classic() +
>   theme(legend.title=element_blank())+
>   theme(legend.position = "right", panel.grid = element_blank(),
> axis.text.x = element_text(angle = 90, vjust = 0.5)) +
>   labs(y = "Hours", x = "Job")
> g  # seems to be working as expected through here
>
> w <- 0.5  # use to set width of bars
>
> # attempt to create waterfall plot
> g <- g +
>   geom_rect(aes(xmin = ID - w/2,
> xmax = ID + w/2,
> ymin = ymin,
> ymax = ymax,
> fill = factor(job)), alpha=0.25)
> g
>
> Any assistance is appreciated
>
>
> Sent from Mail for Windows 10
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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.

__
R-help@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.


[R] Error: Discrete value supplied to continuous variable

2020-12-28 Thread King, Barry
I am attempting to convert an original schedule to longest operating time next 
schedule then create waterfall plot. I am having trouble with the plot. I get 
an Error: Discrete vale supplied to continuous variable message. My example 
code appears below.

library(tidyverse)
library(ggplot2)

# original schedule of four jobs
df <- data.frame(job=c("A","B","C","D"),
 original_begin=c("2021-01-05 07:00:00", "2021-05-01 08:30:00",
 "2021-05-01 10:30:00", "2021-05-01 14:00:00"),
 original_end=c("2021-01-05 08:30:00", "2021-05-01 10:30:00",
   "2021-05-01 14:00:00", "2021-05-01 16:00:00"))

# represent date/times as POSIXct objects
df$original_begin <- as.POSIXct(df$original_begin)
df$original_end <- as.POSIXct(df$original_end)

# calculate span, length of time each job takes
df$span <- as.numeric(difftime(df$original_end,df$original_begin))

# sort by span descending
df <- arrange(df,-span)

# assign ID now that df is correcly sorted
df$ID <- as.numeric(rownames(df))

# calculate ymin and ymax
df$ymin[1] <- min(df$original_begin)
for (i in 1:(nrow(df)-1)) {
  df$ymax[i] <- df$ymin[i] + df$span[i]
  df$ymin[i+1] <- df$ymax[i]
}
df$ymax[nrow(df)] <- df$ymin[nrow(df)] +
  df$span[nrow(df)]

# following is loosely based on tutorial found at
# https://www.stomperusa.com/2019/05/27/basic-waterfall-graphs-in-r/

# set up plot canvas, longest job first (see x=reorder(job,-span))
g <-df %>%
  ggplot(aes(x=reorder(job,-span), y=span, fill=factor(job))) +
  theme_classic() +
  theme(legend.title=element_blank())+
  theme(legend.position = "right", panel.grid = element_blank(),
axis.text.x = element_text(angle = 90, vjust = 0.5)) +
  labs(y = "Hours", x = "Job")
g  # seems to be working as expected through here

w <- 0.5  # use to set width of bars

# attempt to create waterfall plot
g <- g +
  geom_rect(aes(xmin = ID - w/2,
xmax = ID + w/2,
ymin = ymin,
ymax = ymax,
fill = factor(job)), alpha=0.25)
g

Any assistance is appreciated


Sent from Mail for Windows 10


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Replace double slashes with single backslash

2020-12-28 Thread jim holtman
Why do you want to replace '\\' with '\' in the file names?  They are
actually single '\' in the character string, but are printing out as '\\'.
see example below:

> x <- 'a\\b'
> x
[1] "a\\b"
> nchar(x)
[1] 3

Jim Holtman
*Data Munger Guru*


*What is the problem that you are trying to solve?Tell me what you want to
do, not how you want to do it.*


On Mon, Dec 28, 2020 at 1:20 PM Bert Gunter  wrote:

> "\" is an escape in R. See ?Quotes for details.
>
> 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 Mon, Dec 28, 2020 at 12:56 PM Anbu A  wrote:
>
> > Hi All,
> > I am able to replace "r" with "x" for the word "Users" just for a test
> run.
> > *Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x"))  *- this
> > works fine
> > But when I try to replace "\\" with "\".
> > *newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
> > prompt ">" to complete the code. Not working. There is something on
> > backslashes to be "masked".
> > Any help would be appreciated.
> >
> >fpath new_col
> > 1 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> > 2 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> > 3 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> > 4 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> > 5 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> >
> > Thanks,
> > Anbu.
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@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]]
>
> __
> R-help@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]]

__
R-help@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.


Re: [R] Replace double slashes with single backslash

2020-12-28 Thread Bert Gunter
"\" is an escape in R. See ?Quotes for details.

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 Mon, Dec 28, 2020 at 12:56 PM Anbu A  wrote:

> Hi All,
> I am able to replace "r" with "x" for the word "Users" just for a test run.
> *Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x"))  *- this
> works fine
> But when I try to replace "\\" with "\".
> *newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
> prompt ">" to complete the code. Not working. There is something on
> backslashes to be "masked".
> Any help would be appreciated.
>
>fpath new_col
> 1 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> 2 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> 3 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> 4 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
> 5 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
>
> Thanks,
> Anbu.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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]]

__
R-help@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.


[R] Replace double slashes with single backslash

2020-12-28 Thread Anbu A
Hi All,
I am able to replace "r" with "x" for the word "Users" just for a test run.
*Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x"))  *- this
works fine
But when I try to replace "\\" with "\".
*newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
prompt ">" to complete the code. Not working. There is something on
backslashes to be "masked".
Any help would be appreciated.

   fpath new_col
1 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
2 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
3 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
4 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\
5 C:\\Users\\Anbu\\Desktop\\sas\\ C:\\Usexs\\Anbu\\Desktop\\sas\\

Thanks,
Anbu.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Passing variable name

2020-12-28 Thread Avi Gross via R-help
There are endless ways to do what you want, Seyit. If you wish to remain in 
base R, using the names function on the left-hand side changes the names as in:

names(something) <- c("new", "names")

And in general, you may want to learn how to use an alternate set of methods 
that work well with ggplot in the tidyverse such as select() that lets you 
choose which columns of a data.frame (or tibble) to keep while optionally 
renaming them, and the rename() function and the mutate() function and ways to 
combine them to do lots of work. They also allow you to not use within() the 
way you are doing.

It is amusing you want names like V1. Indeed some R functions default to such 
names.

-Original Message-
From: R-help  On Behalf Of Seyit Ali KAYIS
Sent: Monday, December 28, 2020 1:32 PM
To: 'Bert Gunter' ; 'R-help' ; 
erdogancev...@gmail.com; drjimle...@gmail.com
Subject: Re: [R] Passing variable name

Hi Bert, 

 

Thanks a lot for informing me regarding the html format of my email. 

 

I also would like to thank to Erdogan CEVHER and Jim LEMON for their kind 
reply/suggestions. Yes I am aware of names function in R which is not the one I 
am looking for in here. Let me try to explain in another way.

 

The below part includes data generation, making cross-tab, Chi-Squared test and 
bar plot through ggplot. 

 

###

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")



###



Let’s say I have hundreds of variables (e.g SNP data). By using above codes I 
can perform what I need. However , I need to copy/paste variable name(s) for 
making table, Chi-Square test, and ggplot. This increase the chance of 
incorrectly copying/pasting variable name(s). What I can do is define variable 
name(s) earlier and pass that names to making table, Chi-Square test, and 
ggplot part. I believe there is a way to do it. I tried “paste” function (as 
below), but it did not work either.



Any comment/help is deeply appreciated.



Kind Regards



Seyit Ali



##

V1 <- "Gender"

V2 <- "Hand"



MyT2 <- table(paste('MyData$',V1), paste('MyData$',V2) )

print(MyT)



MyChi<- chisq.test(MyT)

print(MyChi)



dMyT <- data.frame(as.table(as.matrix(table(paste('MyData$',V1), 
paste('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")



#









From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
Sent: Monday, 28 December 2020 12:08 AM
To: seyitali.ka...@ibu.edu.tr
Cc: R-help 
Subject: Re: [R] Passing variable name



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 mailto:seyitali.ka...@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",

Re: [R] Passing variable name

2020-12-28 Thread Rui Barradas

Hello,

In my previous post I had meant something like the following.
The two important parts are the use of `[[` in table() and the use of 
get() in the ggplot call.



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)
})

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

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

MyChi <- chisq.test(MyT2)
MyChi

name2 <- c(V1, V2, "Frequency")
dMyT <- as.data.frame(MyT2)
names(dMyT) <- name2

library(ggplot2)

ggplot(data = na.omit(dMyT), aes(get(V1), Frequency, fill = get(V2))) +
  geom_bar(position = "dodge", stat = "identity") +
  labs(x = V1, fill = V2)


Is this what you want?

Hope this helps,

Rui Barradas

Às 18:31 de 28/12/20, Seyit Ali KAYIS escreveu:

Hi Bert,

  


Thanks a lot for informing me regarding the html format of my email.

  


I also would like to thank to Erdogan CEVHER and Jim LEMON for their kind 
reply/suggestions. Yes I am aware of names function in R which is not the one I 
am looking for in here. Let me try to explain in another way.

  


The below part includes data generation, making cross-tab, Chi-Squared test and 
bar plot through ggplot.

  


###

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")



###



Let’s say I have hundreds of variables (e.g SNP data). By using above codes I 
can perform what I need. However , I need to copy/paste variable name(s) for 
making table, Chi-Square test, and ggplot. This increase the chance of 
incorrectly copying/pasting variable name(s). What I can do is define variable 
name(s) earlier and pass that names to making table, Chi-Square test, and 
ggplot part. I believe there is a way to do it. I tried “paste” function (as 
below), but it did not work either.



Any comment/help is deeply appreciated.



Kind Regards



Seyit Ali



##

V1 <- "Gender"

V2 <- "Hand"



MyT2 <- table(paste('MyData$',V1), paste('MyData$',V2) )

print(MyT)



MyChi<- chisq.test(MyT)

print(MyChi)



dMyT <- data.frame(as.table(as.matrix(table(paste('MyData$',V1), paste('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")



#









From: Bert Gunter [mailto:bgunter.4...@gmail.com]
Sent: Monday, 28 December 2020 12:08 AM
To: seyitali.ka...@ibu.edu.tr
Cc: R-help 
Subject: Re: [R] Passing variable name



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 mailto:seyitali.ka...@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

Re: [R] Passing variable name

2020-12-28 Thread Seyit Ali KAYIS
Hi Bert, 

 

Thanks a lot for informing me regarding the html format of my email. 

 

I also would like to thank to Erdogan CEVHER and Jim LEMON for their kind 
reply/suggestions. Yes I am aware of names function in R which is not the one I 
am looking for in here. Let me try to explain in another way.

 

The below part includes data generation, making cross-tab, Chi-Squared test and 
bar plot through ggplot. 

 

###

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")



###



Let’s say I have hundreds of variables (e.g SNP data). By using above codes I 
can perform what I need. However , I need to copy/paste variable name(s) for 
making table, Chi-Square test, and ggplot. This increase the chance of 
incorrectly copying/pasting variable name(s). What I can do is define variable 
name(s) earlier and pass that names to making table, Chi-Square test, and 
ggplot part. I believe there is a way to do it. I tried “paste” function (as 
below), but it did not work either.



Any comment/help is deeply appreciated.



Kind Regards



Seyit Ali



##

V1 <- "Gender"

V2 <- "Hand"



MyT2 <- table(paste('MyData$',V1), paste('MyData$',V2) )

print(MyT)



MyChi<- chisq.test(MyT)

print(MyChi)



dMyT <- data.frame(as.table(as.matrix(table(paste('MyData$',V1), 
paste('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")



#









From: Bert Gunter [mailto:bgunter.4...@gmail.com] 
Sent: Monday, 28 December 2020 12:08 AM
To: seyitali.ka...@ibu.edu.tr
Cc: R-help 
Subject: Re: [R] Passing variable name



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 mailto:seyitali.ka...@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="iden

[R] Interpreting coefficient in selection and outcome Heckman models in sampleSelection

2020-12-28 Thread Marinella Cirillo via R-help
Dear Arne,

I have just read the exchange of messages with Mark Bulling.I was wondering if 
you have discovered/developed a function to calculate the marginal effects of 
the selection and outcome equations (sampleSelection).



Thank you

Marinella
[[alternative HTML version deleted]]

__
R-help@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.