[R] Computing means of multiple variables based on a condition

2016-05-25 Thread KMNanus
I have a large dataset, a sample of which is:

a<- c(“A”, “B”,“A”, “B”,“A”, “B”,“A”, “B”,“A”, “B”)
b <-c(15, 35, 20,  99, 75, 64, 33, 78, 45, 20)
c<- c( 111, 234, 456, 876, 246, 662, 345, 480, 512, 179)
d<- c(1.1, 3.2, 14.2, 8.7, 12.5, 5.9, 8.3, 6.0, 2.9, 9.3) 

df <- data.frame(a,b,c,d)

I’m trying to construct a data frame that shows the means of c & b based on the 
condition of d and grouped by a.

I want to create the data frame below, then use ggplot2 to create a line plot 
of b at various conditions of d.

I can compute the grouped means (d>=2, d>=4, etc.) one at a time using dplyr 
but haven’t figured out how to put them all together or put them in one data 
frame.

I’d rather not use a loop and am relatively new to R.  Is there a way i can use 
tapply and set it to the conditions above so that I can create the df below?


conditionmean(b) mean(c)
Ad>=2   _
Bd>=2   _
Ad>=4   _
Bd>=4  _
Ad>=6  _
B   d>=6  _



Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Computing means of multiple variables based on a condition

2016-05-25 Thread KMNanus
These will be overlapping subgroups from the same data frame.  For example, 
d<=2 will have length=9, d<=4 will have length=7, etc.


Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On May 25, 2016, at 9:06 PM, William Dunlap  wrote:
> 
> Just to be clear, do you really want your 'condition' groups to be be subsets
> of one another?  Most (all?) of the *ply functions assume you want
> non-overlapping groups so they do a split-summarize-combine sequence.
> You would have to replace the split part of that.
> 
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com <http://tibco.com/>
> On Wed, May 25, 2016 at 3:37 PM, KMNanus  <mailto:kmna...@gmail.com>> wrote:
> I have a large dataset, a sample of which is:
> 
> a<- c(“A”, “B”,“A”, “B”,“A”, “B”,“A”, “B”,“A”, “B”)
> b <-c(15, 35, 20,  99, 75, 64, 33, 78, 45, 20)
> c<- c( 111, 234, 456, 876, 246, 662, 345, 480, 512, 179)
> d<- c(1.1, 3.2, 14.2, 8.7, 12.5, 5.9, 8.3, 6.0, 2.9, 9.3)
> 
> df <- data.frame(a,b,c,d)
> 
> I’m trying to construct a data frame that shows the means of c & b based on 
> the condition of d and grouped by a.
> 
> I want to create the data frame below, then use ggplot2 to create a line plot 
> of b at various conditions of d.
> 
> I can compute the grouped means (d>=2, d>=4, etc.) one at a time using dplyr 
> but haven’t figured out how to put them all together or put them in one data 
> frame.
> 
> I’d rather not use a loop and am relatively new to R.  Is there a way i can 
> use tapply and set it to the conditions above so that I can create the df 
> below?
> 
> 
> conditionmean(b) mean(c)
> Ad>=2   _
> Bd>=2   _
> Ad>=4   _
> Bd>=4  _
> Ad>=6  _
> B   d>=6  _
> 
> 
> 
> Ken
> kmna...@gmail.com <mailto:kmna...@gmail.com>
> 914-450-0816  (tel)
> 347-730-4813  (fax)
> 
> 
> 
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help 
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> <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] Need help getting plotly to run on R

2016-06-02 Thread KMNanus
I signed up with plotly on their own site - https://plot.ly/  
- and got a username and password.

When I installed the package in R, I got the following error msg - 
"Storing 'username' as the environment variable 'plotly_username'
Error in Sys.setenv(plotly_username = username) : 
  wrong length for argument”

