[R] Recall: transforming dates

2019-11-02 Thread reichmanj
reichm...@sbcglobal.net would like to recall the message, "transforming
dates".
__
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] transforming dates

2019-11-02 Thread reichmanj
R-Help Forum

 

I have a data set that contains a date field but the dates are in two
formats

 

11/7/2016dd/mm/

14-07-16   dd-mm-yy

 

How would I go about correcting this problem. Should I separate the dates,
format them , and then recombine?

 

Sincerely

 

Jeff Reichman

(314) 457-1966

 


[[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] Bar Charts

2019-10-16 Thread reichmanj
Jim

That’s certainly much more straight forward.

Jeff

-Original Message-
From: Jim Lemon  
Sent: Tuesday, October 15, 2019 8:51 PM
To: Jeff Reichman 
Cc: r-help mailing list 
Subject: Re: [R] Bar Charts

Hi Jeff,
Let's say you have the following data:

set.seed(12345)
CONTBR_RESULT<-sample(20:200,30)

If you don't mind ordering the results, you can do this:

barplot(rev(sort(CONTBR_RESULT))[1:15],...)

If you want the values in the original order:

barplot(CONTBR_RESULT[order(CONTBR_RESULT) > 15],...)

Jim

On Wed, Oct 16, 2019 at 11:21 AM  wrote:
>
> r-help forum
>
>
>
> I have a database that I have performed a "group_by" of a variable 
> called CONTBR_OCCUPATION. I then simply want to plot out just the top 
> 15 results as a bar plot. How do I plot only the top 15 groups on the 
> x -axis. Should I just extract the top 15 records and plot them or is the a 
> better way?
>
>
>
> occup <- myDat %>%
>
>   group_by(CONTBR_OCCUPATION) %>%
>
>   summarize(count = n()) %>%
>
>   arrange(desc(count))
>
>
>
> Jeff
>
>
>
>
> [[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] Bar Charts

2019-10-15 Thread reichmanj
r-help forum

 

I have a database that I have performed a "group_by" of a variable called
CONTBR_OCCUPATION. I then simply want to plot out just the top 15 results as
a bar plot. How do I plot only the top 15 groups on the x -axis. Should I
just extract the top 15 records and plot them or is the a better way?

 

occup <- myDat %>%

  group_by(CONTBR_OCCUPATION) %>%

  summarize(count = n()) %>%

  arrange(desc(count))

 

Jeff 

 


[[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] separate and gather functions

2019-08-14 Thread reichmanj
That's even easier

-Original Message-
From: Ista Zahn  
Sent: Tuesday, August 13, 2019 8:22 AM
To: reichm...@sbcglobal.net
Cc: William Dunlap ; r-help@r-project.org
Subject: Re: [R] separate and gather functions

How about

> library(tidyr)
> separate_rows(d, Col2)
  Col1  Col2
1 Agency A Function1
2 Agency A Function2
3 Agency A Function3
4 Agency A Function4
5 Agency B Function2
6 Agency B Function4
7 Agency C Function1
8 Agency C Function3
9 Agency C Function4


On Mon, Aug 12, 2019 at 11:06 PM  wrote:
>
> William
>
>
>
> Yes that works a little better as I don’t have to create notional 
> variables. Thank you
>
>
>
> Jeff
>
>
>
> From: William Dunlap 
> Sent: Monday, August 12, 2019 6:46 PM
> To: Jeff Reichman 
> Cc: r-help@r-project.org
> Subject: Re: [R] separate and gather functions
>
>
>
> This one uses only core R functions.  Does that count toward "elegance"?
>
>
>
> > # your data, I assume, in a form one can copy and paste into R
>
> > d <- data.frame(stringsAsFactors = FALSE,
> Col1 = c("Agency A", "Agency B", "Agency C"),
> Col2 = c("Function1, Function2, Function3, Function4",
> "Function2, Function4", "Function1, Function3, Function4"))
>
> > # split Col2 by comma following by any number of spaces
>
> > tmp <- strsplit(d$Col2, split=", *")
> > data.frame(Col1 = rep(d$Col1, lengths(tmp)), Col2 = unlist(tmp), 
> > stringsAsFactors=FALSE)
>   Col1  Col2
> 1 Agency A Function1
> 2 Agency A Function2
> 3 Agency A Function3
> 4 Agency A Function4
> 5 Agency B Function2
> 6 Agency B Function4
> 7 Agency C Function1
> 8 Agency C Function3
> 9 Agency C Function4
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com 
>
>
>
>
>
> On Mon, Aug 12, 2019 at 4:23 PM   > wrote:
>
> R-Help Forum
>
>
>
> I have a data set from which I have extracted two columns Column 1 is 
> a listing of Federal agencies and Column 2 lists functions like this
>
>
>
> Col1   Col2
>
> Agency A Function1, Function2, Function3, Function4
>
> Agency B  Function2, Function4
>
> Agency C  Function1, Function3, Function4
>
>
>
> What I need is a long list like this
>
>
>
> Col1   Col2
>
> Agency A Function1
>
> Agency A Function2
>
> Agency 4  Function3 etc
>
>
>
> Is there a more elegant /efficient way other than what I did which was 
> to separate Col2 into separate columns and then gather the data back 
> up
>
>
>
> myDat3 <- separate(data= myDat2, col = type, into = c("x1", "x2", 
> "x3", "x4", "x5"), sep = ",")
>
> myDat4 <- gather(data=myDat3, key="type", value = "Value", 
> "x1","x2","x3","x4","x5", na.rm = TRUE)
>
>
>
> while it works, looking for a more elegant solution, if there is one
>
>
>
> Jeff
>
>
> [[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-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] separate and gather functions

2019-08-12 Thread reichmanj
William

 

Yes that works a little better as I don’t have to create notional variables. 
Thank you

 

Jeff

 

From: William Dunlap  
Sent: Monday, August 12, 2019 6:46 PM
To: Jeff Reichman 
Cc: r-help@r-project.org
Subject: Re: [R] separate and gather functions

 

This one uses only core R functions.  Does that count toward "elegance"?

 

> # your data, I assume, in a form one can copy and paste into R

> d <- data.frame(stringsAsFactors = FALSE,
Col1 = c("Agency A", "Agency B", "Agency C"),
Col2 = c("Function1, Function2, Function3, Function4", 
"Function2, Function4", "Function1, Function3, Function4"))

> # split Col2 by comma following by any number of spaces

> tmp <- strsplit(d$Col2, split=", *")
> data.frame(Col1 = rep(d$Col1, lengths(tmp)), Col2 = unlist(tmp), 
> stringsAsFactors=FALSE)
  Col1  Col2
1 Agency A Function1
2 Agency A Function2
3 Agency A Function3
4 Agency A Function4
5 Agency B Function2
6 Agency B Function4
7 Agency C Function1
8 Agency C Function3
9 Agency C Function4

 

Bill Dunlap
TIBCO Software
wdunlap tibco.com  

 

 

On Mon, Aug 12, 2019 at 4:23 PM mailto:reichm...@sbcglobal.net> > wrote:

R-Help Forum



I have a data set from which I have extracted two columns Column 1 is a
listing of Federal agencies and Column 2 lists functions like this



Col1   Col2

Agency A Function1, Function2, Function3, Function4

Agency B  Function2, Function4

Agency C  Function1, Function3, Function4



What I need is a long list like this



Col1   Col2

Agency A Function1

Agency A Function2

Agency 4  Function3 etc



Is there a more elegant /efficient way other than what I did which was to
separate Col2 into separate columns and then gather the data back up



myDat3 <- separate(data= myDat2, col = type, into = c("x1", "x2", "x3",
"x4", "x5"), sep = ",")  

myDat4 <- gather(data=myDat3, key="type", value = "Value",
"x1","x2","x3","x4","x5", na.rm = TRUE)



while it works, looking for a more elegant solution, if there is one



Jeff


[[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] separate and gather functions

2019-08-12 Thread reichmanj
R-Help Forum

 

I have a data set from which I have extracted two columns Column 1 is a
listing of Federal agencies and Column 2 lists functions like this

 

Col1   Col2

Agency A Function1, Function2, Function3, Function4

Agency B  Function2, Function4

Agency C  Function1, Function3, Function4

 

What I need is a long list like this

 

Col1   Col2

Agency A Function1

Agency A Function2

Agency 4  Function3 etc

 

Is there a more elegant /efficient way other than what I did which was to
separate Col2 into separate columns and then gather the data back up

 

myDat3 <- separate(data= myDat2, col = type, into = c("x1", "x2", "x3",
"x4", "x5"), sep = ",")  

myDat4 <- gather(data=myDat3, key="type", value = "Value",
"x1","x2","x3","x4","x5", na.rm = TRUE)

 

while it works, looking for a more elegant solution, if there is one

 

Jeff


[[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] Plotting hclust() results

2019-08-05 Thread reichmanj
R Help Forum

I have output from hierarchal clustering and want to plot the results using
the ggplot2 function. Where I have a scatter plot with 5 lines representing
the 5 clusters. I assuming I need to transform the data into three columns
(like) cluster, variable, and value. Not an issue but was wondering if I
could plot the data as is.  

  Cluster A B C D E F
  
1   1  0.67  0.56  0.54  0.03 -0.97 -1.09
2   2  0.52  0.43  0.51  0.05 -0.86 -0.96
3   3  0.2   0.3   0.19  0.08  0.02  0.09
4   4 -1.3  -1.13 -1.78 -0.05 -0.23 -0.23
5   5 -1.6  -1.3  -1.34 -0.23 -0.45 -0.45

Something like

Cluster Var Value
1   A   0.67
1   B   0.56 etc

 Then group by cluster??

Jeff

__
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] tidyr gather(function)

2019-07-15 Thread reichmanj
r-help

 

Needing to transform some data for a time series (1930 - 2018). 

 

> tempDat
# A tibble: 89 x 13
Year   Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov
Dec
  

 1  1930  5260.3  60.6  72.2  71.7  86.8  91.3  89.7  82.3  70.4  60.2
52.2
 2  1931  52.9  57.8  62.7  72.4  80.5  8795.1  89.3  85.9  72.8  57.2
49.7
 3  1932  4756.8  61.9  69.3  77.2  84.7  91.9  92.1  8771.5  62.9
49.3
 
If I use the gather function:

 

tempDat.long <- gather(data=tempDat, key=month, value=temp, "Jan", "Feb",
"Mar",

 
"Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

 

> tempDat.long
# A tibble: 1,068 x 3
Year month  temp
 
 1  1930 Jan52  
 2  1931 Jan52.9
 3  1932 Jan47  
 4  1933 Jan48.8
 5  1934 Jan54.5

 

But I need it to be 

 

Year month  temp
 
 1  1930 Janxx.x  
 2  1930 Febxx.x
 3  1930 Marxx.x
 4  1930 Aprxx.x
 5  1930 Mayxx.x

 

So would I need to use the lubridate package to rearrange my data or is
there a more straight forward method?

 

 

Jeff Reichman


[[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] Separating Date and Time

2019-06-19 Thread reichmanj
R-Help

 

I'm using the following code to deparate the date and time components from a
date_time varaible as follows:

 

dt1$date <- format(as.POSIXct(dt1$date_time, format = "%m/%d/%Y %H:%M"),
"%Y-%m-%d")

dt1$time <- format(as.POSIXct(dt1$date_time, format = "%m/%d/%Y %H:%M"),
"%H:%M:%S")

 

But I end up with  objects. What am I missing?

 

Jeff


[[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] gganimate: A Grammar of Animated Graphics

2019-06-08 Thread reichmanj
Roy

Thank you , yes last night as I was reading through the library functions  I
saw the animate() function, for example  animate(map, fps = 2), where map is
a ggplot object

Jeff

-Original Message-
From: Roy Mendelssohn - NOAA Federal  
Sent: Friday, June 7, 2019 10:11 PM
To:  
Cc: r-help@r-project.org
Subject: Re: [R] gganimate: A Grammar of Animated Graphics

There may be other ways but you can store the animation in an object and use
the animate() function.

-Roy

> On Jun 7, 2019, at 7:31 PM, 
 wrote:
> 
> R-Help Forum
> 
> 
> 
> I've been exploring the gganimate package and  am wondering how one 
> might adjust the animation speed?
> 
> 
> 
> Jeff Reichman
> 
> 
> 
> 
>   [[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.

**
"The contents of this message do not reflect any position of the U.S.
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new street address***
110 McAllister Way
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK
Jr.

__
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] gganimate: A Grammar of Animated Graphics

2019-06-07 Thread reichmanj
R-Help Forum

 

I've been exploring the gganimate package and  am wondering how one might
adjust the animation speed?

 

Jeff Reichman

 


[[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] cspade {arulesSequences} error

2019-05-28 Thread reichmanj
Abby

 

My code runs just fine at home but when I transfer it to work and rerun it 
error out at the line shown. Even errors out when I try the example sin the 
package documentation. So I’m pretty sure is isn’t my code but rather how our 
IT folks have configured our work systems. Peter Dalgaard suggested that it 
might be our antivirus so I will look into that. As far as the D:\Temp location 
I changed that from the default thinking it may have been a read/write issue 
with my system.

 

Jeff

 

From: Abby Spurdle  
Sent: Monday, May 27, 2019 8:28 PM
To: reichm...@sbcglobal.net
Cc: r-help 
Subject: Re: [R] cspade {arulesSequences} error

 

> s1 <- cspade(trans_matrix, parameter = list(support = 0.3), control =
> list(verbose = TRUE))

> error in file (con, "r"): cannot open the connection. cannot open file
> 'D:\Temp\cspade13403a927eaa.out': no such file or directory

Note that you haven't provided a fully reproducible example.

(As I don't know what trans_matrix is, and I'm not sure at what point the error 
message is generated, which is important).

 

I installed the lasted versions of arules and arulesSequences.

I tried to run one of the examples from the cspade() function's documentation.

It ran without any problems.

 

Also note the location "D:\Temp" is suspicious. This is not where I would 
expect temporary files to be created, and makes me suspect there's something 
(somewhere on your computer) that's not typical. This could include your 
working directory, startup script files (if any), environment variables (if 
any) or other parts of your R code, or any OS settings.

 

Sorry, I know that's not the most helpful answer...

 

 


[[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] cspade {arulesSequences} error

2019-05-23 Thread reichmanj
R-Help

 

When I run the cspade function from the arulesSequences package...

 

s1 <- cspade(trans_matrix, parameter = list(support = 0.3), control =
list(verbose = TRUE))

#s1 <- cspade(trans_matrix, parameter = list(support = 0.3), control =
list(verbose = TRUE), tmpdir = "C:\\Temp")

 

I receive the following error .

error in file (con, "r"): cannot open the connection. cannot open file
'D:\Temp\cspade13403a927eaa.out': no such file or directory

 

now the program works just fine at home so the issue is with my  work
computer.  I suspect its some sort of read/write issue but the functions
seems to write the files out just fine then deletes them and errors out.

 

Any suggestions

 

Jeff Reichamn

 


[[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] Calculating date difference in days

2019-05-22 Thread reichmanj
R Help

I have a function to calculate a date difference in days but my results come
back in hours.  I suspect I am using the as.POSIXlt function incorrectly . 

Suggestions?

# Start time of data to be considered 
start_day <- "2016-04-30"

# Make event and sequence IDs into factors 
elapsed_days <- function(end_date, start_date){
  ed <- as.POSIXlt(end_date) 
  sd <- as.POSIXlt(start_date) 
  ed-sd 
}

trans_sequence$eventID <- elapsed_days(trans_sequence$Date, start_day)


> trans_sequence
# A tibble: 39 x 5
# Groups:   Emitter [15]
   Emitter DateSIZE Geohash
eventID  

   
 1   1 2016-05-0112 A;B;C;D;E;F;G;H;I;J;K;L
19 hours
 2   1 2016-05-02 5 A;B;C;D;E
43 hours
 3   1 2016-05-0511 A;B;C;D;E;F;G;H;I;J;K
115 hours
 4   2 2016-05-01 9 C;D;E;F;G;H;I;J;K
19 hours
 5   2 2016-05-02 3 F;G;H
43 hours
 6   2 2016-05-05 3 L;M;N
115 hours
 7   3 2016-05-01 3 L;M;N
19 hours
 8   3 2016-05-02 3 I;J;K
43 hours
 9   3 2016-05-0425
A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y  91 hours
10   3 2016-05-05 7 O;P;Q;R;S;T;U
115 hours

Jeff Reichman


[[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] Date Time Conversion

2019-05-08 Thread reichmanj
r-Help Community

 

Never mine figured it out just use the "as.POSIXct" function

 

Jeff

 

I need to convert a date-time field (column)  but I'm losing the time  when
I convert using  ..

 

tsData <- myData[,10, drop=FALSE]

tsData$date_time <- as.Date(tsData$date_time, format="%m/%d/%y %H:%M")

head(tsData)

 


 

 

date_time





1

2013-06-20



2

2013-06-20



3

2013-06-20



4

2013-06-20



5

2013-05-30



6

2013-06-20



 

R is doing what I'm asing it to do so I'm obviously using the wrong command.
How do I convert, retaining the time 

 

Sincerely

 

Jeffery (Jeff) Reichman


[[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] Date Time Conversion

2019-05-08 Thread reichmanj
r-Help Community

 

I need to convert a date-time field (column)  but I'm losing the time  when
I convert using  ..

 

tsData <- myData[,10, drop=FALSE]

tsData$date_time <- as.Date(tsData$date_time, format="%m/%d/%y %H:%M")

head(tsData)

 


 

 

date_time





1

2013-06-20



2

2013-06-20



3

2013-06-20



4

2013-06-20



5

2013-05-30



6

2013-06-20



 

R is doing what I'm asing it to do so I'm obviously using the wrong command.
How do I convert, retaining the time 

 

Sincerely

 

Jeffery (Jeff) Reichman


[[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] counting unique values (summary stats)

2019-03-21 Thread reichmanj
r-help

I have the following little scrip to create a df of summary stats.  I'm
having problems obtaining the # of unique values 

   unique=sapply(myData, function (x)
 length(unique(x), replace = TRUE))

Can I do that, or am I using the wrong R function?

summary.stats <- data.frame(mean=sapply(myData, mean, na.rm=TRUE), 
   sd=sapply(myData, sd, na.rm=TRUE), 
   min=sapply(myData, min, na.rm=TRUE), 
   max=sapply(myData, max, na.rm=TRUE), 
   median=sapply(myData, median, na.rm=TRUE), 
   length=sapply(myData, length),
   unique=sapply(myData, function (x)
 length(unique(x), replace = TRUE))
   miss.val=sapply(myData, function(y) 
 sum(length(which(is.na(y))

Jeff Reichman

__
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] Zoom In/Out maps library

2019-03-06 Thread reichmanj
Roy

Thank you - that's helpful.  Going to have to read up on sf and mapview
library. Those are new ones.  Then to add a point feature layer (lat/long)
where would I insert that?

Library(maps)
Library(sf) # simple features
Library(mapview)

world.map <- maps::map("world", plot = FALSE, fill = TRUE) 
p <- sf::st_as_sf(world.map, coords = c('x', 'y')) 
mapview::mapview(p, legend=FALSE)



-Original Message-
From: rmendelss gmail  
Sent: Wednesday, March 6, 2019 4:11 PM
To: reichm...@sbcglobal.net
Cc: R help Mailing list 
Subject: Re: [R] Zoom In/Out maps library

world.map <- maps::map("world", plot = FALSE, fill = TRUE) p <- sf::
st_as_sf(world.map, coords = c('x', 'y')) map view::map view(p)

HTH,

-Roy

> On Mar 6, 2019, at 1:44 PM, reichm...@sbcglobal.net wrote:
> 
> R Help
> 
> Anyone know if I can add a zoom In/Out function to the maps available via
the "maps" library? Or do I need to use a different mapping library?
> 
> world.map <- map_data("world")
> 
> ggplot(data = world.map) +
>  geom_polygon(mapping = aes(x=long, y=lat, group=group))
> 
> Jeff
> 
> __
> 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] Zoom In/Out maps library

2019-03-06 Thread reichmanj
R Help

Anyone know if I can add a zoom In/Out function to the maps available via the 
"maps" library? Or do I need to use a different mapping library?

world.map <- map_data("world")

ggplot(data = world.map) +
  geom_polygon(mapping = aes(x=long, y=lat, group=group))

Jeff

__
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] Calendar Heat Map

2019-02-06 Thread reichmanj
Jeff

Thanks - that’s easy enough

Jeff

-Original Message-
From: Jeff Newmiller  
Sent: Wednesday, February 6, 2019 7:09 AM
To: r-help@r-project.org; reichm...@sbcglobal.net
Subject: Re: [R] Calendar Heat Map

ggplot automatically chooses continuous or discrete scales depending on the 
type of column you give it... so don't give it a numeric column (integers are a 
subset of numeric)... give it a character (lazy) or factor (better for 
controlling what the output looks like) value for your colour specification.

Read

?cut

for one clean way to make a new factor column in your data set before you give 
it to ggplot. Note that if you don't like the labels it generates automatically 
you can specify them yourself.

On February 5, 2019 2:28:28 PM PST, reichm...@sbcglobal.net wrote:
>r-Help Form
>
> 
>
>I'm working on a "Time-Series Calendar Heatmap" using the following 
>code.
>
> 
>
>ggplot(myData, aes(monthweek, weekdayf, fill = myData $adjusted)) +
>
>geom_tile(colour = "white") + facet_grid(year(myData $date)~monthf) +
>
>scale_fill_gradient(low="red", high="green") +
>
>xlab("Week of Month") + ylab("") +
>
>ggtitle("Time-Series Calendar Heatmap ") + labs(fill = "Price")
>
> 
>
>While the ggplot commands do (almost) what I want I can't figure out 
>how to change my color scaling. While scale_fill_gradient(low="red",
>high="green")
>does what I ask, that is create a color gradient from red to green it 
>not what I thought it would be. What I need is discreet colors 
>something like 0
>- grey; 1:5 - blue; 6:10 - green etc.  How to I set discrete colors for 
>groups of values. A color ramp would work but I need to separately 
>color those cells with 0 counts.
>
> 
>
>Jeff Reichman
>
>
>   [[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.

--
Sent from my phone. Please excuse my brevity.

__
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] Calendar Heat Map

2019-02-05 Thread reichmanj
r-Help Form

 

I'm working on a "Time-Series Calendar Heatmap" using the following code.

 

ggplot(myData, aes(monthweek, weekdayf, fill = myData $adjusted)) + 

geom_tile(colour = "white") + facet_grid(year(myData $date)~monthf) + 

scale_fill_gradient(low="red", high="green") + 

xlab("Week of Month") + ylab("") + 

ggtitle("Time-Series Calendar Heatmap ") + labs(fill = "Price")

 

While the ggplot commands do (almost) what I want I can't figure out how to
change my color scaling. While scale_fill_gradient(low="red", high="green")
does what I ask, that is create a color gradient from red to green it not
what I thought it would be. What I need is discreet colors something like 0
- grey; 1:5 - blue; 6:10 - green etc.  How to I set discrete colors for
groups of values. A color ramp would work but I need to separately color
those cells with 0 counts.

 

Jeff Reichman


[[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] Tukey Test

2019-01-24 Thread reichmanj
R-Help

 

There is an R library that will perform a Tukey test which prints out the
Tukey groups (A, B, C, etc) and I don't recall the library. It was
agriculture or something like that. 

 

And is there a library that will product the Tukey, Bonferonni, Scheffe, and
Dunnett comparison tables?

 

Jeff Reichmqn


[[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] Confusion Table

2019-01-16 Thread reichmanj
Ah yes - thank you

-Original Message-
From: Jeff Newmiller  
Sent: Wednesday, January 16, 2019 6:49 PM
To: r-help@r-project.org; reichm...@sbcglobal.net
Subject: Re: [R] Confusion Table

If you turn your character variable into a factor and specify the levels 
argument, you can control the sequence in which any discrete values are 
presented.

tst_pred <- factor( tst_pred, levels=c("No","Yes") )

On January 16, 2019 4:31:15 PM PST, reichm...@sbcglobal.net wrote:
>R-Help
>
> 
>
>R-Help community is there an simple straight forward way  of changing 
>my confusion table output to list "Yes" before "No" rather than "No"
>before
>"Yes" - R default.
>
> 
>
># Making predictions on the test set.
>
>tst_pred <- ifelse(predict(model_glm, newdata = default_tst, type =
>"response") > 0.5, "Yes", "No")
>
>tst_tab <- table(predicted = tst_pred, actual = default_tst$default)
>
>tst_tab
>
> 
>
>##actual
>
>## predicted   No  Yes
>
>##  No  4817  113
>
>##  Yes  1852
>
> 
>
>Jeff
>
>
>   [[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.

--
Sent from my phone. Please excuse my brevity.

__
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] Confusion Table

2019-01-16 Thread reichmanj
That's easy enough 

Thanks

-Original Message-
From: Peter Langfelder  
Sent: Wednesday, January 16, 2019 6:48 PM
To: reichm...@sbcglobal.net
Cc: r-help 
Subject: Re: [R] Confusion Table

The lazy way is to do

tst_tab = tst_tab[c(2,1), c(2,1)]

The less lazy way is something like

tst_tab <- table(predicted = factor(tst_pred, levels = c("Yes", "No")),  actual 
= factor(default_tst$default, levels = c("Yes",
"No")))

Peter

On Wed, Jan 16, 2019 at 4:39 PM  wrote:
>
> R-Help
>
>
>
> R-Help community is there an simple straight forward way  of changing 
> my confusion table output to list "Yes" before "No" rather than "No" 
> before "Yes" - R default.
>
>
>
> # Making predictions on the test set.
>
> tst_pred <- ifelse(predict(model_glm, newdata = default_tst, type =
> "response") > 0.5, "Yes", "No")
>
> tst_tab <- table(predicted = tst_pred, actual = default_tst$default)
>
> tst_tab
>
>
>
> ##actual
>
> ## predicted   No  Yes
>
> ##  No  4817  113
>
> ##  Yes  1852
>
>
>
> Jeff
>
>
> [[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] Confusion Table

2019-01-16 Thread reichmanj
R-Help

 

R-Help community is there an simple straight forward way  of changing my
confusion table output to list "Yes" before "No" rather than "No" before
"Yes" - R default.

 

# Making predictions on the test set.

tst_pred <- ifelse(predict(model_glm, newdata = default_tst, type =
"response") > 0.5, "Yes", "No")

tst_tab <- table(predicted = tst_pred, actual = default_tst$default)

tst_tab

 

##actual

## predicted   No  Yes

##  No  4817  113

##  Yes  1852

 

Jeff


[[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.