So I called signup("knanus", "kmna...@gmail.com”) and received :
Error: Aw, snap! Either you've already signed-up with this username or this 
username has been taken. If you think you've already signed up, you can view 
your API key at https://plot.ly/api/key and sign in:
>>> p <- plotly(username="knanus", key=api_key)

I called p<- plolty exactly as instructed above (I did not enter the api_key on 
this email for confidentiality) and received
Storing 'username' as the environment variable 'plotly_username'
Storing 'key' as the environment variable 'plotly_api_key'
Error in Sys.setenv(plotly_api_key = key) : object ‘XX' not found

So I detached and deleted plotly from my library and tried - 

install.packages("devtools")
library(devtools)

I received the “DONE” response, but when I called library(plotly) I received 
the same “Storing ‘username…” error msg as before.

What am I doing wrong?


Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Turning a variable name into a function argument

2016-06-27 Thread KMNanus
I’m inexperience but am trying to get my head around using functions to make a 
number of ggplots easier to do.  

I have a function that creates a ggplot taking one input variable as an 
argument. The variable name is shorthand for the actual variable (variable name 
= tue, Actual name = Tuesday).  Since I want to use the actual variable name in 
ylab and ggtitle, I’d like to add a second argument, new.name, to the function 
which would allow me to utilize both inputs as arguments but have not been 
successful.  I tried creating a function within the function to accomplish 
this, using deparse(substitute(new.name))and also using the code you see below.


myfun <- function(myvar, new.name){
  function(new.name){return(as.character(substitute(new.name)))}
  ggplot(b12.2, aes(x= games,  y = myvar, col = Group))+
  geom_point() + 
  geom_line()+
  xlab("Minimum Games" ) +
  ylab(paste(new.name, “Average Change"))+
  ggtitle(new.name, "Change \n as a Function of Minimum Number of Games”)+
  theme_bw()

When call myfun(myvar, new.name), I get an error msg “new.name is not found” 
whether I call new.name or Tuesday.

I want ggplot to automatically insert Tuesday into ylab and ggtitle.

Can anyone help me with this?  Thanks for your patience.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Turning a variable name into a function argument

2016-06-28 Thread KMNanus
Thanks for getting back to me, I’m sorry if I was unclear.

What I’m trying to figure out is the equivalent of “find and replace” in Word.

I have a function - 

myfun <- function(z){
ggplot(df, aes(x,y)+
geom_point() + 
ggtitle (“___ quick brown fox jumped over the lazy dog”)}

Calling myfun(z) works perfectly.  What I’m trying to do is add a string to 
myfun so that it would read:  function(z, “string”){

Then I could call myfun(z, “string”) to replace the space in ggtitle.  Is there 
a straightforward way to do that?

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Jun 28, 2016, at 12:20 PM, David Winsemius  wrote:
> 
>> 
>> On Jun 27, 2016, at 6:12 PM, KMNanus  wrote:
>> 
>> I’m inexperience but am trying to get my head around using functions to make 
>> a number of ggplots easier to do.  
>> 
>> I have a function that creates a ggplot taking one input variable as an 
>> argument. The variable name is shorthand for the actual variable (variable 
>> name = tue, Actual name = Tuesday).  Since I want to use the actual variable 
>> name in ylab and ggtitle, I’d like to add a second argument, new.name, to 
>> the function which would allow me to utilize both inputs as arguments but 
>> have not been successful.  I tried creating a function within the function 
>> to accomplish this, using deparse(substitute(new.name))and also using the 
>> code you see below.
>> 
>> 
>> myfun <- function(myvar, new.name){
>> function(new.name){return(as.character(substitute(new.name)))}
>> ggplot(b12.2, aes(x= games,  y = myvar, col = Group))+
>> geom_point() + 
>> geom_line()+
>> xlab("Minimum Games" ) +
>> ylab(paste(new.name, “Average Change"))+
>> ggtitle(new.name, "Change \n as a Function of Minimum Number of Games”)+
>> theme_bw()
>> 
>> When call myfun(myvar, new.name), I get an error msg “new.name is not found” 
>> whether I call new.name or Tuesday.
> 
> Q1: At the moment we have no idea _how_ you might be "calling" this function. 
> We also do not know what might be assigned to `myvar` or `new.name` in the 
> calling environment. Sounds unlikely that you are typing:
> 
> myfun(myvar, new.name)  ## ?, so was there a loop/lapply calling method?
> 
> 
> Q2: You should not imagine that the inner anonymous function would be 
> altering the value of `new.name`. (That function is only defined and never 
> called, and even if it were called, it would not change the value of the 
> `new.name` in the calling environment.)
> 
> Since more than 12 hours have passed with no response, we can surmise that 
> many people have passed the question over after concluding there was an 
> incomplete problem description. You should post code that can be cut-pasted 
> into a session and produce the error you are getting. It would include data 
> setup and a loop or loop equivalent to show how the function is being called.
> 
> -- 
> David.
> 
> 
>> 
>> I want ggplot to automatically insert Tuesday into ylab and ggtitle.
>> 
>> Can anyone help me with this?  Thanks for your patience.
>> 
>> Ken
>> kmna...@gmail.com <mailto:kmna...@gmail.com>
>> 914-450-0816 (tel)
>> 347-730-4813 (fax)
>> 
>> 
>> 
>> __
>> R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
>> UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help 
>> <https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
>> <http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius
> Alameda, CA, USA

__
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] Turning a variable name into a function argument

2016-06-28 Thread KMNanus
Thanks for getting back to me.  None of them work, because I’m trying to use 
the string in the function  call - myfun(z, “string”) to replace the empty 
space in ggtitle.

When I call myfun(z, gsub(“__”, “string (or any word)”, myfun), I get an 
error msg because gsub is looking for a data frame, not a function.

Paste or paste0 doesn’t work, either because I still have to replace the space 
in ggtitle with something.

In short, I want to put another argument into the function that will enable me 
to call it and fill that space.

I’m stumped.


Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Jun 28, 2016, at 3:42 PM, Greg Snow <538...@gmail.com> wrote:
> 
> There are several options.  The option that is most like search and
> replace is to use the `sub` or `gsub` function (or similar functions
> in added packages).  But you may be able to accomplish what you want
> even simpler by using the `paste`, `paste0`, or `sprintf` functions.
> 
> On Tue, Jun 28, 2016 at 12:10 PM, KMNanus  wrote:
>> Thanks for getting back to me, I’m sorry if I was unclear.
>> 
>> What I’m trying to figure out is the equivalent of “find and replace” in 
>> Word.
>> 
>> I have a function -
>> 
>> myfun <- function(z){
>> ggplot(df, aes(x,y)+
>> geom_point() +
>> ggtitle (“___ quick brown fox jumped over the lazy dog”)}
>> 
>> Calling myfun(z) works perfectly.  What I’m trying to do is add a string to 
>> myfun so that it would read:  function(z, “string”){
>> 
>> Then I could call myfun(z, “string”) to replace the space in ggtitle.  Is 
>> there a straightforward way to do that?
>> 
>> Ken
>> kmna...@gmail.com
>> 914-450-0816 (tel)
>> 347-730-4813 (fax)
>> 
>> 
>> 
>>> On Jun 28, 2016, at 12:20 PM, David Winsemius  
>>> wrote:
>>> 
>>>> 
>>>> On Jun 27, 2016, at 6:12 PM, KMNanus  wrote:
>>>> 
>>>> I’m inexperience but am trying to get my head around using functions to 
>>>> make a number of ggplots easier to do.
>>>> 
>>>> I have a function that creates a ggplot taking one input variable as an 
>>>> argument. The variable name is shorthand for the actual variable (variable 
>>>> name = tue, Actual name = Tuesday).  Since I want to use the actual 
>>>> variable name in ylab and ggtitle, I’d like to add a second argument, 
>>>> new.name, to the function which would allow me to utilize both inputs as 
>>>> arguments but have not been successful.  I tried creating a function 
>>>> within the function to accomplish this, using 
>>>> deparse(substitute(new.name))and also using the code you see below.
>>>> 
>>>> 
>>>> myfun <- function(myvar, new.name){
>>>> function(new.name){return(as.character(substitute(new.name)))}
>>>> ggplot(b12.2, aes(x= games,  y = myvar, col = Group))+
>>>> geom_point() +
>>>> geom_line()+
>>>> xlab("Minimum Games" ) +
>>>> ylab(paste(new.name, “Average Change"))+
>>>> ggtitle(new.name, "Change \n as a Function of Minimum Number of Games”)+
>>>> theme_bw()
>>>> 
>>>> When call myfun(myvar, new.name), I get an error msg “new.name is not 
>>>> found” whether I call new.name or Tuesday.
>>> 
>>> Q1: At the moment we have no idea _how_ you might be "calling" this 
>>> function. We also do not know what might be assigned to `myvar` or 
>>> `new.name` in the calling environment. Sounds unlikely that you are typing:
>>> 
>>> myfun(myvar, new.name)  ## ?, so was there a loop/lapply calling method?
>>> 
>>> 
>>> Q2: You should not imagine that the inner anonymous function would be 
>>> altering the value of `new.name`. (That function is only defined and never 
>>> called, and even if it were called, it would not change the value of the 
>>> `new.name` in the calling environment.)
>>> 
>>> Since more than 12 hours have passed with no response, we can surmise that 
>>> many people have passed the question over after concluding there was an 
>>> incomplete problem description. You should post code that can be cut-pasted 
>>> into a session and produce the error you are getting. It would include data 
>>> setup and a loop or loop equivalent to show how the function is being 
>>> called.
>>> 
>>> --
>>> David.
>>> 
>>> 
>>>> 
>>>> I want ggplot to automatically insert Tuesday into ylab and ggtit

Re: [R] Turning a variable name into a function argument

2016-06-28 Thread KMNanus
I’m trying to modify the function from outside, i.e., when I call the function.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Jun 28, 2016, at 5:07 PM, Greg Snow <538...@gmail.com> wrote:
> 
> Can you edit the source of the function?  or are you trying to modify an 
> existing function without working on the source?
> 
> On Tue, Jun 28, 2016 at 2:46 PM, KMNanus  <mailto:kmna...@gmail.com>> wrote:
> Thanks for getting back to me.  None of them work, because I’m trying to use 
> the string in the function  call - myfun(z, “string”) to replace the empty 
> space in ggtitle.
> 
> When I call myfun(z, gsub(“__”, “string (or any word)”, myfun), I get an 
> error msg because gsub is looking for a data frame, not a function.
> 
> Paste or paste0 doesn’t work, either because I still have to replace the 
> space in ggtitle with something.
> 
> In short, I want to put another argument into the function that will enable 
> me to call it and fill that space.
> 
> I’m stumped.
> 
> 
> Ken
> kmna...@gmail.com <mailto:kmna...@gmail.com>
> 914-450-0816 (tel)
> 347-730-4813 (fax)
> 
> 
> 
>> On Jun 28, 2016, at 3:42 PM, Greg Snow <538...@gmail.com 
>> <mailto:538...@gmail.com>> wrote:
>> 
>> There are several options.  The option that is most like search and
>> replace is to use the `sub` or `gsub` function (or similar functions
>> in added packages).  But you may be able to accomplish what you want
>> even simpler by using the `paste`, `paste0`, or `sprintf` functions.
>> 
>> On Tue, Jun 28, 2016 at 12:10 PM, KMNanus > <mailto:kmna...@gmail.com>> wrote:
>>> Thanks for getting back to me, I’m sorry if I was unclear.
>>> 
>>> What I’m trying to figure out is the equivalent of “find and replace” in 
>>> Word.
>>> 
>>> I have a function -
>>> 
>>> myfun <- function(z){
>>> ggplot(df, aes(x,y)+
>>> geom_point() +
>>> ggtitle (“___ quick brown fox jumped over the lazy dog”)}
>>> 
>>> Calling myfun(z) works perfectly.  What I’m trying to do is add a string to 
>>> myfun so that it would read:  function(z, “string”){
>>> 
>>> Then I could call myfun(z, “string”) to replace the space in ggtitle.  Is 
>>> there a straightforward way to do that?
>>> 
>>> Ken
>>> kmna...@gmail.com <mailto:kmna...@gmail.com>
>>> 914-450-0816 (tel)
>>> 347-730-4813 (fax)
>>> 
>>> 
>>> 
>>>> On Jun 28, 2016, at 12:20 PM, David Winsemius >>> <mailto:dwinsem...@comcast.net>> wrote:
>>>> 
>>>>> 
>>>>> On Jun 27, 2016, at 6:12 PM, KMNanus >>>> <mailto:kmna...@gmail.com>> wrote:
>>>>> 
>>>>> I’m inexperience but am trying to get my head around using functions to 
>>>>> make a number of ggplots easier to do.
>>>>> 
>>>>> I have a function that creates a ggplot taking one input variable as an 
>>>>> argument. The variable name is shorthand for the actual variable 
>>>>> (variable name = tue, Actual name = Tuesday).  Since I want to use the 
>>>>> actual variable name in ylab and ggtitle, I’d like to add a second 
>>>>> argument, new.name <http://new.name/>, to the function which would allow 
>>>>> me to utilize both inputs as arguments but have not been successful.  I 
>>>>> tried creating a function within the function to accomplish this, using 
>>>>> deparse(substitute(new.name <http://new.name/>))and also using the code 
>>>>> you see below.
>>>>> 
>>>>> 
>>>>> myfun <- function(myvar, new.name <http://new.name/>){
>>>>> function(new.name 
>>>>> <http://new.name/>){return(as.character(substitute(new.name 
>>>>> <http://new.name/>)))}
>>>>> ggplot(b12.2, aes(x= games,  y = myvar, col = Group))+
>>>>> geom_point() +
>>>>> geom_line()+
>>>>> xlab("Minimum Games" ) +
>>>>> ylab(paste(new.name <http://new.name/>, “Average Change"))+
>>>>> ggtitle(new.name <http://new.name/>, "Change \n as a Function of Minimum 
>>>>> Number of Games”)+
>>>>> theme_bw()
>>>>> 
>>>>> When call myfun(myvar, new.name <http://new.name/>), I get an error msg 
>>>>> “new.name <http://new.name/> is not found” whether I call new.name

Re: [R] Turning a variable name into a function argument

2016-06-28 Thread KMNanus
You’ve stated my intent perfectly.  I tried depress(substitute(x)) within 
ggplot and it didn’t work.

However, the solution (which I discovered about 10 minutes ago), turned out to 
remarkably easy - I just assigned the new variable and it ran perfectly.  It 
looks like this - 

myfun<- function(z, q = “new.name){
 function(new.name){return(as.character(substitute(new.name)))}
ggplot(df, aes(x,y))+
geom_point()+
ggtitle(paste(q, “quick brown fox….”))

Not sure why assigning “new.name” to q makes the difference, but it did.

Thanks.



>>>>> myfun <- function(z){
>>>>> ggplot(df, aes(x,y)+
>>>>> geom_point() +
>>>>> ggtitle (“___ quick brown fox jumped over the lazy dog”)}




Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Jun 28, 2016, at 8:53 PM, Jim Lemon  wrote:
> 
> Hi Ken,
> As far as I can see, ggtitle accepts a single string. The help page is
> a bit obscure, implying that you can change the title with the "labs"
> function(?), but using the same explicit string in the "ggtitle" line,
> perhaps for didactic purposes. You seem to be asking to substitute
> your own version of a string that is popping out in ggplot
> automatically, e.g. "Tue" -> "Tuesday". The help page doesn't discuss
> whether it is possible to access the string that will be automatically
> used as the title. If ggtitle automatically uses the name of the
> object that you are plotting, something like this may work:
> 
> my_x<-1:5
> myfun<-function(x,mytitle) {
> plot(x)
> old_title<-deparse(substitute(x))
> title(gsub("x",mytitle,old_title))
> }
> myfun(my_x,"wonderful X")
> 
> The reason that I have done this in base graphics is that I could not
> get an equivalent plot in ggplot.
> 
> Jim
> 
> 
> On Wed, Jun 29, 2016 at 9:48 AM, Bert Gunter  wrote:
>> I frankly don't know what the heck you are doing but,
>> 
>> (inline below)
>> 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 Tue, Jun 28, 2016 at 1:46 PM, KMNanus  wrote:
>>> Thanks for getting back to me.  None of them work, because I’m trying to 
>>> use the string in the function  call - myfun(z, “string”) to replace the 
>>> empty space in ggtitle.
>>> 
>>> ***When I call myfun(z, gsub(“__”, “string (or any word)”, myfun), I 
>>> get an error msg because gsub is looking for a data frame, not a 
>>> function.***
>> 
>> That is absolutely, unequivocally, positively, FALSE. See ?gsub for
>> what gsub() *does* want.
>> 
>> This suggests to me that you may also not understand functions and/or
>> function arguments, so I would recommend that you try a web tutorial
>> or two on R function to see where your confusion may lie. However, I
>> freely admit (see my initial remark) that I may not understand what
>> you are trying to do, so maybe that's not it. I will say if I wanted
>> to give an arbitrary character string to a function that called a
>> title function, titleFUN, I'd do it like this:
>> 
>> myfun <- function(..., mytitle){
>> 
>> ## lots of stuff
>> 
>> titleFUN(mytitle)
>> 
>> ## more stuff
>> 
>> }
>> 
>> and call it by:
>> 
>> myfun(..., "myReallyCuteTitle")
>> 
>> 
>> I do not use ggplot and so do not know its detailed syntax; but I
>> would be surprised if it did not accept something along these lines...
>> 
>> Cheers,
>> Bert
>> 
>> 
>> 
>> 
>> 
>> 
>>> 
>>> Paste or paste0 doesn’t work, either because I still have to replace the 
>>> space in ggtitle with something.
>>> 
>>> In short, I want to put another argument into the function that will enable 
>>> me to call it and fill that space.
>>> 
>>> I’m stumped.
>>> 
>>> 
>>> Ken
>>> kmna...@gmail.com
>>> 914-450-0816 (tel)
>>> 347-730-4813 (fax)
>>> 
>>> 
>>> 
>>>> On Jun 28, 2016, at 3:42 PM, Greg Snow <538...@gmail.com> wrote:
>>>> 
>>>> There are several options.  The option that is most like search and
>>>> replace is to use the `sub` or `gsub` function (or similar functions
>>>> in added packages).  But you may be able to accomplish what you want
>>>> even simpler by using the `paste

[R] Is there a way to coerce ggplot into using min & max values for x & y axes?

2016-07-11 Thread KMNanus
I’m plotting few dozen variables, doing so because I need to examine them one 
at a time.  The range of these variables varies widely.  One can range from -.5 
to .03, another from -600 to +750.

I want both axes to automatically plot from both min and max values for both 
continuous variables.  

I’ve tried  - stat_summary(fun.ymax=max, fun.ymin=min), but it doesn’t plot to 
the min and max values.

This code neither plots to the min/max nor does it create tick marks on either 
axis - scale_y_continuous(breaks = c(min(b12.2$myvar), 0, max(b12.2$myvar)))

Has anyone faced this situation before?  I appreciate the help.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Please help me, I'm trying to update my version of R

2016-08-22 Thread KMNanus
I’m a newbie running 3.2.4 on a mac equipped with Yosemite (10.10.5).

I want to update to 3.3.1 and have downloaded the package, but have not been 
able to install it.  I’ve tried install.packages("R-3.3.1.tar.gz”) and 
install.packages("R-3.3.1.pkg”) after downloading both files.

I get an error msg - "package ‘R-3.3.1.pkg’ is not available (for R version 
3.2.4)"

I know this question has shown up on several message boards but I’m having 
trouble understanding the process.

Is there a straightforward way to update my version of R and, if successful, 
will R automatically work with the packages I’ve installed?

Ken Nanus
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Please help me, I'm trying to update my version of R

2016-08-23 Thread KMNanus
Thanks for getting back to me. Worked like a charm.  


Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Aug 22, 2016, at 11:45 PM, Thomas Mailund  wrote:
> 
> Hi Ken,
> 
> You are trying to install R as a package. That won't work. The .pkg file you 
> downloaded from https://cran.r-project.org/bin/macosx/ is an installer, 
> though, so if you just double-click on it, it should take you through the 
> installation. After that you probably need to install a number of packages, 
> since the ones you have installed for version 3.2 R won't be available in the 
> 3.3 installation, but *those* packages you can install using install.packages.
> 
> Cheers
> 
> -- 
> Thomas Mailund
> On 22 August 2016 at 22:17:50, KMNanus (kmna...@gmail.com 
> <mailto:kmna...@gmail.com>) wrote:
> 
>> I’m a newbie running 3.2.4 on a mac equipped with Yosemite (10.10.5).
>> 
>> I want to update to 3.3.1 and have downloaded the package, but have not been 
>> able to install it. I’ve tried install.packages("R-3.3.1.tar.gz”) and 
>> install.packages("R-3.3.1.pkg”) after downloading both files.
>> 
>> I get an error msg - "package ‘R-3.3.1.pkg’ is not available (for R version 
>> 3.2.4)"
>> 
>> I know this question has shown up on several message boards but I’m having 
>> trouble understanding the process.
>> 
>> Is there a straightforward way to update my version of R and, if successful, 
>> will R automatically work with the packages I’ve installed?
>> 
>> Ken Nanus
>> kmna...@gmail.com
>> 914-450-0816  (tel)
>> 347-730-4813  (fax)
>> 
>> 
>> 
>> __
>> 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] receiving Error: unexpected '='

2016-02-29 Thread KMNanus
I’m a newbie and trying to execute this simple function in order to change wk 5 
NA’s to wk 4 values for the dataset (ken) below.  Can someone pls tell me what 
I’m doing wrong?  The error msg is “"rror: unexpected input in "new_week <- 
function(x,y) { “
Even the “E” is missing in the word “Error."

new_week <- function(x,y) {
if x[is.na(x)] {
x = y
}
}

patient wk1 wk2 wk3 wk4 wk5
A   1   2   4   6   8
B   2   3   NA  3   17
C   3   4   5   11  NA
D   4   NA  6   12  11
E   5   6   7   NA  21
F   6   7   8   3   NA
G   7   8   9   7   NA



Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Extracting part of a factor

2016-03-03 Thread KMNanus
I have a factor variable that is 6 digits and hyphenated.  For example, 001-014.

I need to extract the first 3 digits to a new variable using mutate in dplyr - 
in this case 001 - but can’t find a function to do it.

substr will do this for character strings, but I need the variable to remain as 
a factor.

Is there an R function  or workaround to do this?

 
Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Extracting part of a factor

2016-03-03 Thread KMNanus
When I do that, I get "Error in `$<-.data.frame`(`*tmp*`, "site", value = 
integer(0)) : 
  replacement has 0 rows, data has 6”

The data frame has 6 rows.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 3, 2016, at 4:52 PM, Hervé Pagès  wrote:
> 
> Hi,
> 
> On 03/03/2016 12:18 PM, KMNanus wrote:
>> I have a factor variable that is 6 digits and hyphenated.  For example, 
>> 001-014.
>> 
>> I need to extract the first 3 digits to a new variable using mutate in dplyr 
>> - in this case 001 - but can’t find a function to do it.
>> 
>> substr will do this for character strings, but I need the variable to remain 
>> as a factor.
> 
> What prevents you from calling as.factor() on the result to turn it
> back into a factor?
> 
> H.
> 
>> 
>> Is there an R function  or workaround to do this?
>> 
>> 
>> Ken
>> kmna...@gmail.com
>> 914-450-0816 (tel)
>> 347-730-4813 (fax)
>> 
>> 
>> 
>> __
>> 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.
>> 
> 
> -- 
> Hervé Pagès
> 
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
> 
> E-mail: hpa...@fredhutch.org
> Phone:  (206) 667-5791
> Fax:(206) 667-1319

__
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] Extracting part of a factor

2016-03-03 Thread KMNanus
When I did that, I got - 

 "Error in `$<-.data.frame`(`*tmp*`, "site", value = integer(0)) : 
  replacement has 0 rows, data has 6”

The data frame has 6 rows.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 3, 2016, at 4:14 PM, Ista Zahn  wrote:
> 
> Like this?
> 
> x <- factor("001-014")
> y <- substr(as.character(x), 1, 3)
> 
> Best,
> Ista
> 
> 
> 
> 
> On Thu, Mar 3, 2016 at 3:18 PM, KMNanus  wrote:
>> I have a factor variable that is 6 digits and hyphenated.  For example, 
>> 001-014.
>> 
>> I need to extract the first 3 digits to a new variable using mutate in dplyr 
>> - in this case 001 - but can’t find a function to do it.
>> 
>> substr will do this for character strings, but I need the variable to remain 
>> as a factor.
>> 
>> Is there an R function  or workaround to do this?
>> 
>> 
>> Ken
>> kmna...@gmail.com
>> 914-450-0816 (tel)
>> 347-730-4813 (fax)
>> 
>> 
>> 
>> __
>> 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] Extracting part of a factor

2016-03-04 Thread KMNanus
Let me see if I can ask the question more clearly - I am trying to extract a 
section of a hyphenated factor. For example, 001-004 is one observation of 
test$ken, which is a factor, and I want to set up a new factor variable called 
place that would have 001 as an observation. If I call mutate(place = 
(as.character (test$ken)), I can extract 001 from  001-004, but but don't know 
how to subsequently convert that character string back into a factor.


Or can 001 be extracted from a factor as a factor?

Do you know how to execute either of these approaches?

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 3, 2016, at 8:33 PM, Hervé Pagès  wrote:
> 
> On 03/03/2016 02:13 PM, KMNanus wrote:
>> When I do that,
> 
> When you do what exactly?
> 
> It's impossible for anyone here to know what you're doing if you
> don't show the code.
> 
>> I get "Error in `$<-.data.frame`(`*tmp*`, "site", value
>> = integer(0)) :
>>   replacement has 0 rows, data has 6”
>> 
>> The data frame has 6 rows.
> 
> You said you had a factor variable, you never mentioned you had a
> data.frame. If the factor variable is part of a data.frame 'df',
> then first extract it with something like df$myvar or df[["myvar"]],
> and then call substr() followed by as.factor() on it.
> 
> H.
> 
>> 
>> Ken
>> kmna...@gmail.com <mailto:kmna...@gmail.com>
>> 914-450-0816 (tel)
>> 347-730-4813 (fax)
>> 
>> 
>>> On Mar 3, 2016, at 4:52 PM, Hervé Pagès >> <mailto:hpa...@fredhutch.org>> wrote:
>>> 
>>> Hi,
>>> 
>>> On 03/03/2016 12:18 PM, KMNanus wrote:
>>>> I have a factor variable that is 6 digits and hyphenated.  For
>>>> example, 001-014.
>>>> 
>>>> I need to extract the first 3 digits to a new variable using mutate
>>>> in dplyr - in this case 001 - but can’t find a function to do it.
>>>> 
>>>> substr will do this for character strings, but I need the variable to
>>>> remain as a factor.
>>> 
>>> What prevents you from calling as.factor() on the result to turn it
>>> back into a factor?
>>> 
>>> H.
>>> 
>>>> 
>>>> Is there an R function  or workaround to do this?
>>>> 
>>>> 
>>>> Ken
>>>> kmna...@gmail.com <mailto:kmna...@gmail.com>
>>>> 914-450-0816 (tel)
>>>> 347-730-4813 (fax)
>>>> 
>>>> 
>>>> 
>>>> __
>>>> 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.
>>>> 
>>> 
>>> --
>>> Hervé Pagès
>>> 
>>> Program in Computational Biology
>>> Division of Public Health Sciences
>>> Fred Hutchinson Cancer Research Center
>>> 1100 Fairview Ave. N, M1-B514
>>> P.O. Box 19024
>>> Seattle, WA 98109-1024
>>> 
>>> E-mail: hpa...@fredhutch.org <mailto:hpa...@fredhutch.org>
>>> Phone:  (206) 667-5791
>>> Fax:(206) 667-1319
>> 
> 
> -- 
> Hervé Pagès
> 
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
> 
> E-mail: hpa...@fredhutch.org
> Phone:  (206) 667-5791
> Fax:(206) 667-1319

__
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] Extracting part of a factor

2016-03-04 Thread KMNanus
Here’s the dataset I’m working with, called test - 

subject group   wk1 wk2 wk3 wk4 place
001-002 boys2   3   4   5   
002-003 boys7   6   5   4   
003-004 boys9   4   6   1   
004-005 girls   5   7   8   9   
005-006 girls   2   6   3   8   
006-007 girls   1   4   7   4   


if I call mutate(test, place = substr(subject,1,3), “001 is the first 
observation in the place column

But it’s a character and “subject” is a factor.  I need place to be a factor, 
too, but I need the observations to be ONLY the first three numbers of 
“subject.”

Does that make my request more understandable?

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 4, 2016, at 12:49 PM, Sarah Goslee  wrote:
> 
> Hi Ken,
> 
> You do that with as.factor(), as has already been suggested. You'll need to 
> provide a reproducible example to show us what's going wrong. Using fake data 
> is fine, we just need to see some data that look like yours and the code 
> you're using.
> 
> Sarah
> 
> On Fri, Mar 4, 2016 at 11:57 AM, KMNanus  <mailto:kmna...@gmail.com>> wrote:
> Let me see if I can ask the question more clearly - I am trying to extract a 
> section of a hyphenated factor. For example, 001-004 is one observation of 
> test$ken, which is a factor, and I want to set up a new factor variable 
> called place that would have 001 as an observation. If I call mutate(place = 
> (as.character (test$ken)), I can extract 001 from  001-004, but but don't 
> know how to subsequently convert that character string back into a factor.
> 
> 
> Or can 001 be extracted from a factor as a factor?
> 
> Do you know how to execute either of these approaches?
> 
> Ken
> kmna...@gmail.com <mailto:kmna...@gmail.com>
> 914-450-0816  (tel)
> 347-730-4813  (fax)
> 
> 
> 
> > On Mar 3, 2016, at 8:33 PM, Hervé Pagès  > <mailto:hpa...@fredhutch.org>> wrote:
> >
> > On 03/03/2016 02:13 PM, KMNanus wrote:
> >> When I do that,
> >
> > When you do what exactly?
> >
> > It's impossible for anyone here to know what you're doing if you
> > don't show the code.
> >
> >> I get "Error in `$<-.data.frame`(`*tmp*`, "site", value
> >> = integer(0)) :
> >>   replacement has 0 rows, data has 6”
> >>
> >> The data frame has 6 rows.
> >
> > You said you had a factor variable, you never mentioned you had a
> > data.frame. If the factor variable is part of a data.frame 'df',
> > then first extract it with something like df$myvar or df[["myvar"]],
> > and then call substr() followed by as.factor() on it.
> >
> > H.
> >
> >>
> >> Ken
> >> kmna...@gmail.com <mailto:kmna...@gmail.com> <mailto:kmna...@gmail.com 
> >> <mailto:kmna...@gmail.com>>
> >> 914-450-0816  (tel)
> >> 347-730-4813  (fax)
> >>
> >>
> >>> On Mar 3, 2016, at 4:52 PM, Hervé Pagès  >>> <mailto:hpa...@fredhutch.org>
> >>> <mailto:hpa...@fredhutch.org <mailto:hpa...@fredhutch.org>>> wrote:
> >>>
> >>> Hi,
> >>>
> >>> On 03/03/2016 12:18 PM, KMNanus wrote:
> >>>> I have a factor variable that is 6 digits and hyphenated.  For
> >>>> example, 001-014.
> >>>>
> >>>> I need to extract the first 3 digits to a new variable using mutate
> >>>> in dplyr - in this case 001 - but can’t find a function to do it.
> >>>>
> >>>> substr will do this for character strings, but I need the variable to
> >>>> remain as a factor.
> >>>
> >>> What prevents you from calling as.factor() on the result to turn it
> >>> back into a factor?
> >>>
> >>> H.
> >>>
> >>>>
> >>>> Is there an R function  or workaround to do this?
> >>>>
> >>>>
> >>>> Ken
> >>>> kmna...@gmail.com <mailto:kmna...@gmail.com> <mailto:kmna...@gmail.com 
> >>>> <mailto:kmna...@gmail.com>>
> >>>> 914-450-0816  (tel)
> >>>> 347-730-4813  (fax)
> >>>>
> >>>>
> >>>>
> >>>> __
> >>>> R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
> >>>> UNSUBSCRIBE and more, see
> >>>> https://stat.ethz.ch/mailm

Re: [R] Extracting part of a factor

2016-03-04 Thread KMNanus
Here’s where I’m stumped - 

when I call mutate(test, place = substr(test$subject, 1,3)) to create a place 
variable, I get this, with place as a character variable. 

 subject  group   wk1   wk2   wk3   wk4 place
   (fctr) (fctr) (int) (int) (int) (int) (chr)
1 001-002   boys 2 3 4 5   001
2 002-003   boys 7 6 5 4   002
3 003-004   boys 9 4 6 1   003
4 004-005  girls 5 7 8 9   004
5 005-006  girls 2 6 3 8   005
6 006-007  girls 1 4 7 4   006

When I call test$place <- factor(test$place), I receive the msg  - "Error in 
`$<-.data.frame`(`*tmp*`, "place", value = integer(0)) : 
  replacement has 0 rows, data has 6.

If I call mutate this way - mutate(test, place = 
factor(substr(test$subject,1,3))), I get the same output as above but when I 
call class(test$place), I get NULL and the variable disappears.

I can’t figure out why.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 4, 2016, at 3:46 PM, Jeff Newmiller  wrote:
> 
> I much prefer the factor function over the as.factor function for converting 
> character to factor, since you can set the levels in the order you want them 
> to be. 
> -- 
> Sent from my phone. Please excuse my brevity.
> 
> On March 4, 2016 10:07:27 AM PST, Sarah Goslee  wrote:
> As everyone has been telling you, as.factor().
> If you like the mutate approach, you can call as.factor(test$subject)
> to convert it.
> 
> Here's a one-liner with reproducible data.
> 
> 
> testdata <- structure(list(subject = structure(1:6, .Label = c("001-002",
> "002-003", "003-004", "004-005", "005-006", "006-007"), class = "factor"),
> group = structure(c(1L, 1L, 1L, 2L, 2L, 2L), .Label = c("boys",
> "girls"), class = "factor"), wk1 = c(2L, 7L, 9L, 5L, 2L,
> 1L), wk2 = c(3L, 6L, 4L, 7L, 6L, 4L), wk3 = c(4L, 5L, 6L,
> 8L, 3L, 7L), wk4 = c(5L, 4L, 1L, 9L, 8L, 4L)), .Names = c("subject",
> "group", "wk1", "wk2", "wk3", "wk4"), class = "data.frame", row.names = c(NA,
> -6L))
> 
> testdata$subject <- as.factor(substring(as.character(testdata$subject), 1, 3))
> 
> 
> testdata
>   subject group wk1 wk2 wk3 wk4
> 1 001  boys   2   3   4   5
> 2 002  boys   7   6   5   4
> 3 003  boys   9   4   6   1
> 4 004 girls   5   7   8   9
> 5 005 girls   2   6   3   8
> 6 006 girls   1   4   7   4
>  str(testdata)
> 'data.frame': 6 obs. of  6 variables:
>  $ subject: Factor w/ 6 levels "001","002","003",..: 1 2 3 4 5 6
>  $ group  : Factor w/ 2 levels "boys","girls": 1 1 1 2 2 2
>  $ wk1: int  2 7 9 5 2 1
>  $ wk2: int  3 6 4 7 6 4
>  $ wk3: int  4 5 6 8 3 7
>  $ wk4: int  5 4 1 9 8 4
> 
> Sarah
> 
> On Fri, Mar 4, 2016 at 1:00 PM, KMNanus  wrote:
> 
>  Here’s the dataset
> I’m working with, called test -
> 
>  subject group wk1 wk2 wk3 wk4 place
>  001-002 boys 2 3 4 5
>  002-003 boys 7 6 5 4
>  003-004 boys 9 4 6 1
>  004-005 girls 5 7 8 9
>  005-006 girls 2 6 3 8
>  006-007 girls 1 4 7 4
> 
> 
>  if I call mutate(test, place = substr(subject,1,3), “001 is the first 
> observation in the place column
> 
>  But it’s a character and “subject” is a factor.  I need place to be a 
> factor, too, but I need the observations to be ONLY the first three numbers 
> of “subject.”
> 
>  Does that make my request more understandable?
> 
> 
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help 
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> <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] Extracting part of a factor

2016-03-05 Thread KMNanus
Boris - 

Boy, do I feel dumb - that’s exactly what I wanted.  I’ve tried this every way 
I can think of without assigning the result to the original name of the data 
frame.  I was trying to assign the result to a variable (test$place).

Can u pls explain to me why assigning the result to the new variable was wrong?

BTW, really appreciate your help.
 
Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 4, 2016, at 9:21 PM, Boris Steipe  wrote:
> 
> LOL you still need to assign it though:
> 
> 
> test <- mutate(test, place = factor(substr(test$subject,1,3)))
> 
> str(test)
> 'data.frame': 6 obs. of  7 variables:
> $ subject: Factor w/ 6 levels "001-002","002-003",..: 1 2 3 4 5 6
> $ group  : Factor w/ 2 levels "boys","girls": 1 1 1 2 2 2
> $ wk1: int  2 7 9 5 2 1
> $ wk2: int  3 6 4 7 6 4
> $ wk3: int  4 5 6 8 3 7
> $ wk4: int  5 4 1 9 8 4
> $ place  : Factor w/ 6 levels "001","002","003",..: 1 2 3 4 5 6
> 
> 
> Without assigning the result, the output only gets printed to console. 
> Remember that R is a functional language - a properly written R functio does 
> not change anything, it only returns its result.
> 
> :-)
> 
> 
> On Mar 4, 2016, at 4:13 PM, KMNanus  wrote:
> 
>> If I call mutate this way - mutate(test, place = 
>> factor(substr(test$subject,1,3))), I get the same output as above but when I 
>> call class(test$place), I get NULL and the variable disappears.
> 

__
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] extracting months from a data

2016-03-09 Thread KMNanus
I have a series of dates in  format 3-Oct, 10-Oct, 20-Oct, etc.

I want to create a variable of just the month.  If I convert the date to a 
character string, substr is ineffective because some of the dates have 5 
characters (3-Oct) and some have 6 (10-Oct).

Is there a date function that accomplishes this easily?

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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 in make.names(col.names, unique = TRUE) : invalid multibyte string at '14 <4a>ULY 2012'

2016-03-10 Thread KMNanus
I’m trying to read in the data below from an Excel file (as a .csv file) in  
order to create an age (in years.%years) but am getting the error message in 
the subject line.

I’ve tried saving the dates as dates in Excel and tried saving the dates as 
text, both give me the same error message.  Can someone pls tell me what I’m 
doing wrong?

Gender  DOB Diagnosis   Screen Date
Male 14 JULY 2012   No   05 OCTOBER 2015
Female   31 OCTOBER 2009No   30 NOVEMBER 2015
Female   08 JULY 2009   No   06 DECEMBER 2015
Male 04 JUNE 2011   NA   11 JANUARY 2016
Female   21 AUGUST 2009 Yes  01 FEBRUARY 2016
Male 05 NOVEMBER 2007   No   16 FEBRUARY 2016
Male 01 JUNE 2009   NA   29 FEBRUARY 2016


 
Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] extracting months from a data

2016-03-10 Thread KMNanus
Thanks for this.  I wasn’t familiar with paste0, so I’ll call that and see if 
it works.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 9, 2016, at 7:15 PM, Dalthorp, Daniel  wrote:
> 
> Or: 
> 
> x <- c( "3-Oct", "10-Nov" )
> format(as.Date(paste0(x,rep("-1970",length(x))),format='%d-%b-%Y'),'%b')
> 
> # the 'paste0' appends a year to the text vector
> # the 'as.Date' interprets the strings as dates with format  10-Jun-2016 
> (e.g.)
> # the 'format' returns a string with date in format '%b' (which is just the 
> name of the month)
> 
> On Wed, Mar 9, 2016 at 3:52 PM, Jeff Newmiller  <mailto:jdnew...@dcn.davis.ca.us>> wrote:
> Your dates are incomplete (no year) so I suggest staying away from the date 
> functions for this. Read ?regex and ?sub.
> 
> x <- c( "3-Oct", "10-Nov" )
> m <- sub( "^\\d+-([A-Za-z]{3})$", "\\1", x )
> 
> --
> Sent from my phone. Please excuse my brevity.
> 
> On March 9, 2016 10:14:25 AM PST, KMNanus  <mailto:kmna...@gmail.com>> wrote:
> >I have a series of dates in  format 3-Oct, 10-Oct, 20-Oct, etc.
> >
> >I want to create a variable of just the month.  If I convert the date
> >to a character string, substr is ineffective because some of the dates
> >have 5 characters (3-Oct) and some have 6 (10-Oct).
> >
> >Is there a date function that accomplishes this easily?
> >
> >Ken
> >kmna...@gmail.com <mailto:kmna...@gmail.com>
> >914-450-0816 (tel)
> >347-730-4813 (fax)
> >
> >
> >
> >__
> >R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
> >UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help 
> ><https://stat.ethz.ch/mailman/listinfo/r-help>
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html 
> ><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 <mailto:R-help@r-project.org> mailing list -- To 
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help 
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html 
> <http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 
> -- 
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way 
> Corvallis, OR 97331 
> ph: 541-750-0953
> ddalth...@usgs.gov <mailto:ddalth...@usgs.gov>
> 

__
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] Everything in ggplot2 is blue

2016-03-12 Thread KMNanus
I’m working with a data frame called “Koufax” (his lifetime pitching stats) in 
order to improve my ggplot2 skills.

I’ve worked with a variety of iterations of ken <- ggplot(koufax, aes(x = W, y 
= IPouts, color = SO)) + geom_bar(stat = "identity”)  but all the bars come up 
blue, even if I call... ken +   scale_fill_gradient(low = "red",high = 
"yellow”).

Has this happened to anyone?  I’m wondering if there’s a package that I need to 
load through a library call.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] How To Start R Studio After Installation

2016-03-19 Thread KMNanus
If you’re on a mac, just go into finder, then applications. highlight R studio 
and drag it to the dock.  Then double-click it and r studio should start.

If you’re on Windows, I don’t have a clue.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 19, 2016, at 10:09 AM, Prasad Kale  
> wrote:
> 
> Hello,
> 
> I am new to 'R' and just now installed R as well as 'R Studio' on my
> personal desktop.
> 
> Firstly I have downloaded R and I am able open the same as well.
> 
> Afterwords I have downloaded and installed the 'R Studio' but i don't know
> from where I can open the 'R Studio'. As I am not finding a short cut from
> where I can open the 'R Studio'.
> 
> Please Help..
> 
>   [[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] Help! Mann whitney

2016-03-21 Thread KMNanus
Here’s how I did it - 

Save the xlsx file as a .csv.  Then call read.csv(“your file.csv”) and you 
should be in.

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 20, 2016, at 1:37 PM,   
> wrote:
> 
> This may be really basic, but could you help me with this issue?
> I have an excel file named table1.xls.
> I need to input this table in r, in order to calculate mann whitney between
> columns 1 and 2.
> Could you please show me how to do this task?
> 
>   [[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] installing packages

2016-03-21 Thread KMNanus
Have you set your working directory to the “3.2” folder?
Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 21, 2016, at 5:07 PM, James Henson  wrote:
> 
> Dear R community,
> 
> When I install or update a package, R prints the waring below.  I go to the
> ‘downloaded_packages’ folder in the Temp file and manually move the new or
> updated package to the folder ‘3.2’.   How can I instruct R to download new
> and updates packages into the ‘3.2’ folder?
> 
> Warning in install.packages :
> 
>  unable to move temporary installation
> ‘C:\Users\james_henson\Desktop\Documents\R\win-library\3.2\file1c5c6f1731c8\nlme’
> to ‘C:\Users\james_henson\Desktop\Documents\R\win-library\3.2\nlme
> 
> 
> 
> The downloaded binary packages are in
> 
> 
> C:\Users\james_henson\AppData\Local\Temp\RtmpIZmUa3\downloaded_packages
> 
> 
> 
> Thank for your help.
> 
> James F. Henson
> 
>   [[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] Manually inserting an extra tick on the y axis in ggplot2

2016-03-25 Thread KMNanus
I have called geom_hline to insert a horizontal line on the y axis of a plot at 
a given point.

How can I insert the corresponding tick and its value on the y axis itself?

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



__
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] Manually inserting an extra tick on the y axis in ggplot2

2016-03-25 Thread KMNanus
Thanks.  Actually, found a good answer online - 

I wanted a horizontal line with a y intercept of 12.6.

I set m <- 12.6

I drew the line with geom_hline then added geom_text(aes(0,m,label = m, vjust = 
-1))

which worked just fine.  

Ken
kmna...@gmail.com
914-450-0816 (tel)
347-730-4813 (fax)



> On Mar 25, 2016, at 5:15 PM, John Kane  wrote:
> 
> You might abe able to do it by using scale_y_continuous() but it would be a 
> great help to see some (minimal) code and some sample data.
> 
> Please have a look at
> http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
>  and/or http://adv-r.had.co.nz/Reproducibility.html
> 
> Re  scale_y_continuous() have a look at 
> http://stackoverflow.com/questions/8696/specify-tick-marks-on-y-axis-ggplot2
>  which might suggest some approaches.
> 
> John Kane
> Kingston ON Canada
> 
> 
>> -Original Message-
>> From: kmna...@gmail.com
>> Sent: Fri, 25 Mar 2016 10:07:10 -0400
>> To: r-help@r-project.org
>> Subject: [R] Manually inserting an extra tick on the y axis in ggplot2
>> 
>> I have called geom_hline to insert a horizontal line on the y axis of a
>> plot at a given point.
>> 
>> How can I insert the corresponding tick and its value on the y axis
>> itself?
>> 
>> Ken
>> kmna...@gmail.com
>> 914-450-0816 (tel)
>> 347-730-4813 (fax)
>> 
>> 
>> 
>> __
>> 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.
> 
> 
> FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
> family!
> Visit http://www.inbox.com/photosharing to find out more!
> 
> 

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