Re: [R] How do I parse text?

2013-09-06 Thread Tyler Rinker
Henry,

Have look at the qdap package's termco, wfm, adjacency_matrix, and (possibly) 
word_associate functions.  I'm not sure if they'll work as you really don't 
give much in the way of what the data is and the desired output (an example of 
the output).

Cheers,
Tyler Rinker

 
> From: htrobert...@seton.org
> To: r-help@r-project.org
> Date: Fri, 6 Sep 2013 21:14:42 +
> Subject: [R] How do I parse text?
>
> I have a data frame with a character field of the form "ACUTE URI NOS", "OPEN 
> WOUND OF FOREHEAD", "CROUP", "STREP SORE THROAT", 
>
> How can I get counts of all the words and their co-occurences? I've spent a 
> long time searching on google, but it just takes me on a wild goose chase of 
> dozens of modules involving advanced natural language processing theory. All 
> I want is word counts and co-occurences.
>
> Thanks
>
>
>
>
> CONFIDENTIALITY NOTICE:\ This email message and any acco...{{dropped:13}}
>
> __
> R-help@r-project.org mailing list
> 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
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] Trouble with Slidify and Latex

2013-09-01 Thread Tyler Rinker
Is there a reason not to contact the package author directly and ask him?  
slidify isn't on CRAN so likely you got it from GitHub which is where you 
discuss package problems, particularly, a beta package's problems.  Here is the 
link to the issues page for slidify: https://github.com/ramnathv/slidify/issues?state=open

Tyler Rinker 



> From: noahsilver...@ucla.edu
> Date: Sun, 1 Sep 2013 13:40:52 -0700
> To: r-help@r-project.org
> Subject: [R] Trouble with Slidify and Latex
>
> Hi,
>
> (Re-submitting as the original doesn't look like it made it to the list.)
>
> Just starting to play around with the awesome Slidify package.
>
> For some reason, I can't get it to render any Latex in the presentation. Have 
> reviews all the docs and think I'm doing things correctly. Is there something 
> possibly broken with my installation, or am I misunderstanding the markdown 
> syntax?
>
> I have, on a single slide:
>
> Test $A = 1+2$ and some text after
>
> What I see in the Presentation:
>
>
> Test \(A = 1+2\) and some text after
>
>
> Note: This is literally a "slash" followed by a "parenthesis" in the final 
> HTML slide.
>
>
> Any ideas on what's wrong here?
>
> Thanks.
>
> --
> Noah Silverman, C.Phil
> UCLA Department of Statistics
> 8117 Math Sciences Building
> Los Angeles, CA 90095
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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
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] Incorporating a dataset only package

2013-08-25 Thread Tyler Rinker
Greetings R Community,

I am attempting to make sure a parent package passes all CRAN checks for the 
dev version (R Under development (unstable) (2013-08-24 r63687) -- "Unsuffered 
Consequences").  The parent package I'm compiling relies on another package 
that is purely a dataset package as recommended by  CRAN Repository Policy for 
larger data sets:


"Where a large amount of data is required (even after compression), 
consideration should be given to a separate data-only package which can be 
updated only rarely (since older versions of packages are archived in 
perpetuity)."


The dataset only package is used heavily by the parent in that the data sets 
are frequently used by the parent package's functions and, additionally, it is 
sensible (in my opinion; particularly considering the intended user for my 
package) that the user would not need to manually load the dataset package when 
loading the parent package and still have access to all the data. 


In the past I would have loaded the data sets from the data set only package by 
adding the dataset package to the `Depends:` field in the `DESCRIPTION file` of 
the parent package.  In the R dev version (Windows; R Under development 
(unstable) (2013-08-24 r63687) -- "Unsuffered Consequences") a Note occurs when 
including this dataset only package in the Depends field and nothing is 
actually imported (currently I don't export data sets but maybe I should be 
adding @exports to the roxygen2 documentation):


* checking dependencies in R code ... NOTE
Package in Depends field not imported from: 'qdapDictionaries'
  These packages needs to imported from for the case when
  this namespace is loaded but not attached.
See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.


If the datasets were actually functions I could use @importFrom (roxygen2 
documentation) to import the functions, and the Note would go away, but in this 
case the package contains datasets which are not exported (I don't think you're 
supposed to export data sets but would love to be wrong).


What is the best approach to having a data only package be accessible to the 
parent functions and user without explicitly loading the data set package, yet, 
pass the R dev version (R Under development (unstable) (2013-08-24 r63687) -- 
"Unsuffered Consequences") check?  This desired outcome is very much the way 
the `datasets` package is loaded by default when R starts.



Cheers

Tyler (apologies on the double send as the first one had no subject line)
===


Plain text version of this email: 
https://dl.dropboxusercontent.com/u/61803503/Errors/depends_question.txt

__
R-help@r-project.org mailing list
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] (no subject)

2013-08-25 Thread Tyler Rinker
Greeting R Community,


Greetings R Community,

I am attempting to make sure a parent package passes all CRAN checks for the 
dev version (R Under development (unstable) (2013-08-24 r63687) -- "Unsuffered 
Consequences").  The parent package I'm compiling relies on another package 
that is purely a dataset package as recommended by  CRAN Repository Policy for 
larger data sets:


"Where a large amount of data is required (even after compression), 
consideration should be given to a separate data-only package which can be 
updated only rarely (since older versions of packages are archived in 
perpetuity)."


The dataset only package is used heavily by the parent in that the data sets 
are frequently used by the parent package's functions and, additionally, it is 
sensible (in my opinion; particularly considering the intended user for my 
package) that the user would not need to manually load the dataset package when 
loading the parent package and still have access to all the data. 


In the past I would have loaded the data sets from the data set only package by 
adding the dataset package to the `Depends:` field in the `DESCRIPTION file` of 
the parent package.  In the R dev version (Windows; R Under development 
(unstable) (2013-08-24 r63687) -- "Unsuffered Consequences") a Note occurs when 
including this dataset only package in the Depends field and nothing is 
actually imported (currently I don't export data sets but maybe I should be 
adding @exports to the roxygen2 documentation):


* checking dependencies in R code ... NOTE
Package in Depends field not imported from: 'qdapDictionaries'
  These packages needs to imported from for the case when
  this namespace is loaded but not attached.
See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.


If the datasets were actually functions I could use @importFrom (roxygen2 
documentation) to import the functions, and the Note would go away, but in this 
case the package contains datasets which are not exported (I don't think you're 
supposed to export data sets but would love to be wrong).


What is the best approach to having a data only package be accessible to the 
parent functions and user without explicitly loading the data set package, yet, 
pass the R dev version (R Under development (unstable) (2013-08-24 r63687) -- 
"Unsuffered Consequences") check?



Cheers

Tyler
===


Plain text version of this email: 
https://dl.dropboxusercontent.com/u/61803503/Errors/depends_question.txt

__
R-help@r-project.org mailing list
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] Parts of Speach Tagging

2013-08-24 Thread Tyler Rinker
Have a look at ?Maxent_POS_Tag_Annotator  The examples show you how to get the 
tagPOS behavior.
Cheers,Tyler

> Date: Sun, 25 Aug 2013 04:11:33 +0530
> From: sid.aru...@gmail.com
> To: r-help@r-project.org; r-h...@stat.math.ethz.ch
> Subject: [R] Parts of Speach Tagging
> 
> I was using tagPOS function from openNLP package for parts-of-speach. Now
> the package is updated and the function is not present. Any suggestions how
> to do it now ?
> 
> Thanks for your help.
> 
> -- 
> Regards,
> 
> Siddharth Arun,
> Contact No. - +91 8880065278
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] custom startup/welcome message

2013-04-04 Thread Tyler Rinker
What is your OS?


> Fom: michael.weyla...@gmail.com
> Date: Thu, 4 Apr 2013 15:31:31 -0500
> To: pelj...@yahoo.co.uk
> CC: r-help@r-project.org
> Subject: Re: [R] custom startup/welcome message
>
> On Thu, Apr 4, 2013 at 9:49 AM, lejeczek  wrote:
> > yeap, I've done it,
> > I was hoping for a complete customization,
> > and even Rprofile.site adds only to what is being printed by default anyway,
> > I mean that header is always there. R version. untill "Type 'q()'..
> > and R -q silences everything :(
> >
>
> I'm not sure what the question is now (and please "context post"
> instead of top-posting) -- I suppose you could patch the C code that
> prints that message if you want it to say something else. You'd have
> to re-build R but it's easy code to change.
>
> It's at the top of $R_HOME/src/main/version.c:
> http://svn.r-project.org/R/trunk/src/main/version.c
>
> Michael
>
> >
> >
> > On 04/04/13 15:01, Michael Weylandt wrote:
> >>
> >> On Apr 4, 2013, at 6:20, lejeczek  wrote:
> >>
> >>> hi everybody
> >>>
> >>> I wonder if there is a simple way, but not simple would be
> >>> ok too,
> >>> to customize info/welcome page at session start time?
> >>
> >> Probably easiest to do it by way of some cat() calls in your .Rprofile.
> >> See ?Startup for details.
> >>
> >> MW
> >>
> >>> what I'd like to do is to put together simple short howto /
> >>> dos & don'ts page for users,
> >>> I'm thinking it would be great if it was possible
> >>>
> >>> many thanks
> >>>
> >>> [[alternative HTML version deleted]]
> >>>
> >>> __
> >>> R-help@r-project.org mailing list
> >>> 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
> > 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
> 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
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] [R-pkgs] reports 0.1.2 released

2013-03-12 Thread Tyler Rinker

I'm very pleased to announce the release of reports: An R package to assist in 
the workflow of writing academic articles and other reports.


This is a bug fix release of reports: 
http://cran.r-project.org/web/packages/reports/index.html


The reports package assists in writing reports and presentations by providing a 
frame work that brings together existing R, LaTeX/.docx and Pandoc tools. The 
package is designed to be used with RStudio, MiKTex/Tex Live/LibreOffice, 
knitr, knitcitations, Pandoc and pander. The user will want to download these 
free programs/packages to maximize the effectiveness of the reports package. 
Functions with two letter names are general text formatting functions for 
copying text from articles for inclusion as a citation.


Github development version: https://github.com/trinker/reports


As reports is further developed the following are planned: (a) a help video 
section and (b) a vignette detailing workflow and use of reports.


Tyler Rinker

  
___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list
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] Word Frequency for each row

2013-03-09 Thread Tyler Rinker


I see you provided sample data.  Here it is with that:


library(qdap)
termco(dat$Data, dat$ID, c(" oranges "))



> From: tyler_rin...@hotmail.com
> To: sudipanal...@gmail.com; r-help@r-project.org
> Date: Sat, 9 Mar 2013 17:20:24 -0500
> Subject: Re: [R] Word Frequency for each row
>
>
> I think the qdap package's termco (termo count) function will do what you 
> want. Read the specifics as spacing around the word matters.
>
>
>
> library(qdap);
> termco(DATA$state, 1:nrow(DATA), c("it"))
>
>
>
>
> 
> > Date: Fri, 8 Mar 2013 21:34:31 +0530
> > From: sudipanal...@gmail.com
> > To: r-help@r-project.org
> > Subject: [R] Word Frequency for each row
> >
> > Hi All,
> >
> > I am wondering if there is any examples where you can count your
> > interested "word" in each row. For an example if you have data with *'ID*'
> > and '*write-up*' for 100 rows, how would I calculate the word frequency for
> > each row ?
> >
> > Thank you for all your time.
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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
> 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
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] Word Frequency for each row

2013-03-09 Thread Tyler Rinker

I think the qdap package's termco (termo count) function will do what you want. 
Read the specifics as spacing around the word matters.
    


library(qdap);       
termco(DATA$state, 1:nrow(DATA), c("it"))
    




> Date: Fri, 8 Mar 2013 21:34:31 +0530
> From: sudipanal...@gmail.com
> To: r-help@r-project.org
> Subject: [R] Word Frequency for each row
>
> Hi All,
>
> I am wondering if there is any examples where you can count your
> interested "word" in each row. For an example if you have data with *'ID*'
> and '*write-up*' for 100 rows, how would I calculate the word frequency for
> each row ?
>
> Thank you for all your time.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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
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] [R-pkgs] qdap 0.2.0 released

2013-02-04 Thread Tyler Rinker

qdap (Quantitative Discourse Analysis Package) is an R package designed to 
assist in quantitative discourse analysis. The package stands as a bridge 
between qualitative transcripts of dialogue and statistical analysis and 
visualization.


This is the first CRAN release of qdap: 
http://cran.r-project.org/web/packages/qdap/index.html


The qdap package automates many of the tasks associated with quantitative 
discourse analysis of transcripts containing discourse including frequency 
counts of sentence types, words, sentence, turns of talk, syllable counts and 
other assorted analysis tasks. The package provides parsing tools for preparing 
transcript data. Many functions enable the user to aggregate data by any number 
of grouping variables providing analysis and seamless integration with other R 
packages that undertake higher level analysis and visualization of text. This 
provides the user with a more efficient and targeted analysis.


Github development version: https://github.com/trinker/qdap


As qdap is further developed the following are planned: (a) a github hosted 
website via statics (b) a help video section and (c) a vignette detailing 
workflow and use of qdap.


Tyler Rinker  
___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
R-help@r-project.org mailing list
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] Creating an R package in windows- where to put images?

2012-12-09 Thread Tyler Rinker

I recently included a .bib file in a package in the directory: 
package_name/inst/extdata


I then recall this file using:  <- system.file("extdata/bibTest.bib", package = 
"metaDAT")


I assume something similar could be helpful here.
> From: jdnew...@dcn.davis.ca.us
> Date: Sun, 9 Dec 2012 22:11:47 -0800
> To: su...@sssu.edu.in; r-help@r-project.org
> Subject: Re: [R] Creating an R package in windows- where to put images?
> 
> http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Data-in-packages
> 
> Don't get stuck on your idea that the file is a gif... once you load it into 
> memory it is an R object.
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  Live Go...
>   Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
> --- 
> Sent from my phone. Please excuse my brevity.
> 
> Subramanian S  wrote:
> 
> >My R version: 2.15.1- windows
> >
> >While creating an R package in windows, i want to include an image (a
> >.gif
> >image) that will finally be in the package. A function in my package
> >will
> >call the gif image. Where should i put the images before running "Rcmd
> >build mypkg" or "Rcmd INSTALL --build mypkg", so that after creating
> >the
> >package, the .zip file / .tar.gz/ .tgz would have the gif image in the
> >correct place in each OS.  Basically two questions (1) which directory
> >should i put the gif image before building the pkg and (2)how do i
> >specify
> >the path in the function that will call the gif image?
> >
> > [[alternative HTML version deleted]]
> >
> >__
> >R-help@r-project.org mailing list
> >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
> 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
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] Long equation in documentation

2012-12-09 Thread Tyler Rinker

I have a long equation that I need to break in the R documentation of a package 
or it trails off the right hand side of the page. Here's the formula:


\deqn{Cov(r_{ist}, r_{iuv})= [.5\rho_{ist}\rho_{iuv}(\rho_{isu}^2 + 
\rho_{isv}^2 + \rho_{itu}^2 + \rho_{itv}^2) + \rho_{isu}\rho_{itv}+ 
\rho_{isv}\rho_{itu}-(\rho_{ist}\rho_{isu}\rho_{isv} + 
\rho_{its}\rho_{itu}\rho_{itv}) + \rho_{ius}\rho_{iut}\rho_{iuv} + 
\rho_{ivs}\rho_{ivt}\rho_{ivu}]/n_i}



How can I break the formula and optionally indent the second lower piece; 
though I'd settle for break it right now? 

Tyler Rinker

Note:  Cross posted here after no viable answer on stackoverflow: 
http://stackoverflow.com/questions/13780190/break-long-formula-r-documentation

Plain txt file attached in case message is garbled. 
  I have a long formula that I need to break in the R documentation of a package 
or it trails off the right hand side of the page. Here's the formula:



\deqn{Cov(r_{ist}, r_{iuv})= [.5\rho_{ist}\rho_{iuv}(\rho_{isu}^2 + 
\rho_{isv}^2 + \rho_{itu}^2 + \rho_{itv}^2) + \rho_{isu}\rho_{itv}+ 
\rho_{isv}\rho_{itu}-(\rho_{ist}\rho_{isu}\rho_{isv} + 
\rho_{its}\rho_{itu}\rho_{itv}) + \rho_{ius}\rho_{iut}\rho_{iuv} + 
\rho_{ivs}\rho_{ivt}\rho_{ivu}]/n_i}




How can I break the formula and optionally indent it, though I'd settle for 
break it right now? 


Tyler Rinker


Note:  Cross posted here after no viable answer on stackoverflow: 
http://stackoverflow.com/questions/13780190/break-long-formula-r-documentation__
R-help@r-project.org mailing list
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] First value in a row

2012-07-24 Thread Tyler Rinker

This would work:
X <- lapply(1:nrow(dat1), function(i) rev(dat1[i, -c(1:2)]))sapply(X, 
function(x) x[!is.na(x)][1])


> Date: Tue, 24 Jul 2012 23:56:17 -0300
> From: cm...@dal.ca
> To: smartpink...@yahoo.com
> CC: r-help@r-project.org; henrik.singm...@psychologie.uni-freiburg.de
> Subject: Re: [R] First value in a row
> 
> Hi Henrik and Arun,
> 
> I now understand the script you provided. Very smart solution I think.  
> I wonder, however, if there is an alternative way as to count the last  
> number in a row?.
> For instance, considering the following dataframe
> 
> dat1<-read.table(text="
> Lat  Lon  x1  x2  x3
> 0112  .4  .5  .6
> 0112  .2  .3  NA
> 0111  .1  NA  NA
> 0110  NA  NA  NA
> ",sep="",header=TRUE)
> 
> the last value (from left to right) should be:
> .6
> .3
> .1
> NA
> 
> NAs are always consecutive once they appear.
> 
> Thanks again,
> 
> Camilo
> 
> 
> Camilo Mora, Ph.D.
> Department of Geography, University of Hawaii
> Currently available in Colombia
> Phone:   Country code: 57
>   Provider code: 313
>   Phone 776 2282
>   From the USA or Canada you have to dial 011 57 313 776 2282
> http://www.soc.hawaii.edu/mora/
> 
> 
> 
> Quoting arun :
> 
> > Hi Henrik,
> >
> > Thanks for testing it to a different dataset.  I didn't test it at  
> > that time to multiple conditions.  Probably, apply is a better method.
> >
> >
> > Anyway, you can still get the same result by doing this:
> >
> > dat1<-read.table(text="
> > Lat  Lon  x1  x2  x3
> > 0110  NA  NA  .1
> > 0111  .4  NA  .3
> > 0112  NA  .5  .6
> > ",sep="",header=TRUE)
> > dat2<-data.frame(t(dat1[,3:5]))
> > dat3<-data.frame(dat1,NewColumn=unlist(lapply(dat2,function(x)  
> > x[!is.na(x)][1])))
> >  row.names(dat3)<-1:nrow(dat3)
> >  dat3
> > #  Lat Lon  x1  x2  x3 NewColumn
> > #1   1  10  NA  NA 0.1   0.1
> > #2   1  11 0.4  NA 0.3   0.4
> > #3   1  12  NA 0.5 0.6   0.5
> >
> > #Now, to a slightly different dataset
> > dat1<-read.table(text="
> > Lat  Lon  x1  x2  x3
> > 0110  NA  NA  NA
> > 0111  NA  NA  .3
> > 0112  NA  .6   NA
> > ",sep="",header=TRUE)
> >  dat2<-data.frame(t(dat1[,3:5]))
> >  dat3<-data.frame(dat1,NewColumn=unlist(lapply(dat2,function(x)  
> > x[!is.na(x)][1])))
> >   row.names(dat3)<-1:nrow(dat3)
> >   dat3
> >   #Lat Lon x1  x2  x3 NewColumn
> > #1   1  10 NA  NA  NANA
> > #2   1  11 NA  NA 0.3   0.3
> > #3   1  12 NA 0.6  NA   0.6
> >
> >
> > I hope this works well.
> >
> >
> > A.K.
> >
> >
> >
> >
> > - Original Message -
> > From: Henrik Singmann 
> > To: arun 
> > Cc: Camilo Mora ; R help 
> > Sent: Tuesday, July 24, 2012 10:18 AM
> > Subject: Re: First value in a row
> >
> > Hi,
> >
> > As Arun's idea was also my first idea let me pinpoint the problem of  
> > this solution.
> > It only works if the data in question (i.e., columns x1 to x3)  
> > follow the pattern of the example data insofar that the NAs form a  
> > triangle like structure. This is so because it loops over columns  
> > instead of rows and takes advantage of the triangle NA structure.
> >
> > For example, slightly changing the data leads to a result that does  
> > not follow the description of Camilo seem to want:
> >
> > dat1<-read.table(text="
> > Lat  Lon  x1  x2  x3
> > 0110  NA  NA  .1
> > 0111  .4  NA  .3
> > 0112  NA  .5  .6
> > ",sep="",header=TRUE)
> >
> > # correct answer from description would be .1, .4, .5
> >
> > # arun's solution:
> > data.frame(dat1,NewColumn=rev(unlist(lapply(dat1[,3:5],function(x)  
> > x[!is.na(x)][1]
> >
> > #  x3  x2  x1
> > # 0.1 0.5 0.4
> >
> > # my solution:
> > apply(dat1[,-(1:2)], 1, function(x) x[!is.na(x)][1])
> >
> > # [1] 0.1 0.4 0.5
> >
> > So the question is, what you want and how the data looks.
> >
> > Cheers,
> > Henrik
> >
> >
> > Am 24.07.2012 14:27, schrieb arun:
> >> Hi,
> >>
> >> Try this:
> >>
> >> dat1<-read.table(text="
> >> Lat  Lon  x1  x2  x3
> >> 0110  NA  NA  .1
> >> 0111  NA  .2  .3
> >> 0112  .4  .5  .6
> >> ",sep="",header=TRUE)
> >>
> >> dat2<-dat1[,3:5]
> >> 
> >> dat3<-data.frame(dat1,NewColumn=rev(unlist(lapply(dat2,function(x)  
> >> x[!is.na(x)][1]
> >> row.names(dat3)<-1:nrow(dat3)
> >>dat3
> >> Lat Lon  x1  x2  x3 NewColumn
> >> 1   1  10  NA  NA 0.1   0.1
> >> 2   1  11  NA 0.2 0.3   0.2
> >> 3   1  12 0.4 0.5 0.6   0.4
> >>
> >> A.K.
> >>
> >>
> >>
> >>
> >> - Original Message -
> >> From: Camilo Mora 
> >> To: r-help@r-project.org
> >> Cc:
> >> Sent: Tuesday, July 24, 2012 2:48 AM
> >> Subject: [R] First value in a row
> >>
> >> Hi.
> >>
> >> This is likely a trivial problem but have not found a solution.  
> >> Imagine the following dataframe:
> >>
> >> Lat   Lon  x1   x2  x3
> >> 0110   NA   NA  .1
> >> 0111   NA   .2  .3
> >> 0112   .4   .5  .6
> >>
> >> I want to generate another column that consist of the first value  
> >> in each row from columns x1 to x3. That is
> >>
> >> NewColu

Re: [R] Plot

2012-05-14 Thread Tyler Rinker

I noticed I was remiss in addressing your origin question:
Use the xlim and ylim, setting the lower limit to 0.  Here's an example of this 
with the CO2 dataset:


plot(uptake~Plant, data=CO2)


plot(uptake~as.numeric(Plant), data=CO2)


plot(uptake~as.numeric(Plant), data=CO2, ylim=c(0, 50), xlim=c(0, 14))



Cheers,Tyler

> From: tyler_rin...@hotmail.com
> To: kellycoo...@yahoo.com; r-help@r-project.org
> Date: Mon, 14 May 2012 16:31:26 -0400
> Subject: Re: [R] Plot
>
>
>
> That is likely because ferm is a factor.  A scatterplot is two numeric 
> variables.  To make it a scatterplot wrap ferm with as.numeric.
> Cheers,
> Tyler
> 
> Date: Mon, 14 May 2012 12:21:12 -0700
> From: kellycoo...@yahoo.com
> To: r-help@r-project.org
> Subject: [R] Plot
>
>
> Hello,
>
> I am trying to make a plot of the rates of an enzyme against three different 
> protein concentrations (there are 45 rates in total and split up into 3 
> groups of 15, each receiving one of the 3 protein concentrations). When I 
> enter the following code I instead get 3 separate boxplots for each of the 
> three different protein concentrations ...
>
>
> plot(rate ~ ferm, data=LDH, col=LDH$rate, 
> pch=c(17,18,19)[(as.numeric(LDH$rate)%%3)+1])
>
>
> but I want a scatterplot showing 3 different lines indicating each of the 
> protein concentrations. I'm not sure if I need to tweak my data set in order 
> to get what I want?
>
> I was also wondering how to include the origin (0,0) in the plots. I'm not 
> sure if I'm missing something on the plot help page?
>
> Any help would be appreciated. Thanks so much.
> [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> 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
> 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
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error in names(x) <- value: 'names' attribute must be the same length as the vector

2012-05-14 Thread Tyler Rinker


I'd throw a browser() in at that point and see what colnames(newdf.int) gives 
you.  If you have less columns than names this is likely the reason for the 
error.
You can get the same error with:

colnames(mtcars) <- LETTERS

Cheers,Tyler

> Date: Mon, 14 May 2012 11:35:07 -0700
> From: bhatt...@gmail.com
> To: r-help@r-project.org
> Subject: [R] Error in names(x) <- value: 'names' attribute must be the same 
> length as the vector
>
> Dear R-helpers,
>
> I am stuck on an error in R: When I run my code (below), I get this error
> back:
>
> Error in names(x) <- value :
> 'names' attribute must be the same length as the vector
>
>
> Then when I use traceback(), R gives me back this in return:
>
> `colnames<-`(`*tmp*`, value = c(""Item", "Color" ,"Number", "Size"))
>
>
>
> I'm not exactly sure how to fix this problem. Any advice would be greatly
> appreciated!
>
> Thanks,
> Priya
>
>
> MODIFIED CODE:
> # Looping through a series of CSV files
> for (c in csvfiles)
> {
> #A DF (prevdf) was created based on an initial csv file..
> #so the condition below states that if there are rows with NAs or the
> number of rows in prevdf is zero
> if( (apply(prevdf, 1, function(y) !sum(!is.na(y))==1) > 0) ||
> (nrow(prevdf) == 0) )
> {
> #Open a new file
> currentCSVFile <- read.csv(c, header=TRUE)
> #pick only the few columns we want from the file
> currentCSVFile <- data.frame(currentCSVFile$Item,
> currentCSVFile$Color..type , currentCSVFile$Number..owned,
> currentCSVFile$Size..shirt)
> #rename the column names
> colnames(currentCSVFile) <- c("Item", "Color" ,"Number", "Size")
>
> #find the rows in prevdf that do not have any values. (sum should be 1
> because the Item name is unique for every row)
> NArows <- prevdf[apply(prevdf, 1, function(y) sum(!is.na(y))==1),]
>
> #if NAs rows is not equal to zero
> if (nrow(NArows) != 0 )
> {
> #find the rows in the current CSV file where there is missing data in
> prevdf (this info is in NArows)
> intersectItem<- intersect(currentCSVFile$Item, NArows$Item)
>
> #initiate another data frame to put the data in
> newdf.int <- data.frame(Item=c(), Color=c(), Number=c(), Size=c())
>
>
> print(nrow(currentCSVFile))
> for (i in 1:nrow(currentCSVFile))
>
> {
> print("In loop") # check for me
> row <- currentCSVFile[i,]
>
> if (row$Item %in% intersectItem){ # this is where the code stops
> and throws back error
> .
> .
> .
> # do stuff to fill vectors named Item, Color, Number and Size
> .
> .
> .
>
> newdf.int <-rbind(newdf.int, c(Item, Color, Number, Size)
> }
>
> colnames(newdf.int) <- c("Item", "Color", "Number", "Size")
> prevdf <- merge(newdf.int, prevdf, by=c("Item", "Color", "Number",
> "Size"), all=TRUE)
> prevdf <- prevdf[apply(prevdf, 1, function(y) !sum(!is.na(y))==1),]
> print("after removing row = 1")
>
>
> } # end of for loop
>
> } # end of NA rows condition
>
> } # end of main if statement
>
> else
> {
> break
> }
>
>
> }
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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
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] Plot

2012-05-14 Thread Tyler Rinker


That is likely because ferm is a factor.  A scatterplot is two numeric 
variables.  To make it a scatterplot wrap ferm with as.numeric. 
Cheers,
Tyler

Date: Mon, 14 May 2012 12:21:12 -0700
From: kellycoo...@yahoo.com
To: r-help@r-project.org
Subject: [R] Plot


Hello,

I am trying to make a plot of the rates of an enzyme against three different 
protein concentrations (there are 45 rates in total and split up into 3 groups 
of 15, each receiving one of the 3 protein concentrations). When I enter the 
following code I instead get 3 separate boxplots for each of the three 
different protein concentrations ...


plot(rate ~ ferm, data=LDH, col=LDH$rate, 
pch=c(17,18,19)[(as.numeric(LDH$rate)%%3)+1])


but I want a scatterplot showing 3 different lines indicating each of the 
protein concentrations. I'm not sure if I need to tweak my data set in order to 
get what I want?

I was also wondering how to include the origin (0,0) in the plots. I'm not sure 
if I'm missing something on the plot help page?

Any help would be appreciated. Thanks so much.
[[alternative HTML version deleted]]


__
R-help@r-project.org mailing list
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
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 specify multiple regular expressions for pattern argument

2012-05-11 Thread Tyler Rinker


I'm curious about the 'real' answer myself but this would work:



ls(pattern='^d')[ls(pattern='^d') %in% ls(pattern='[[:digit:]]$')]


Cheers,Tyler Rinker


> Date: Fri, 11 May 2012 13:18:59 -0500
> From: jun.shen...@gmail.com
> To: r-h...@stat.math.ethz.ch
> Subject: [R] How to specify multiple regular expressions for pattern argument
>
> Dear list,
>
> I want to show all the objects starting with "d" and ending with a digit.
> How do I specify these conditions in the pattern argument
>
> I can do one condition but not two
>
> ls(pattern='^d')
> ls(pattern='[[:digit:]]$')
>
> are working.
>
> But,
>
> ls(pattern='^d'&'[[:digit:]]$') is not working.
>
> Appreciate any comment.
>
> Jun Shen
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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
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] for loop problem

2012-04-30 Thread Tyler Rinker


I don't really work with dates but thought I'd pass a solution on.  I think 
that there some great packages for handling dates though (lubridate) and you 
may want to convert your data to a true date instead of separate columns.

# FUNCTION TO INDEX DATES


date.int <- function(month, year, day){


    yearLength <- function(year) year %% 4 == 0


    key1 <- data.frame(m=1:12, nm=c(31, 28, 31, 30, 31, 30, 31, 30, 31, 31, 30, 
31))


    key1$sum <- c(0, cumsum(key1$nm)[-12])


    key2 <- data.frame(m=1:12, nm=c(31, 29, 31, 30, 31, 30, 31, 30, 31, 31, 30, 
31))


    key2$sum <- c(0, cumsum(key2$nm)[-12])


    ifelse(yearLength(year), key1[month-1, 3] + day, key2[month-1, 3] + day)


}


#TRY IT OUT ON A MADE UP DATA SET


M <- sort(sample(seq(as.Date("2000/1/1"), by="day", length.out=1000), 10))


N <- do.call(rbind, strsplit(as.character(M), "\\-"))


N <- data.frame(apply(N, 2, as.numeric))


colnames(N) <- c('year', 'month', 'day')


with(N, date.int(month=month, year=year, day=day))



> Date: Mon, 30 Apr 2012 17:57:02 -0600
> From: stefan.schrei...@ales.ualberta.ca
> To: r-help@r-project.org
> Subject: [R] for loop problem
>
> Hi all,
>
> I was wondering if you can help me with the following situation:
>
> I have a data frame that includes weather station data for 30 years in
> the form:
>
> YEAR, MONTH, DAY, TEMP
> 1970, 01, 01, -15
> ...
> 1999, 12, 31, -21
>
> I would like to add another variable "JULIAN" that assigns the integers
> 1 to 365 (and 1 to 366 for leap years) for each day of a year over
> multiple years.
>
> Here is what I came up with:
>
> counter<-1
>
> for(i in 1:12){
> for (j in 1:31){
>
> df$JULIAN[df$MONTH==i & stn$DAY==j]<- counter
> counter<-counter+1
> }
> }
>
> R does it exactly what I told it to but I am not satisfied with it since
> it doesn't stop assigning the integers when months have 28, 29 or 30
> days. For instance on Feb-28 JULIAN is 59 and on March-1 it's 64, as
> opposed to be 60.
>
> I am assuming it must be an ifelse statement, and I was messing around
> with it already but without success.
>
> I guess I am missing some vocabulary here and hope someone can give me
> some pointers.
>
> Thanks,
> Stefan
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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
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] introducing R to high school students

2012-04-18 Thread Tyler Rinker

Indrajit,
As a former math teacher I understand your concerns wholly.  My perspective is 
that this must be approached with caution so you don't miss out on the 
important learning but I think with proper guidance and scaffolding this could 
be an amazing tool.  We already using the graphing capabilities of the 
TI-(insert number here) to demonstrate graphing problems, why not put a 
sophisticated tool in their hands that may be very useful to them in the future 
and at least introduce them to programming.  Students are capable of some 
pretty cool and creative things if we give them the tools and support to allow 
them to be creative (I mean which one of use didn't program out ti-81s to play 
video games?).
Your point of the learning being hindered isn't lost.  This has to be 
approached delicately so R isn't just another program spitting out 
answers/graphs.  Chris's question sounds like a one time intro thing so this 
may be a moot pint, however if the R learning is more long term, I would 
suggest some sort of lab set up (maybe a "lab day") each week that augments and 
compliments the standard curriculum.  One thing I may advise against is 
the  "--maybe t-tests, chi-square tests, and simple linear regression." as this 
is usually far beyond the scope of high school curriculum (at least to 
my knowledge). 
Could I also suggest you do some eye candy (not much but some) where you show a 
few of the things R is capable of to get their interests peaked (I consider 
this like playing guitar; I learned it because Hendrix played sweet stuff not 
because I liked playing basic chords and scales; I plugged through the 
elementary stuff because I knew Hendrix, Clapton, and Page were within my grasp 
if I kept going).  Here's a few 
suggestions:http://paulbutler.org/archives/visualizing-facebook-friends/
http://blog.revolutionanalytics.com/2012/01/nyt-uses-r-to-map-the-1.html
http://blog.revolutionanalytics.com/2009/11/choropleth-challenge-result.html
http://www.r-bloggers.com/visualize-your-facebook-friends-network-with-r/
http://www.r-bloggers.com/see-the-wind/
http://www.r-bloggers.com/mapped-british-and-spanish-shipping-1750-1800/

And also I'd introduce them to Anthony Damico's "r twotorials" as it provides 
catchy short tutorials on how to do basic 
stuff:http://www.twotorials.com/2012/04/

I wish I knew R when I was a math teacher and applaud any effort to engage 
students in authentic learning with powerful tools that they may use later on.  
I would encourage physics teachers to incorporate R too.  
Tyler Rinker
From: indra_cali...@yahoo.com
To: R-help@r-project.org
Subject: Re: [R] introducing R to high school students


Hi Chris,

I am not sure, whether introducing R to High School students would be a good 
idea as I feel we should encourage students to sketch the graphs in paper to 
get their concepts right. Excel is fine, but - if I write an equation on the 
board, will the student be able to visualize its graph? Allowing students to 
use software to plot graphs at a very early age may hinder that learning. What 
I would focus on (as the teacher pointed out - that they may not be able to 
write code) - is being able to write simple codes to get a grasp on programming 
(they can use QBASIC which is one of the simplest programming softwares).

R to my mind should be introduced at an undergraduate level - where they are 
able to use its real power (vectors, matrices, graphics etc.).

Thats my view :)

Regards,
Indrajit





From: Christopher W Ryan 
To: R-help 
Sent: Wednesday, April 18, 2012 8:16 AM
Subject: [R] introducing R to high school students

I participate peripherally on a listserve for middle- and high-school
science teachers. Sometimes questions about graphing or data analysis
come up. I never miss an opportunity to advocate for R. However, the
teachers are often skeptical that their students would be able to
issue commands or write a little code; they think it would be too
difficult. Perhaps this stems from the Microsoft- and
spreadsheet-centered, pointy-clicky culture prevalent in most US
public schools. Then again, I have little experience teaching this age
group, besides my own kids and my Science Olympiad team, so I respect
their concerns and expertise.

I don't know yet what software they generally use, but I suspect MS
Excel and SPSS.

Now I have to put my money where my mouth is. I've offered to visit a
high school and introduce R to some fairly advanced students
participating in a longitudinal 3-year science research class.

I anticipate keeping things very simple:
--objects and the fact that there is stuff inside them. str(), head(), tail()
--how to get data into R
--dataframes, as I imagine they will mostly be using single,
"rectangular" datasets
--a lot of graphics (I can't imagine that  plot(force, acceleration)
is beyond a high-schooler's capabili

Re: [R] Choose between duplicated rows

2012-04-14 Thread Tyler Rinker


My solution:
SP <- split(df, df[, 1:2])
minner <- function(x, col = 'numMiss') {    x[which.min(unlist(x[,col])), , 
drop=FALSE]}
NEW <- do.call('rbind', lapply(SP, minner))SP2 <- split(NEW, NEW[, 
'id'])do.call('rbind', lapply(SP2, function(x) minner(x, 'A')))

Cheers,Tyler

> Date: Sat, 14 Apr 2012 12:03:36 -0700
> From: francy.casal...@gmail.com
> To: r-help@r-project.org
> Subject: [R] Choose between duplicated rows
> 
> Dear r experts,
> 
> Sorry for this basic question, but I can't seem to find a solution…
> 
> I have this data frame:
> df <- data.frame(id = c("id1", "id1", "id1", "id2", "id2", "id2"), A =
> c(11905, 11907, 11907, 11829, 11829, 11829), v1 = c(NA, 3, NA,1,2,NA), v2 =
> c(NA,2,NA, 2, NA,NA), v3 = c(NA,1,NA,1,NA,NA), v4 = c("N", "Y", "N", "Y",
> "N","N"), v5 = c(0,0,0,1,0,0), numMiss=c(3,0,3,0,2,3))
> 
> > df
>id A v1 v2 v3 v4 v5numMiss
> 1 id1 11905 NA NA NA  N  03
> 2 id1 11907  3  2  1  Y  0 0
> 3 id1 11907 NA NA NA  N  03
> 4 id2 11829  1  2  1  Y  1 0
> 5 id2 11829  2 NA NA  N  0  2
> 6 id2 11829 NA NA NA  N  0   3
> 
> 
> And I need to keep, of the rows that have the same value for "A" by id, only
> the ones with the least amount of missing values for all the variables (with
> min(numMiss)) to get this:
> 
>id A v1 v2 v3 v4 v5numMiss
> 1 id1 11905 NA NA NA  N  03
> 2 id1 11907  3  2  1  Y  0 0
> 4 id2 11829  1  2  1  Y  1 0
> 
> Then I have to choose the records with the least value of "A" of the rows
> that have the same id like this:
>id A v1 v2 v3 v4 v5numMiss
> 1 id1 11905 NA NA NA  N  03
> 4 id2 11829  1  2  1  Y  1 0
> 
> For groupings I have used the package "plyr" before, but this would involve
> a sort of double-grouping by id and by duplicated values of A…Could you
> please help me understand how this can be done? 
> 
> Thank you very much.
> -f
> 
> 
> 
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Choose-between-duplicated-rows-tp4557833p4557833.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> 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
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] Missing CRAN Mirror

2012-04-06 Thread Tyler Rinker

Hello R community,
This isn't a technical question about R:
I have used 
http://lib.stat.cmu.edu/R/CRAN/ as my mirror for some time now.  As of a few 
days now I don't seem to be able to use this mirror.  The link from CRAN to 
this repository does not work either.  Does anyone know the fate of this 
repository?  
Cheers,Tyler Rinker
If this was not the appropriate place for this question please feel free to 
direct me to a more appropriate place to ask this question.
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Reshape from long to wide

2012-03-20 Thread Tyler Rinker

Another approach, as your needs are very specific (take every other item in the 
second column and the unique values of columns 1) would be to index, use unique 
and put it together with data.frame (or cbind).

data.frame(family = unique(x[, 1]), kid1 = x[c(T, F), 2], kid2 = x[c(F, T), 2])

Cheers,Tyler

> From: jorgeivanve...@gmail.com
> Date: Tue, 20 Mar 2012 00:29:08 -0400
> To: alyaba...@gmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] Reshape from long to wide
> 
> Hi aly,
> 
> Try
> 
> # your data
> x <- structure(list(family = c(14L, 14L, 15L, 15L, 17L, 17L, 18L,
> 18L, 20L, 20L, 24L, 24L, 25L, 25L, 27L, 27L, 28L, 28L, 29L, 29L
> ), length = c(18L, 7L, 7L, 21L, 50L, 21L, 36L, 21L, 36L, 42L,
> 56L, 42L, 43L, 56L, 15L, 42L, 7L, 42L, 56L, 49L)), .Names = c("family",
> "length"), class = "data.frame", row.names = c(NA, -20L))
> 
> # processing
> require(plyr)
> ddply(x, .(family), function(df) c(kid1 = df$length[1], kid2 =
> df$length[2]))
>family kid1 kid2
> 1  14   187
> 2  157   21
> 3  17   50   21
> 4  18   36   21
> 5  20   36   42
> 6  24   56   42
> 7  25   43   56
> 8  27   15   42
> 9  287   42
> 10 29   56   49
> 
> HTH,
> Jorge.-
> 
> 
> On Mon, Mar 19, 2012 at 7:01 PM, aly <> wrote:
> 
> > Hi,
> >
> > I'm a total beginner in R and this question is probably very simple but
> > I've
> > spent hours reading about it and can't find the answer. I'm trying to
> > reshape a data table from long to wide format. I've tried reshape() and
> > cast() but I get error messages every time and I can't figure why. In my
> > data, I have the length of two fish from each family. My data table (called
> > fish) looks like this:
> >
> > family  length
> > 14  18
> > 14  7
> > 15  7
> > 15  21
> > 17  50
> > 17  21
> > 18  36
> > 18  21
> > 20  36
> > 20  42
> > 24  56
> > 24  42
> > 25  43
> > 25  56
> > 27  15
> > 27  42
> > 28  7
> > 28  42
> > 29  56
> > 29  49
> >
> > I want it to look like this:
> >
> > family kid1 kid2
> > 14  18  7
> > 15  7   21
> > 17  50  21
> > 18  36  21
> > 28  36  42
> > 24  56  42
> > 25  43  56
> > 27  15  42
> > 28  7   42
> > 29  56  49
> >
> > I've tried:
> >
> > >cast( fish, fam~length)
> >
> > and got the error message:
> >
> > Using length as value column.  Use the value argument to cast to override
> > this choice
> > Error in `[.data.frame`(data, , variables, drop = FALSE) :
> >  undefined columns selected
> >
> > Then I rename the columns:
> >
> > >myvars<-c("fam","length")
> > >fish<-fish[myvars]
> >
> > and try the cast() again with no luck (same error)
> >
> > By using reshape() I don't get the results I want:
> >
> > >reshape(rdm1, timevar="fam", idvar=c("length"), direction="wide")
> > > head(first)
> >   length
> > 14.2014
> > 14.19 7
> > 15.2521
> > 17.3050
> > 18.3236
> > 20.3642
> >
> > Can someone help with this? Thanks a lot!
> >
> >
> >
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/Reshape-from-long-to-wide-tp4486875p4486875.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org mailing list
> > 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
> 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
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] paste (CTRL + v) not working rgui

2012-03-19 Thread Tyler Rinker

I attempted the advice of Ajay but found that the names ◦Network DDE DSDM, 
◦Network DDE, ◦Clipbook  were not found in that location.
Here's a bit more information about the problem I've discovered.  I have a 
manual I've created of useful R tricks I've elarned that I created as a word 
doc but store as a pdf because it's faster to load and work with.  I've done 
this as long as I've used R.  The problem occurs when I've cut and pasted from 
a pdf to R.  I can get the problem to replicate by doing this over and over 
again.  Here's the weird thing: I can not replicate this problem in R 2.14.1.  
Also if I wait a duration of time the problem goes a way (maybe an hour or two) 
but returns again of I try to cut and paste from a pdf.
Not sure what's going on but it may have to do with encoding issues, but why 
has this not been a problem until R 2.14.2?
Date: Sun, 18 Mar 2012 16:56:50 +
From: aa2e...@yahoo.co.uk
To: lig...@statistik.tu-dortmund.de; aa2e...@lycos.co.uk
CC: r-help@r-project.org
Subject: Re: [R] paste (CTRL + v) not working rgui

 
 
I've definitely encountered problems when running programs without 
administrator righs. Perhaps that was down to virus/spyware protection software.
 
At this linkhttp://forums.techarena.in/windows-software/1258938.htm there is 
the following suggestion
 
1.Click on Start
2.Type Run in Search and hit Enter
3.Type services.msc and hit enter
4.Find These services: ◦Network DDE DSDM.
◦Network DDE.
◦Clipbook.
 
5.Right Click on Each
6.And select Restart
 
NOt tried it - as I do not have the prolem - but it sounds plausible.
 
The alternative to the first 3 steps is Administration Tools + SERVICES>
 
[[alternative HTML version deleted]]
 

__
R-help@r-project.org mailing list
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
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] paste (CTRL + v) not working rgui

2012-03-17 Thread Tyler Rinker

R community,
I feel almost embarrassed to ask this question as it is strange behavior.  When 
I think there's a bug around R or a package I ask "Self it's not a bug what 
dumb thing are you doing?"  
I'm running version 2.14.2 (2012-02-29) on a Windows 7 machine using the 
standard rgui
Ever since I downloaded this latest version I have been having difficulty using 
the windows commands cut and paste (mostly paste) [CNTRL +V].  The problem has 
gotten worse and now I can't paste at all.  This is unique to the 2.14.2 
version as I have no problems using paste in version 2.14.1.  I can also 
cut(CNTRL + c) from the gui and paste elsewhere but not paste withing the gui. 
To specify neither the shortcut command CNTRL + V  or right click/paste works.  
This problem does not occur in other programs either.
I assumed this is a Windows problem at first (and Is till haven't ruled that 
out but that the problem is specific to just the 2.14.2 gui indicates it's not 
a Windows problem) and thought I had a malware that was causing this behavior.  
I've run Webroot and Malwarebites in safe mode and nothing has changed.  I've 
rebooted R several times (which has never alleviated the problem) as well as 
the computer several times (which sometimes alleviates the problem but no 
longer seems to help). I've uninstalled R v. 2.14.2 and reinstalled.  No 
change.  I tried a system restore to 2012-2-19 (and again reinstalled R 2.14.2) 
and no change in behavior.
I appreciate any direction anyone can give me with solving this problem as I 
use the command very frequently.
Cheers,Tyler Rinker   
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Vertical string with horizontal letters

2012-02-02 Thread Tyler Rinker

I apologize for the improperly formatted submission.  I had my hotmail set to 
plain text instead of rich text.
x <- "output"y <- unlist(strsplit(x, NULL))
plot.new()text(.5, .5, paste(y, collapse="\n"))

> From: tyler_rin...@hotmail.com
> To: israelb...@hotmail.com; r-help@r-project.org
> Date: Thu, 2 Feb 2012 13:08:17 -0500
> Subject: Re: [R] Vertical string with horizontal letters
> 
> 
> 
> One possible solution is to use strsplit to break on each character and then 
> paste to put in a "\n" after each character.  Then when you plot the text 
> should be in the format you desire.
> x <- "output"y <- unlist(strsplit(x, NULL))p <- cat(paste(y, collapse="\n"))
> plot.new()text(.5, .5, paste(y, collapse="\n"))
> 
> cheersTyler
> > From: israelb...@hotmail.com
> > To: r-help@r-project.org
> > Date: Thu, 2 Feb 2012 17:20:17 +
> > Subject: [R] Vertical string with horizontal letters
> >
> >
> > I'm trying to format text on a plot such that the string is vertical but 
> > the letters are horizonal. I tried
> > text(1,1,label="output", srt=270)
> > This gives the string rotation I want, but that rotates the entire "output" 
> > so the letters are also rotated. I've also tried
> > text(1,1,label="output", srt=270, crt=270)
> > to no avail. par()$crt doesn't seem to affect text? The format I want is 
> > demonstrated below:
> >
> > o
> > u
> > t
> > p
> > u
> > t
> >
> > Thanks.
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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
> 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
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] Vertical string with horizontal letters

2012-02-02 Thread Tyler Rinker


One possible solution is to use strsplit to break on each character and then 
paste to put in a "\n" after each character.  Then when you plot the text 
should be in the format you desire.
x <- "output"y <- unlist(strsplit(x, NULL))p <- cat(paste(y, collapse="\n"))
plot.new()text(.5, .5, paste(y, collapse="\n"))

cheersTyler
> From: israelb...@hotmail.com
> To: r-help@r-project.org
> Date: Thu, 2 Feb 2012 17:20:17 +
> Subject: [R] Vertical string with horizontal letters
>
>
> I'm trying to format text on a plot such that the string is vertical but the 
> letters are horizonal. I tried
> text(1,1,label="output", srt=270)
> This gives the string rotation I want, but that rotates the entire "output" 
> so the letters are also rotated. I've also tried
> text(1,1,label="output", srt=270, crt=270)
> to no avail. par()$crt doesn't seem to affect text? The format I want is 
> demonstrated below:
>
> o
> u
> t
> p
> u
> t
>
> Thanks.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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
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] tm package: handling contractions

2012-01-27 Thread Tyler Rinker


This may not be the answer to your problem but you could gsub out the 
"pretty apostrophe" for the one tm recognizes.  Also note that this may be due 
to your use of word which automatically uses the "pretty apostrophe".  The 
default setting on MS word can be altered 
to alleviate this.#===
#using gsub
x <-  "I didn’t know!"x <- gsub("’", "'", 
x)removePunctuation(x)#===#You could make that into 
a function and apply it to the corpus with tm_map
exchanger <- function(x) gsub("’", "'", x)corp <- tm_map(corp, 
exchanger)#===

Cheers,Tyler
> Date: Fri, 27 Jan 2012 09:50:51 -0500
> From: frien...@yorku.ca
> To: r-help@r-project.org
> Subject: [R] tm package: handling contractions
>
> I tried making a wordcloud of Obama's State of the Union address using
> the tm package to process the text
>
> sotu <- scan(file="c:/R/data/sotu2012.txt", what="character")
> sotu <- tolower(sotu)
> corp <-Corpus(VectorSource(paste(sotu, collapse=" ")))
>
> corp <- tm_map(corp, removePunctuation)
> corp <- tm_map(corp, stemDocument)
> corp <- tm_map(corp, function(x)removeWords(x,stopwords()))
> tdm <- TermDocumentMatrix(corp)
> m <- as.matrix(tdm)
> v <- sort(rowSums(m),decreasing=TRUE)
> d <- data.frame(word = names(v),freq=v)
>
> wordcloud(d$word,d$freq)
>
> I ended up with a large number of contractions that were split at the
> "’" character, e.g., "don’t" --> "don'"
> e.g.,
>
> > sotu[grep("’", sotu)]
> [1] "qaeda’s" "taliban’s" "america’s" "they’re" "don’t"
> [6] "we’re" "aren’t" "we’ve" "patton’s" "what’s"
> [11] "let’s" "weren’t," "couldn’t" "people’s" "didn’t"
> [16] "we’ve" "we’ve" "we’ve" "i’m" "that’s"
> [21] "world’s" "what’s" "can’t" "that’s" "it’s"
> [26] "lock’s" "let’s" "you’re" "shouldn’t" "you’re"
> [31] "you’re" "it’s" "i’ll" "we’re" "don’t"
> [36] "we’ve" "it’s" "it’s" "it’s" "they’re"
> ...
> [201] "didn’t" "bush’s" "didn’t" "can’t" "there’s"
> [206] "i’m" "other’s" "we’re"
> >
>
> NB: What appears as the ' character above actually the character hex 92,
> not hex 27 on my Windows system.
>
> This should be a common problem in text processing, but I don't see a
> transformation in the tm package that
> handles this nicely. Is there something I've missed?
>
> -Michael
>
> --
> Michael Friendly Email: friendly AT yorku DOT ca
> Professor, Psychology Dept.
> York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street Web: http://www.datavis.ca
> Toronto, ONT M3J 1P3 CANADA
>
> __
> R-help@r-project.org mailing list
> 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
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] References for book "R In Action" by Kabacoff

2011-12-01 Thread Tyler Rinker

In the ebook version there is a list of references (pp. 434-437).

> Date: Thu, 1 Dec 2011 10:48:45 +0100
> From: lig...@statistik.tu-dortmund.de
> To: ravi.k...@gmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] References for book "R In Action" by Kabacoff
> 
> On 01.12.2011 10:10, Ravi Kulkarni wrote:
> > I know this is not really an R question - it is a query about a recent book
> > on R ("R In Action") by Robert Kabacoff, (Manning Publications 2011).
> > There are many references to interesting topics in R in the book, BUT, I do
> > not find a bibliography/list of references in the book!
> > Does anybody know if there are errata for the book available some place?
> 
> I'd ask the author!
> 
> Uwe Ligges
> 
> 
> 
> > Thanks,
> >Ravi
> >
> > --
> > View this message in context: 
> > http://r.789695.n4.nabble.com/References-for-book-R-In-Action-by-Kabacoff-tp4127625p4127625.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > __
> > R-help@r-project.org mailing list
> > 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
> 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
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] Problem creating reference manuals from latex

2011-11-15 Thread Tyler Rinker


 Duncan,

Thank you for your patience, time and expertise.  You were 100% correct and the 
problem has been resolved.  I'm adding what I did as a windows user to complete 
the list record for future searchers.
 
To download the inconsolata package (you may approach this several ways this 
one seemed easiest ot me) Go to the  command prompt and type:
 
mpm --verbose --install inconsolata
 
Thanks again Duncan!  I appreciate it.

Tyler
 

> Date: Tue, 15 Nov 2011 06:15:05 -0500
> From: murdoch.dun...@gmail.com
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] Problem creating reference manuals from latex
> 
> On 11-11-14 10:25 PM, Tyler Rinker wrote:
> >
> > Duncan,
> >
> > Thank you for your reply. I was not clear about the Internet access. I do 
> > have access, just at times I don't, hence the need to produce the manuals 
> > from latex rather than simply using the Internet.
> >
> > Please pardon my lack of knowledge around your response. You said I'd have 
> > to install the inconsolata.sty from CTAN. How? Is this installed in an R 
> > directory or a Tex directory? Do I use R to install it or latex or save the 
> > file and drop into a particular folder (directory)?
> 
> It is a TeX package. You need to use the MikTeX package installer to 
> install it.
> 
> I usually set up MikTeX to do this automatically when it needs a new 
> package, but that requires an available Internet connection; you'll need 
> to do something manually. Start in the Start Menu item for MikTeX 2.9, 
> and find the "package manager" item. Run it, and choose to install the 
> "inconsolata" package.
> 
> Duncan Murdoch
> 
> 
> > I've used rseek and a simple google search which reveals a great deal about 
> > inconsolata, unfortunately I am not grasping what I need to do.
> >
> > Tyler
> >
> >
> >
> >> Date: Mon, 14 Nov 2011 21:59:10 -0500
> >> From: murdoch.dun...@gmail.com
> >> To: tyler_rin...@hotmail.com
> >> CC: r-help@r-project.org
> >> Subject: Re: [R] Problem creating reference manuals from latex
> >>
> >> On 11-11-14 9:44 PM, Tyler Rinker wrote:
> >>>
> >>> R Community,
> >>>
> >>> I often am in need of viewing the reference manuals of packages and do 
> >>> not have Internet access. I have used the code:
> >>>
> >>> path<- find.package('tm')
> >>> system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
> >>> "Rd2pdf",shQuote(path)))
> >>>
> >>> someone kindly provided from this help list to generate the manuals from 
> >>> the latex files. This worked well with version R 2.13. After the upgrade 
> >>> to R 2.14 I use this code (see below and get an error message I don't 
> >>> understand). I'm pretty sure "! LaTeX Error: File `inconsolata.sty'" not 
> >>> found. is important but don't get it's significance. There's a post about 
> >>> it here: 
> >>> http://r.789695.n4.nabble.com/inconsolata-font-for-building-vignettes-with-R-devel-td3838176.html
> >>>  but I am a windows user making this a moot point. I know this file is n 
> >>> R font's file that Miktext needs to build the manual.
> >>>
> >>> I'd like to be able generate the reference manuals again without the 
> >>> Internet. While the code above worked in the past I'm open to alternative 
> >>> methods.
> >>
> >> You need to install the inconsolata.sty file. It is available on CTAN
> >> (the TeX network, not the R one). You say you don't have Internet
> >> access, so I don't know how you'll do this, but presumably there's a
> >> way: you got MikTex installed somehow.
> >>
> >> Duncan Murdoch
> >>
> >>>
> >>> Version: R 2.14.0 2011-10-31
> >>> OS: Windows 7
> >>> Latex: MikTex 2.9
> >>>
> >>> Thank you
> >>> Tyler Rinker
> >>>
> >>>
> >>>> path<- find.package('tm')
> >>>> system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
> >>>> "Rd2pdf",shQuote(path)))
> >>> Hmm ... looks like a package
> >>> Converting parsed Rd's to LaTeX ...
> >>> Creating pdf output from LaTeX ...
> >>> Warning: running command 
> >>> '

Re: [R] Problem creating reference manuals from latex

2011-11-14 Thread Tyler Rinker

Duncan,
 
Thank you for your reply.  I was not clear about the Internet access.  I do 
have access, just at times I don't, hence the need to produce the manuals from 
latex rather than simply using the Internet.
 
Please pardon my lack of knowledge around your response.  You said I'd have to 
install the inconsolata.sty from CTAN.  How?  Is this installed in an R 
directory or a Tex directory?  Do I use R to install it or latex or save the 
file and drop into a particular folder (directory)?
 
I've used rseek and a simple google search which reveals a great deal about 
inconsolata, unfortunately I am not grasping what I need to do.
 
Tyler

 

> Date: Mon, 14 Nov 2011 21:59:10 -0500
> From: murdoch.dun...@gmail.com
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] Problem creating reference manuals from latex
> 
> On 11-11-14 9:44 PM, Tyler Rinker wrote:
> >
> > R Community,
> >
> > I often am in need of viewing the reference manuals of packages and do not 
> > have Internet access. I have used the code:
> >
> > path<- find.package('tm')
> > system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
> > "Rd2pdf",shQuote(path)))
> >
> > someone kindly provided from this help list to generate the manuals from 
> > the latex files. This worked well with version R 2.13. After the upgrade to 
> > R 2.14 I use this code (see below and get an error message I don't 
> > understand). I'm pretty sure "! LaTeX Error: File `inconsolata.sty'" not 
> > found. is important but don't get it's significance. There's a post about 
> > it here: 
> > http://r.789695.n4.nabble.com/inconsolata-font-for-building-vignettes-with-R-devel-td3838176.html
> >  but I am a windows user making this a moot point. I know this file is n R 
> > font's file that Miktext needs to build the manual.
> >
> > I'd like to be able generate the reference manuals again without the 
> > Internet. While the code above worked in the past I'm open to alternative 
> > methods.
> 
> You need to install the inconsolata.sty file. It is available on CTAN 
> (the TeX network, not the R one). You say you don't have Internet 
> access, so I don't know how you'll do this, but presumably there's a 
> way: you got MikTex installed somehow.
> 
> Duncan Murdoch
> 
> >
> > Version: R 2.14.0 2011-10-31
> > OS: Windows 7
> > Latex: MikTex 2.9
> >
> > Thank you
> > Tyler Rinker
> >
> >
> >> path<- find.package('tm')
> >> system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
> >> "Rd2pdf",shQuote(path)))
> > Hmm ... looks like a package
> > Converting parsed Rd's to LaTeX ...
> > Creating pdf output from LaTeX ...
> > Warning: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" 
> > --pdf "Rd2.tex" -I "C:/PROGRA~1/R/R-214~1.0/share/texmf/tex/latex" -I 
> > "C:/PROGRA~1/R/R-214~1.0/share/texmf/bibtex/bst"' had status 1
> > Error : running 'texi2dvi' on 'Rd2.tex' failed
> > LaTeX errors:
> > ! LaTeX Error: File `inconsolata.sty' not found.
> > Type X to quit or to proceed,
> > or enter new name. (Default extension: sty)
> > ! Emergency stop.
> > 
> >
> > l.267
> >
> > ! ==> Fatal error occurred, no output PDF file produced!
> > Error in running tools::texi2dvi
> > Warning message:
> > running command '"C:/PROGRA~1/R/R-214~1.0/bin/i386/R" CMD Rd2pdf 
> > "C:/Users/Rinker/R/win-library/2.14/tm"' had status 1
> > 
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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
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] Problem creating reference manuals from latex

2011-11-14 Thread Tyler Rinker

R Community,
 
I often am in need of viewing the reference manuals of packages and do not have 
Internet access.  I have used the code:
 
path <- find.package('tm')
system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
"Rd2pdf",shQuote(path)))
 
someone kindly provided from this help list to generate the manuals from the 
latex files.  This worked well with version R 2.13.  After the upgrade to R 
2.14 I use this code (see below and get an error message I don't understand).  
I'm pretty sure "! LaTeX Error: File `inconsolata.sty'" not found. is important 
but don't get it's significance.  There's a post about it here: 
http://r.789695.n4.nabble.com/inconsolata-font-for-building-vignettes-with-R-devel-td3838176.html
  but I am a windows user making this a moot point.  I know this file is n R 
font's file that Miktext needs to build the manual.
 
I'd like to be able generate the reference manuals again without the Internet.  
While the code above worked in the past I'm open to alternative methods.
 
Version: R 2.14.0 2011-10-31
OS: Windows 7
Latex: MikTex 2.9
 
Thank you
Tyler Rinker

 
>  path <- find.package('tm')
>  system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
> "Rd2pdf",shQuote(path)))
Hmm ... looks like a package
Converting parsed Rd's to LaTeX ...
Creating pdf output from LaTeX ...
Warning: running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe"  
--pdf "Rd2.tex"  -I "C:/PROGRA~1/R/R-214~1.0/share/texmf/tex/latex" -I 
"C:/PROGRA~1/R/R-214~1.0/share/texmf/bibtex/bst"' had status 1
Error : running 'texi2dvi' on 'Rd2.tex' failed
LaTeX errors:
! LaTeX Error: File `inconsolata.sty' not found.
Type X to quit or  to proceed,
or enter new name. (Default extension: sty)
! Emergency stop.
 
 
l.267 
   
!  ==> Fatal error occurred, no output PDF file produced!
Error in running tools::texi2dvi
Warning message:
running command '"C:/PROGRA~1/R/R-214~1.0/bin/i386/R" CMD Rd2pdf 
"C:/Users/Rinker/R/win-library/2.14/tm"' had status 1 
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Rd2pdf error after 2.14 upgrade‏

2011-11-07 Thread Tyler Rinker

I have determined this is a MikTex problem and not an R problem.
 
I apoligize for the post.
 

> From: tyler_rin...@hotmail.com
> To: r-help@r-project.org
> Date: Mon, 7 Nov 2011 20:38:54 -0500
> Subject: [R] Rd2pdf error after 2.14 upgradeþ
> 
> 
> > The command Rd2pdf was rather useful for opening a package's manual
> > when you don't have access to the Internet (by using latex to pdf
> > conversion). However the way the function seems to operate changed at
> > version 2.14 of R. The noted changes listed on CRAN for this function
> > are as follows (which doesn't seem like it would affect my usage as
> > below):
> > 
> > #R CMD Rd2dvi without the --pdf option is now deprecated: only PDF output 
> > will be 
> > #supported in future releases (since this allows the use of fonts only 
> > #supported for PDF), and only R CMD Rd2pdf will be available. 
> > 
> > The way I used to open a package's pdf manual from latex file was as
> > follows:
> 
> (path <- find.package('plyr'))
> 
> system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
> "Rd2pdf",shQuote(path)))
> 
> > After version 2.14 R the same code now throws up the error:
> > 
> > Hmm ... looks like a package
> > Converting parsed Rd's to LaTeX 
> > Creating pdf output from LaTeX ...
> > Error in texi2dvi("Rd2.tex", pdf = (out_ext == "pdf"), quiet = FALSE, : 
> > pdflatex is not available
> > Error in running tools::texi2dvi
> > Warning message:
> > running command '"C:/PROGRA~1/R/R-214~1.0/bin/i386/R" CMD 
> > Rd2pdf "C:/Users/Rinker/R/win-library/2.14/plyr"' had status 1 
> > 
> > 
> > I'm running this from the R console. Any idea on what changes would
> > be needed to make this code work to generate a pdf from latex? I also
> > just downloaded the new miktex2.9 over 2.8. Not sure if this
> > information is relevant (I believe this is an R problem but don't know how 
> > to diagnosis this from the error). Usually, I can figure out the error 
> > message
> > but not this time.
> 
> R version 2.14.0 2011-10-31
> OS windows 7 
> [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] Rd2pdf error after 2.14 upgrade‏

2011-11-07 Thread Tyler Rinker

> The command Rd2pdf was rather useful for opening a package's manual
> when you don't have access to the Internet (by using latex to pdf
> conversion).  However the way the function seems to operate changed at
> version 2.14 of R.  The noted changes listed on CRAN for this function
> are as follows (which doesn't seem like it would affect my usage as
> below):
> 
> #R CMD Rd2dvi without the --pdf option is now deprecated: only PDF output 
> will be 
> #supported in future releases (since this allows the use of fonts only 
> #supported for  PDF), and only R CMD Rd2pdf will be available. 
> 
> The way I used to open a package's pdf manual from latex file was as
> follows:
 
 (path <- find.package('plyr'))
 
 system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
   "Rd2pdf",shQuote(path)))
 
> After version 2.14 R the same code now throws up the error:
> 
> Hmm ... looks like a package
> Converting parsed Rd's to LaTeX 
> Creating pdf output from LaTeX ...
> Error in texi2dvi("Rd2.tex", pdf = (out_ext == "pdf"), quiet = FALSE,  : 
> pdflatex is not available
> Error in running tools::texi2dvi
> Warning message:
> running command '"C:/PROGRA~1/R/R-214~1.0/bin/i386/R" CMD 
> Rd2pdf "C:/Users/Rinker/R/win-library/2.14/plyr"' had status 1 
> 
> 
> I'm running this from the R console.  Any idea on what changes would
> be needed to make this code work to generate a pdf from latex?  I also
> just downloaded the new miktex2.9 over 2.8.  Not sure if this
> information is relevant (I believe this is an R problem but don't know how to 
> diagnosis this from the error).  Usually, I can figure out the error message
> but not this time.
 
R version 2.14.0 2011-10-31
OS windows 7  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Summary stats in table

2011-10-23 Thread Tyler Rinker

I had to set it up as a data frame and then it workd beautifully with the 
reshape package.  
 
DF<-data.frame(A,B,x)
library(reshape)

cast(DF, A ~ B, fun.aggregate=mean, 
 margins=c("grand_row", "grand_col"))
 
Cheers
Tyler

> Date: Sun, 23 Oct 2011 14:39:08 -0400
> From: murdoch.dun...@gmail.com
> To: R-help@r-project.org
> Subject: [R] Summary stats in table
>
> Suppose I have data like this:
>
> A <- sample(letters[1:3], 1000, replace=TRUE)
> B <- sample(LETTERS[1:2], 1000, replace=TRUE)
> x <- rnorm(1000)
>
> I can get a table of means via
>
> tapply(x, list(A, B), mean)
>
> and I can add the marginal means to this using cbind/rbind:
>
> main <- tapply(x, list(A,B), mean)
> Amargin <- tapply(x, list(A), mean)
> Bmargin <- tapply(x, list(B), mean)
>
> rbind(cbind(main, all=Amargin),all=c(Bmargin, mean(x)))
>
> But this is tedious. Has some package got some code that makes this easier?
>
> Duncan Murdoch
>
> __
> R-help@r-project.org mailing list
> 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
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] summarizing a data frame i.e. count -> group by

2011-10-23 Thread Tyler Rinker

This could be done with aggregate but I am unfamiliar with it so I'll give what 
I think you want from your message using the library 'reshape' that you'll have 
to doneload.  If you're problem is large the data.table library would be much 
faster.
 
You haven't really said what you'd like to get from the output so I'm going by 
what your code looks like you want. There is no count in R, the function is 
called length (you may want sum but it does not appear that way).  Also giving 
the list a bit of what you'd expect for an out put is often helpful.
 
Here is the code(one of these three options is what you want I think:
 
library(reshape)
throughput1 <- cast(df, time~partitioning_mode, value="runtime",  length)
throughput2 <- cast(df, partitioning_mode~time, value="runtime",  length)
throughput3 <- cast(df, partitioning_mode + workload~time, value="runtime", 
length)


> From: brave...@gmail.com
> Date: Sun, 23 Oct 2011 19:29:40 +0200
> To: r-help@r-project.org
> Subject: [R] summarizing a data frame i.e. count -> group by
>
> Hello,
>
> This is one problem at the time :)
>
> I have a data frame df that looks like this:
>
> time partitioning_mode workload runtime
> 1 1 sharding query 607
> 2 1 sharding query 85
> 3 1 sharding query 52
> 4 1 sharding query 79
> 5 1 sharding query 77
> 6 1 sharding query 67
> 7 1 sharding query 98
> 8 1 sharding refresh 2932
> 9 1 sharding refresh 2870
> 10 1 sharding refresh 2877
> 11 1 sharding refresh 2868
> 12 1 replication query 2891
> 13 1 replication query 2907
> 14 1 replication query 2922
> 15 1 replication query 2937
>
> and if I could use SQL ... omg! I really wish I could! I would do exactly 
> this:
>
> insert into throughput
> select time, partitioning_mode, count(*)
> from data.frame
> group by time, partitioning_mode
>
> My attempted R versions are wrong and produce very cryptic error message:
>
> > throughput <- aggregate(x=df[,c("time", "partitioning_mode")], 
> > by=list(df$time,df$partitioning_mode), count)
> Error in `[.default`(df2, u_id, , drop = FALSE) :
> incorrect number of dimensions
>
> > throughput <- aggregate(x=df, by=list(df$time,df$partitioning_mode), count)
> Error in `[.default`(df2, u_id, , drop = FALSE) :
> incorrect number of dimensions
>
> >throughput <- tapply(X=df$time, INDEX=list(df$time,df$partitioning), 
> >FUN=count)
> I cant comprehend what comes out from this one ... :(
>
> and I thought C++ template errors were the most cryptic ;P
>
> Many many thanks in advance,
> Best regards,
> Giovanni
> __
> R-help@r-project.org mailing list
> 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
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] Expanding rows of a data frame into multiple rows

2011-10-22 Thread Tyler Rinker


To further  Weidong Gu's suggestion merge would give you what you want but not 
the numeric column corresponding to the sector.  Adding that would be easy 
enough via transform if you really desired it.
 
Tyler

 
obs.l<-sapply(input$observations,length) 
desire.output<-data.frame(site=rep(1:6,obs.l),obs=unlist(input$observations))
merge(input[,-3], desire.output, all.x=TRUE)

> Date: Sat, 22 Oct 2011 20:34:04 -0400
> From: anopheles...@gmail.com
> To: peter.meilst...@gmail.com
> CC: r-help@r-project.org; manipul...@googlegroups.com
> Subject: Re: [R] Expanding rows of a data frame into multiple rows
>
> This may work
>
> obs.l<-sapply(input$observations,length)
>
> desire.output<-data.frame(site=rep(1:6,obs.l),obs=unlist(input$observations))
>
> Weidong Gu
>
> On Sat, Oct 22, 2011 at 7:51 PM, Peter Meilstrup
>  wrote:
> > The setup: I have a data frame where one column is in list mode, and
> > each entry contains a vector of varying length.
> > I want to expand this into a data frame with one row for each member
> > of the list-mode column (the other values being replicated)
> >
> > For example, an example input and the desired output would be:
> >
> > input <- data.frame(site = 1:6,
> > sector = factor(c("north", "south", "east",
> > "west", "east", "south")),
> > observations =
> > I(list(c(1,2,3),c(4,3),c(),c(14,12,53,2,4),c(3),c(23
> >
> > desired.output <-
> > data.frame(site = c(1,1,1,2,2,4,4,4,4,5,6),
> > sector = factor(c(2,2,2,3,3,4,4,4,4,4,1,3),
> > labels = c("east", "north", "south", "west")),
> > observations = c(1,2,3,4,3,14,12,53,2,4,3,23))
> >
> > There seems like there ought to be a good (simple, fast) way to do
> > this, but I've been struggling. Any ideas?
> >
> > __
> > R-help@r-project.org mailing list
> > 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
> 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
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] Square ended segments

2011-10-19 Thread Tyler Rinker



Sarah,
 
Thank you very much.  I apoligize for the way the code came through.  I'm not 
sure whay it was formatted that way.  
 
You were 100% correct about the lend=2.  Thank you.  I don't know why i didn't 
think to look at par.  I was thinking the argument had to be from segments.  It 
even says "... further graphical parameters (from par)" right in the help page 
for ?segments.  I apoligize for this oversight and appreciate your response 
anyway.

Tyler Rinker
 
 
> Date: Wed, 19 Oct 2011 17:34:27 -0400
> Subject: Re: [R] Square ended segments
> From: sarah.gos...@gmail.com
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> 
> Hi Tyler,
> 
> Your code is unreadable, but take a look at ?par and search for lend.
> 
> ?par is the first place to look for all base graphics settings.
> 
> Sarah
> 
> On Wed, Oct 19, 2011 at 5:26 PM, Tyler Rinker  
> wrote:
> >
> > Good Afternoon R Community,
> >  I am working on plotting behavior codes over short durations of time (a 
> > few seconds at a time over 1-2 hrs).  I am utilizing as.POSIXct to store 
> > the time.  I wanted to make a quasi time line using these time.  I utilized 
> > the segments function to represent these times.  However the segments 
> > rounds off at the ends and does not have the crisp look I need for my 
> > purposes.  I then used a "squared" point(pch=15)at the beginning and end of 
> > each of these segments to make it square.  It looks like I want it to now 
> > but the point is centered over the ends of the segments meaning the 
> > segments get extended a bit in each direction.  This distorts a segment 
> > that is only a few seconds long.
> > How can I make nice squared end  segments roughly lwd=6 and be accurate 
> > with the segment's begining and end point.
> >
> > I've included the code in this email and in a pastebin link:Link to the 
> > pastebin code:  http://pastebin.com/raw.php?i=LYnZh1VD OS: win 7 R ver: 
> > 2.14 build  XX<-structure(list(ID = structure(1:7, .Label = c("a", "b", 
> > "c", "d", "e", "f", "g"), class = "factor"), X1 = structure(1:7, .Label = 
> > c("A", "B", "C", "D", "E", "F", "G"), class = "factor"), Code.begin = 
> > structure(c(1318996823, 1318997163, NA, 1318997842, NA, 1319000172, 
> > 1319001123), class = c("POSIXct", "POSIXt"), tzone = ""), Code.end = 
> > structure(c(1318996828, 1318997168, NA, 1318997884, NA, 1319000229, 
> > 1319001142), class = c("POSIXct", "POSIXt"), tzone = ""), Code2.begin = 
> > structure(c(1318996823, 1318997163, NA, 1318997842, 1318997962, NA, 
> > 1319001123), class = c("POSIXct", "POSIXt"), tzone = ""), Code2.end = 
> > structure(c(1318996828, 1318997168, NA, 1318997884, 1318998120, NA, 
> > 1319001142), class = c("POSIXct", "POSIXt"), tzone = "")), .Names = c("ID", 
> > "X1", "Code.begin", "Code.end", "Code2.begin", "Code2.end"), row.n!
 ames!
> >  = c(NA, -7L), class = "data.frame") x <- 
> > as.POSIXct(paste(substr(Sys.time(), 1, 10), "00:00:00", sep=" "))Start <- 
> > rep(x, ncol(XX))a <- as.vector(na.omit(difftime(XX$Code.begin, x, 
> > units="secs")))b <- as.vector(na.omit(difftime(XX$Code.end, x, 
> > units="secs")))d1<-substr(as.character(x),1,10)d <- seq(x, 
> > as.POSIXct(paste(d1," 01:20:00 EDT", sep="")), by=150 )e <- 
> > 0:(length(d)-1)f <- na.omit(XX$Code.end)g <- paste(a, ", ", "27, ", b, ", 
> > ", "27", sep="")r <- c(x, as.POSIXct(paste(d1," 01:20:00 EDT", sep=""))) 
> > x11(15,3)##plot(d, e, type="n", 
> > xlab="",ylab="", axes=FALSE, xaxs = "i")axis.POSIXct(1, at=seq(r[1], r[2], 
> > by="mins"), format="%H:%M:%S", tcl = -1, tick=FALSE)  #tcl = 
> > -0.2axis.POSIXct(1, at=seq(r[1], r[2], by=360), tcl = -1.1, labels = 
> > FALSE)#, lwd=2) axis.POSIXct(1, at=seq(r[1], r[2], by=60), tcl = -.7, 
> > labels = FALSE) axis.POSIXct(1, at=seq(r[1], r[2], by=15), tcl = -.35, 
> > labels = FALSE) title(main="Codes Over Time of Transcript",x!
 lab!
> >  ="Transcript Time (min)", ylab="Codes") par(yaxt="n")lablist.y<-as.vec
> > tor(c("Code 1", "Code 2", "Code 3"))axis(2, at=seq(2, 27, length=3), labels 
> > = FALSE)text(y = seq(2, 27, length=3), par("usr")[1], labels = lablist.y, 
> > srt = 35, pos = 2, xpd = TRUE) grid(nx=80, ny=3, lty="solid", 
> > col="gray90")box() segments(XX$Code.begin,27, XX$Code.end, 27, lwd=6, 
> > lty="solid", col="black")points(c(XX$Code.begin, XX$Code.end), rep(27, 14), 
> > pch=15, cex=.83)
> >
> >
> >
> 
> 
> 
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Square ended segments

2011-10-19 Thread Tyler Rinker

Good Afternoon R Community,
 I am working on plotting behavior codes over short durations of time (a few 
seconds at a time over 1-2 hrs).  I am utilizing as.POSIXct to store the time.  
I wanted to make a quasi time line using these time.  I utilized the segments 
function to represent these times.  However the segments rounds off at the ends 
and does not have the crisp look I need for my purposes.  I then used a 
"squared" point(pch=15)at the beginning and end of each of these segments to 
make it square.  It looks like I want it to now but the point is centered over 
the ends of the segments meaning the segments get extended a bit in each 
direction.  This distorts a segment that is only a few seconds long. 
How can I make nice squared end  segments roughly lwd=6 and be accurate with 
the segment's begining and end point.
 
I've included the code in this email and in a pastebin link:Link to the 
pastebin code:  http://pastebin.com/raw.php?i=LYnZh1VD OS: win 7 R ver: 2.14 
build  XX<-structure(list(ID = structure(1:7, .Label = c("a", "b", "c", "d", 
"e", "f", "g"), class = "factor"), X1 = structure(1:7, .Label = c("A", "B", 
"C", "D", "E", "F", "G"), class = "factor"), Code.begin = 
structure(c(1318996823, 1318997163, NA, 1318997842, NA, 1319000172, 
1319001123), class = c("POSIXct", "POSIXt"), tzone = ""), Code.end = 
structure(c(1318996828, 1318997168, NA, 1318997884, NA, 1319000229, 
1319001142), class = c("POSIXct", "POSIXt"), tzone = ""), Code2.begin = 
structure(c(1318996823, 1318997163, NA, 1318997842, 1318997962, NA, 
1319001123), class = c("POSIXct", "POSIXt"), tzone = ""), Code2.end = 
structure(c(1318996828, 1318997168, NA, 1318997884, 1318998120, NA, 
1319001142), class = c("POSIXct", "POSIXt"), tzone = "")), .Names = c("ID", 
"X1", "Code.begin", "Code.end", "Code2.begin", "Code2.end"), row.names!
  = c(NA, -7L), class = "data.frame") x <- as.POSIXct(paste(substr(Sys.time(), 
1, 10), "00:00:00", sep=" "))Start <- rep(x, ncol(XX))a <- 
as.vector(na.omit(difftime(XX$Code.begin, x, units="secs")))b <- 
as.vector(na.omit(difftime(XX$Code.end, x, 
units="secs")))d1<-substr(as.character(x),1,10)d <- seq(x, 
as.POSIXct(paste(d1," 01:20:00 EDT", sep="")), by=150 )e <- 0:(length(d)-1)f <- 
na.omit(XX$Code.end)g <- paste(a, ", ", "27, ", b, ", ", "27", sep="")r <- c(x, 
as.POSIXct(paste(d1," 01:20:00 EDT", sep=""))) 
x11(15,3)##plot(d, e, type="n", 
xlab="",ylab="", axes=FALSE, xaxs = "i")axis.POSIXct(1, at=seq(r[1], r[2], 
by="mins"), format="%H:%M:%S", tcl = -1, tick=FALSE)  #tcl = 
-0.2axis.POSIXct(1, at=seq(r[1], r[2], by=360), tcl = -1.1, labels = FALSE)#, 
lwd=2) axis.POSIXct(1, at=seq(r[1], r[2], by=60), tcl = -.7, labels = FALSE) 
axis.POSIXct(1, at=seq(r[1], r[2], by=15), tcl = -.35, labels = FALSE) 
title(main="Codes Over Time of Transcript",xlab!
 ="Transcript Time (min)", ylab="Codes") par(yaxt="n")lablist.y<-as.vec
tor(c("Code 1", "Code 2", "Code 3"))axis(2, at=seq(2, 27, length=3), labels = 
FALSE)text(y = seq(2, 27, length=3), par("usr")[1], labels = lablist.y, srt = 
35, pos = 2, xpd = TRUE) grid(nx=80, ny=3, lty="solid", col="gray90")box() 
segments(XX$Code.begin,27, XX$Code.end, 27, lwd=6, lty="solid", 
col="black")points(c(XX$Code.begin, XX$Code.end), rep(27, 14), pch=15, cex=.83)
 
 
 
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Import in R with White Spaces

2011-10-03 Thread Tyler Rinker

I use the following function I stole somewhere.  There's probably better ways.
 
white <- function(x){
x <- as.data.frame(x)
W <- function(x) gsub(" +", "", x)
sapply(x,W)
}

#EXAPLE
dat <- paste(letters," ", " ", LETTERS)
(DAT <- data.frame(dat, dat))   #nasty white spaces
white(DAT)   #white spaces gone
 
 
Tyler
 

> Date: Mon, 3 Oct 2011 08:14:27 -0700
> From: francy.casal...@gmail.com
> To: r-help@r-project.org
> Subject: [R] Import in R with White Spaces
> 
> Hi,
> 
> I have a simple question about importing data, I would be very grateful if
> you could help me out.
> 
> I have used read.csv(file name, header=T, sep=",") to bring in a csv file I
> saved in MS Excel.The problem is I have white spaces in the middle of values
> (not in the column names), and this messes up the column entries. Since I
> have many many files that I am importing and I have spaces in all of them, I
> was looking for a way to avoid going into all of them and changing the white
> spaec to, for example, an underscore.
> Can you suggest whether there is a way to tell R that each element delimited
> by "," is actually a different entry, regardless of whether there are white
> spaces in between?
> 
> Thank you so much for the help!
> -f
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Import-in-R-with-White-Spaces-tp3867799p3867799.html
> Sent from the R help mailing list archive at Nabble.com.
> [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] R help on write.csv

2011-09-21 Thread Tyler Rinker

You haven't followed the rules of the posting guide.  No reproducible code.  No 
OS or R version.  I'm guessing you are a newer R user and didn't know this.  So 
please read that guide.  It'll help others to help you more quickly.
 
If you're new you may not know about using ?object.  So if you type 
"?write.csv" into the r console it will take you to a help page.  There you 
will see info about the object and in this case append is what you will most 
likely want to look at.
 
Tyler

 

> From: ashish.ku...@esteeadvisors.com
> To: r-help@r-project.org
> Date: Wed, 21 Sep 2011 17:31:01 +0530
> Subject: [R] R help on write.csv
> 
> Hi,
> 
> 
> 
> I wanted to write the data created using R on existing csv file. However
> everytime I use write.csv, it overwrites the values already there in the
> existing csv file. Any workaround on this. 
> 
> 
> 
> Thanks for your help
> 
> 
> 
> Ashish Kumar
> 
> 
> 
> Estee Advisors Pvt. Ltd.
> 
> Email: ashish.ku...@esteeadvisors.com
> 
> Cell: +91-9654072144
> 
> Direct: +91-124-4637-713
> 
> 
> 
> 
> [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] Package dependency

2011-09-20 Thread Tyler Rinker

Greetings R community,
 
I am making my first package and have run into the need to use other packages.  
I  pass all the checks in the command prompt running Rcmd check package.name.  
In the Description file I have included:
 
Depends: R (>= 2.13), plotrix
Repository: CRAN
 
Now I create the zip file for windows 7.  I delete my plotrix package from my 
library to create a setup where others might encounter when installing my 
package (perhaps they don't have the package dependency plotrix installed).  I 
now install the zip file in my R library and try to load it in R generating the 
following error:
 
> library(genTools)
Loading required package: plotrix
Error: package ‘plotrix’ could not be loaded
In addition: Warning message:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = 
lib.loc) :
  there is no package called ‘plotrix’
 
Now the question:  How do I get my package to automatically download 
dependencies from CRAN as other CRAN packages do when I install them to my 
library for the first time?
 
Tyler Rinker
 
R version 2.14 (beta)   
Windows 7 
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] url prep function (backslash issue)

2011-08-30 Thread Tyler Rinker

Duncan, Thanks.  Combined with what Brian Ripley wrote it all works.   For 
future thread searchers this worked: oldstring <- readline()
C:\Users\Rinker\Desktop\Research& Law\Data\School Data 09-10
chartr("\\", "/",oldstring) Thank you both,Tyler
 #> Date: Tue, 30 Aug 2011 09:35:58 
-0400
> From: murdoch.dun...@gmail.com
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] url prep function (backslash issue)
> 
> Brian Ripley told you how to do the translation, but there's another 
> problem:
> 
> On 30/08/2011 8:14 AM, Tyler Rinker wrote:
> 
> [ much deleted ]
> > When I try
> > the function the backslash gets me again:
> >
> > >
> > readyPath("C:\Users\Rinker\Desktop\Research&  Law\Data\School Data
> > 09-10")
> 
> The problem is that you haven't entered a string containing backslashes, 
> you've tried to enter a string containing escapes.  The parser sees a 
> single backslash and attaches it to the next letter, so \U is taken to 
> be the start of a Unicode character, and you get the error
> > Error: '\U' used without hex digits in character string starting
> > "C:\U"
> >
> 
> The way around this is to avoid the parser, by something like this:
> 
> oldstring <- readline()
> 
> C:\Users\Rinker\Desktop\Research&  Law\Data\School Data 09-10
> 
> 
> and then applying chartr to oldstring.
> 
> Duncan Murdoch
> 
> 
> > This is
> > what I'd like the function to return:
> >
> > [1]
> > "C:/Users/Rinker/Desktop/Research&  Law/Data/School Data 09-10"
> >
> > I want a
> > function in which I enter a path and it returns the path with backslashes
> >
> > replaced
> > with forward slashes. Is there a way to make a function to do this?
> >
> > Windows 7
> > user
> >
> > R version
> > 2.14 beta
> >
> > Thank you,
> >
> > Tyler
> > Rinker
> >
> >
> >
> > 
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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
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] url prep function (backslash issue)

2011-08-30 Thread Tyler Rinker

Thank you Brian. When I wrote the email I typed url into the subject line by 
accident.  I mean path.   Thank you,Tyler

 > Date: Tue, 30 Aug 2011 14:00:22 +0100
> From: rip...@stats.ox.ac.uk
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] url prep function (backslash issue)
> 
> You seem to be looking for chartr("\\", "/", path) (and FAQ Q7.8)
> 
> What does any of this have to do with 'url prep': URLs are never 
> written with backslashes?
> 
> On Tue, 30 Aug 2011, Tyler Rinker wrote:
> 
> >
> >
> >
> > Greeting R
> > Community,
> >
> > I am a
> > windows user so this problem may be specific to windows. I often want to 
> > source
> > files from within R
> >
> > such as:
> > C:\Users\Rinker\Desktop\Research & Law\Data\School Data 09-10. To source
> > this file I need to go
> >
> > through the
> > path and replace all the backslashes (\) with forward slashes (/). I 
> > usually do
> > this in MS Word
> >
> > using the
> > replace option, however, I'd like to do this in R. Attempting to write a
> > function to do this runs into
> >
> > problems:
> >
> > When I
> > enter the following:
> >
> > readyPath
> > <- function(path){
> >
> > z <- gsub("\", "/", path)
> >
> > return(z)
> >
> > }
> >
> > I get:
> >
> >>
> > readyPath <- function(path){
> >
> > + z <- gsub("\", "/", path)
> >
> > + return(z)
> >
> > + }
> >
> > +
> >
> > ...meaning
> > R can't close the sequence (presumably because of the backslash which has
> > special meaning).
> >
> > So I tried
> > (\\):
> >
> >
> >
> > readyPath <- function(path){
> >
> > z <- gsub("\\", "/", path)
> >
> > return(z)
> >
> > }This allows
> > the function to be stored as an object but I'm not sure if this is correct.
> 
> It isn't: please do read the help for gsub (\ is a metacharacter).
> 
> > When I try
> > the function the backslash gets me again:
> >
> >>
> > readyPath("C:\Users\Rinker\Desktop\Research & Law\Data\School Data
> > 09-10")
> >
> > Error: '\U' used without hex digits in character string starting
> > "C:\U"
> 
> You cannot do that: you have to scan a file or escape \
> 
> > This is
> > what I'd like the function to return:
> >
> > [1]
> > "C:/Users/Rinker/Desktop/Research & Law/Data/School Data 09-10"
> >
> > I want a
> > function in which I enter a path and it returns the path with backslashes
> >
> > replaced
> > with forward slashes. Is there a way to make a function to do this?
> 
> ?normalizePath
> chartr("\\", "/", path)
> 
> > Windows 7
> > user
> >
> > R version
> > 2.14 beta
> >
> > Thank you,
> >
> > Tyler
> > Rinker
> >
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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.
> >
> 
> -- 
> Brian D. Ripley,  rip...@stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel:  +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UKFax:  +44 1865 272595
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] url prep function (backslash issue)

2011-08-30 Thread Tyler Rinker



Greeting R
Community, 

I am a
windows user so this problem may be specific to windows. I often want to source
files from within R 

such as:
C:\Users\Rinker\Desktop\Research & Law\Data\School Data 09-10. To source
this file I need to go 

through the
path and replace all the backslashes (\) with forward slashes (/). I usually do
this in MS Word

using the
replace option, however, I'd like to do this in R. Attempting to write a
function to do this runs into 

problems: 

When I
enter the following:

readyPath
<- function(path){

z <- gsub("\", "/", path)

return(z)

} 

I get:

>
readyPath <- function(path){

+ z <- gsub("\", "/", path)

+ return(z)

+ }

+  

...meaning
R can't close the sequence (presumably because of the backslash which has
special meaning).

So I tried
(\\):



readyPath <- function(path){

z <- gsub("\\", "/", path)

return(z)

}This allows
the function to be stored as an object but I'm not sure if this is correct.

When I try
the function the backslash gets me again: 

>
readyPath("C:\Users\Rinker\Desktop\Research & Law\Data\School Data
09-10")

Error: '\U' used without hex digits in character string starting
"C:\U" 

This is
what I'd like the function to return:

[1]
"C:/Users/Rinker/Desktop/Research & Law/Data/School Data 09-10" 

I want a
function in which I enter a path and it returns the path with backslashes 

replaced
with forward slashes. Is there a way to make a function to do this? 

Windows 7
user

R version
2.14 beta 

Thank you,

Tyler
Rinker

 

  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Make a function work on an environemnt

2011-08-27 Thread Tyler Rinker

Michael, Michael wrote: "However, this certainly isn't the most useful code 
because it clears itself..." If you were to put this code in a package, .Rdata 
file, or .First() script it could be recalled in that way.  So it could serve a 
purpose.  The exercise was more about me learning how to apply the function to 
global environment though.  You were certainly helpful there.  


 From: michael.weyla...@gmail.com
Date: Sat, 27 Aug 2011 12:01:02 -0400
Subject: Re: [R] Make a function work on an environemnt
To: tyler_rin...@hotmail.com
CC: r-help@r-project.org

Well, here's one way you could do it: 

# Don't run this unless you really mean it
clear <- function(){rm(list=ls(.GlobalEnv), envir = .GlobalEnv)}

Both calls to .GlobalEnv seem necessary so that both rm() and ls() go 
everywhere with it. However, this certainly isn't the most useful code because 
it clears itself...



I'm not the best with environments so I'll let someone else work out the 
problems with your other attempts, but I believe the problem with the first is 
that it only executes inside the function environment and not the global 
environment. Not sure about the second...



Michael Weylandt


On Sat, Aug 27, 2011 at 9:25 AM, Tyler Rinker  wrote:




A previous attempt at this question resulted in the message running together, 
making the message difficult to read and the code lines hard to distinquinsh. 
In my R learning I've come across a situation in which a piece of code that 
works on the work space outside a function does not work inside the function. 
WARNING THIS EMAIL CONTAINES THE CODE:#rm(list=ls()) THIS WILL CLEAR ALL 
OBJECTS FROM YOUR WORKSPACE! When I use rm(list=ls()) and then ls() it shows 
character(0) So I tried to make a quick function to speed this up as follows:





#

#ATTEMPT 1

#

clear <- function()rm(list=ls())clear()

ls()  #all objects are still attached

#

#ATTEMPT 2

#

clear <- function(){

{CLEAR <- function()rm(list=ls())}

eapply(globalenv(),CLEAR)

}clear()ls()

#

#ERROR MESSAGE FRPM ATTEMPT 2

#

 clear()

Error in FUN(list(function (x)  : unused argument(s) (list(function (x)



QUESTIONS:Why does this code not work inside the function?  Please critique 
both my attempts.

What would I need to do to make the pieces of code work inside the function?

Windows 7

R version 2.14 beta



Thanks in advance,

Tyler Rinker





[[alternative HTML version deleted]]



__

R-help@r-project.org mailing list

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
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] Make a function work on an environemnt

2011-08-27 Thread Tyler Rinker


 Michael, Thank you for that information.  It was very insightful.   Anyone 
else with why my second attempt does not work (using eapply)? ThanksTylerFrom: 
michael.weyla...@gmail.com
Date: Sat, 27 Aug 2011 12:01:02 -0400
Subject: Re: [R] Make a function work on an environemnt
To: tyler_rin...@hotmail.com
CC: r-help@r-project.org

Well, here's one way you could do it: 

# Don't run this unless you really mean it
clear <- function(){rm(list=ls(.GlobalEnv), envir = .GlobalEnv)}

Both calls to .GlobalEnv seem necessary so that both rm() and ls() go 
everywhere with it. However, this certainly isn't the most useful code because 
it clears itself...



I'm not the best with environments so I'll let someone else work out the 
problems with your other attempts, but I believe the problem with the first is 
that it only executes inside the function environment and not the global 
environment. Not sure about the second...



Michael Weylandt


On Sat, Aug 27, 2011 at 9:25 AM, Tyler Rinker  wrote:




A previous attempt at this question resulted in the message running together, 
making the message difficult to read and the code lines hard to distinquinsh. 
In my R learning I've come across a situation in which a piece of code that 
works on the work space outside a function does not work inside the function. 
WARNING THIS EMAIL CONTAINES THE CODE:#rm(list=ls()) THIS WILL CLEAR ALL 
OBJECTS FROM YOUR WORKSPACE! When I use rm(list=ls()) and then ls() it shows 
character(0) So I tried to make a quick function to speed this up as follows:





#

#ATTEMPT 1

#

clear <- function()rm(list=ls())clear()

ls()  #all objects are still attached

#

#ATTEMPT 2

#

clear <- function(){

{CLEAR <- function()rm(list=ls())}

eapply(globalenv(),CLEAR)

}clear()ls()

#

#ERROR MESSAGE FRPM ATTEMPT 2

#

 clear()

Error in FUN(list(function (x)  : unused argument(s) (list(function (x)



QUESTIONS:Why does this code not work inside the function?  Please critique 
both my attempts.

What would I need to do to make the pieces of code work inside the function?

Windows 7

R version 2.14 beta



Thanks in advance,

Tyler Rinker





[[alternative HTML version deleted]]



__

R-help@r-project.org mailing list

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
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] Make a function work on an environemnt

2011-08-27 Thread Tyler Rinker

A previous attempt at this question resulted in the message running together, 
making the message difficult to read and the code lines hard to distinquinsh. 
In my R learning I've come across a situation in which a piece of code that 
works on the work space outside a function does not work inside the function. 
WARNING THIS EMAIL CONTAINES THE CODE:#rm(list=ls()) THIS WILL CLEAR ALL 
OBJECTS FROM YOUR WORKSPACE! When I use rm(list=ls()) and then ls() it shows 
character(0) So I tried to make a quick function to speed this up as follows: 
 
#
#ATTEMPT 1
#
clear <- function()rm(list=ls())clear()
ls()  #all objects are still attached
#
#ATTEMPT 2
#
clear <- function(){
{CLEAR <- function()rm(list=ls())}
eapply(globalenv(),CLEAR)
}clear()ls()
#
#ERROR MESSAGE FRPM ATTEMPT 2
#
 clear()
Error in FUN(list(function (x)  : unused argument(s) (list(function (x) 
 
QUESTIONS:Why does this code not work inside the function?  Please critique 
both my attempts.
What would I need to do to make the pieces of code work inside the function? 
Windows 7
R version 2.14 beta 
 
Thanks in advance,
Tyler Rinker

  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Make a function work on an environemnt

2011-08-26 Thread Tyler Rinker

In my R learning I've come across a situation in which a piece of code that 
works on the work space outside a function does not work inside the function. 
WARNING THIS EMAIL CONTAINES THE CODE:#rm(list=ls()) THIS WILL CLEAR ALL 
OBJECTS FROM YOUR WORKSPACE! When I use rm(list=ls()) and then ls() it shows 
character(0) So I tried to make a quick function to speed this up as follows: 
#
#ATTEMPT 1
#
clear <- function()rm(list=ls())clear()ls()  #all objects are still attached
#
#ATTEMPT 2
#
clear <- function(){
{CLEAR <- function()rm(list=ls())}
eapply(globalenv(),CLEAR)
}clear()ls()
#
#ERROR MESSAGE FRPM ATTEMPT 2
#
> clear()
Error in FUN(list(function (x)  : unused argument(s) (list(function (x) 
QUESTIONS:Why does this code not work inside the function?  Please critique 
both my attempts?What would I need to do to make the pieces of code work inside 
the function? Windows 7R 2.14 beta Thanks in advance,Tyler Rinker   
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Construct a File Path: File Path Unknown

2011-08-25 Thread Tyler Rinker


 Bill, Thank you very much!  That's very fast.  Exactly what I was looking for. 
 Jean thank you for your response as well. Tyler> From: wdun...@tibco.com
> To: tyler_rin...@hotmail.com; jvad...@usgs.gov
> CC: r-help@r-project.org
> Subject: RE: [R] Construct a File Path: File Path Unknown
> Date: Thu, 25 Aug 2011 20:25:15 +
> 
> Try using normalizePath("foo.pdf") after creating
> the file.  It should return an absolute path to
> an existing file.
> 
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com 
> 
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> > Behalf Of Tyler Rinker
> > Sent: Thursday, August 25, 2011 12:43 PM
> > To: jvad...@usgs.gov
> > Cc: r-help@r-project.org
> > Subject: Re: [R] Construct a File Path: File Path Unknown
> > 
> > 
> > Jean, Thank you.  It's slow but it works. dir("C:/", pattern="plotrix.pdf", 
> > full.names=T,
> > ignore.case=T, recursive=T)   Does anyone have a faster way? If it helps 
> > using:
> > shell.exec("search-ms://query=plotrix.pdf")utilizes windows's search 
> > bar to find the file (this is
> > quick), however it opens a screen that finds the file rather than providing 
> > me with the search path.
> > For a look at what that looks like on a windows machine click here: 
> > http://windows.microsoft.com/en-
> > US/windows7/products/features/windows-search I'm thinking there's a way to 
> > use this method to extract
> > the path even faster than dir(). TylerTo: tyler_rin...@hotmail.com
> > CC: r-help@r-project.org
> > Subject: Re: [R] Construct a File Path: File Path Unknown
> > From: jvad...@usgs.gov
> > Date: Thu, 25 Aug 2011 13:19:37 -0500
> > 
> > 
> > 
> > Try the dir() function.
> > 
> > 
> > 
> > ?dir
> > 
> > 
> > 
> > # for example
> > 
> > dir("c:/", pattern="foo.pdf",
> > full.names=T, ignore.case=T, recursive=T)
> > 
> > 
> > 
> > Jean
> > 
> > 
> > 
> > 
> > 
> > Tyler Rinker wrote on 08/25/2011 11:54:28 AM:
> > 
> > >
> > 
> > > I am not a programmer and am self-taught so I may lack the
> > 
> > > language to ask this appropriately (perhaps why an rseek search was
> > 
> > 
> > > unfruitful).
> > 
> > >
> > 
> > > Let's say I saved a file to my desktop called foo.pdf.  Then
> > I want
> > 
> > > R to return the file path of
> > 
> > > foo.pdf (pretend I don't know the location(path) of foo.pdf).
> > 
> > >
> > 
> > > Question: How would I get R to return the unknown file path for
> > 
> > > foo.pdf.
> > 
> > >
> > 
> > > I hypothesize that the find find.package() function code contains
> > 
> > > the secret for doing this but am unable to parse out the snippet to
> > do so.
> > 
> > >
> > 
> > > I attempted file.path("foo.pdf")
> > 
> > >
> > 
> > > which R returns [1] "foo.pdf"  #not what I want
> > 
> > >
> > 
> > > ===
> > 
> > >
> > 
> > > R version 2.14 beta
> > 
> > >
> > 
> > > Windows 7
> > 
> > >
> > 
> > > Reproducible code is not appropriate for this query
> > 
> > >
> > 
> > > __
> > 
> > > R-help@r-project.org mailing list
> > 
> > > 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
> > 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
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] Construct a File Path: File Path Unknown

2011-08-25 Thread Tyler Rinker

Jean, Thank you.  It's slow but it works. dir("C:/", pattern="plotrix.pdf", 
full.names=T, ignore.case=T, recursive=T)   Does anyone have a faster way? If 
it helps using:  shell.exec("search-ms://query=plotrix.pdf")utilizes 
windows's search bar to find the file (this is quick), however it opens a 
screen that finds the file rather than providing me with the search path.  For 
a look at what that looks like on a windows machine click here: 
http://windows.microsoft.com/en-US/windows7/products/features/windows-search 
I'm thinking there's a way to use this method to extract the path even faster 
than dir(). TylerTo: tyler_rin...@hotmail.com
CC: r-help@r-project.org
Subject: Re: [R] Construct a File Path: File Path Unknown
From: jvad...@usgs.gov
Date: Thu, 25 Aug 2011 13:19:37 -0500



Try the dir() function.



?dir



# for example

dir("c:/", pattern="foo.pdf",
full.names=T, ignore.case=T, recursive=T)



Jean





Tyler Rinker wrote on 08/25/2011 11:54:28 AM:

> 

> I am not a programmer and am self-taught so I may lack the

> language to ask this appropriately (perhaps why an rseek search was


> unfruitful).

> 

> Let's say I saved a file to my desktop called foo.pdf.  Then
I want 

> R to return the file path of

> foo.pdf (pretend I don't know the location(path) of foo.pdf).

> 

> Question: How would I get R to return the unknown file path for

> foo.pdf.

> 

> I hypothesize that the find find.package() function code contains

> the secret for doing this but am unable to parse out the snippet to
do so.

> 

> I attempted file.path("foo.pdf")

> 

> which R returns [1] "foo.pdf"  #not what I want

> 

> ===

> 

> R version 2.14 beta

> 

> Windows 7

> 

> Reproducible code is not appropriate for this query

> 

> __

> R-help@r-project.org mailing list

> 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
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] Construct a File Path: File Path Unknown

2011-08-25 Thread Tyler Rinker






I am not a programmer and am self-taught so I may lack the
language to ask this appropriately (perhaps why an rseek search was unfruitful).

 

Let's say I saved a file to my desktop called foo.pdf.  Then I want R to return 
the file path of
foo.pdf (pretend I don't know the location(path) of foo.pdf).

 

Question: How would I get R to return the unknown file path for
foo.pdf.

 

I hypothesize that the find find.package() function code contains
the secret for doing this but am unable to parse out the snippet to do so.

 

I attempted file.path("foo.pdf")

which R returns [1] "foo.pdf"  #not what I want

 

===

R version 2.14 beta

Windows 7

Reproducible code is not appropriate for this query

  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Opening package manual from within R

2011-08-24 Thread Tyler Rinker

Apparently my request to view the help pages is not a popular method among R 
users for gaining information.  for me these pages are very helpful so I will 
follow up to completed this thread for future searchers.
 
First thanks fo Prof. Brian Ripley.  Your idea was spot on what I was looking 
for for generating a pdf from the package library.
 
I worked out the following code that I added to my .First() library:
#=manual
 <- function(library, method=web){

LIB <- substitute(library)
LIB <- as.character(LIB)

METH <- substitute(method)
METH <- as.character(METH)

switch(METH,
   web = 
browseURL(paste("http://cran.r-project.org/web/packages/",LIB,"/",LIB,".pdf";, 
sep = "")),
   system =  {unlink(paste(getwd(),"/",LIB,".pdf",sep=""))
 path <- find.package(LIB)
 system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
"Rd2pdf",shQuote(path)))})   
}
#=
 
library is the package name
method is either web or system (web is Internet based and faster where as 
system creates the pdf from the library latex code and is slower)
 
#=
Thanks for your responses!

Tyler
 

> Date: Wed, 24 Aug 2011 07:12:24 +0100
> From: rip...@stats.ox.ac.uk
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] Opening package manual from within R
> 
> On Tue, 23 Aug 2011, Tyler Rinker wrote:
> 
> >
> > Simple question but searching rseek did not yield the results I wanted.
> >
> > Question: Is there a way to open a help manual for a package from within R.
> >
> > For instance I would like to type a function in r for the tm package 
> > and R would open that PDF as seen here: 
> > http://cran.r-project.org/web/packages/tm/tm.pdf
> >
> > -The vignette function exists for vignettes 
> > [vignette("package.name")] so I assume the same exists for manuals.
> 
> You assume wrong. Vignettes PDFs are installed as part of the package 
> (and often take minutes to regenerate): the PDF version of the help 
> pages (what you seem to call 'the package manual') is not (in 
> general). In many cases what other people (including the author, e.g. 
> me for RODBC) call the 'package manual' is a PDF in the doc directory 
> (which may or may not be a vignette).
> 
> The assumption is that people will use search facilities or the hints 
> given by the help titles in help(package="tm") or browse the HTML 
> version of the same information (e.g. via help.start).
> 
> But you can (provided you have pdflatex etc in your path) generate the 
> PDF version of the help pages by
> 
> R CMD Rd2pdf /path/to/installed/package
> 
> It will even open it in a browser for you (unless you use 
> --no-preview). You could easily encapsulate this in a function by 
> e.g.
> 
> showPDFmanual <- function(package, lib.loc=NULL)
> {
> path <- find.package(package, lib.loc)
> system(paste(shQuote(file.path(R.home("bin"), "R")),
> "CMD", "Rd2pdf",
> shQuote(path)))
> }
> 
> Alternatively *for packages on CRAN only* you can access the version 
> on CRAN by browseURL.
> 
> > -I do not want library(help="package.name") as this is not detailed enough.
> >
> > I am running R 2.14.0 beta on a windows 7 machine
> > Reproducible code does not seem appropriate in this case.
> 
> But accurate 'at a minimum' information (and no HTML) does. There is 
> no such version as '2.14.0 beta', and will not be for a couple of 
> months. If you are running a beta version of R it is old, so please 
> update to a released or patched version. (Also, any version 
> calling itself '2.14.0 Under development' is old and needs updating: 
> the current R-devel displays no version number.)
> 
> 
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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.
> >
> 
> -- 
> Brian D. Ripley, rip...@stats.ox.ac.uk
> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> University of Oxford, Tel: +44 1865 272861 (self)
> 1 South Parks Road, +44 1865 272866 (PA)
> Oxford OX1 3TG, UK Fax: +44 1865 272595
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Opening package manual from within R

2011-08-23 Thread Tyler Rinker

David,
 
For me, on a windows machine, help(package=) results in a summary window 
opening in R rather than the detailed help manual that is available through 
CRAN.  Others suggested help.start() which takes me to a CRAN library site but 
requires me to still click with the mouse to locate the manual for the specific 
package.  My function:
 
manual <- function(library){

LIB <- substitute(library)
LIB <- as.character(LIB)
browseURL(paste("http://cran.r-project.org/web/packages/",LIB,"/",LIB,".pdf";, 
sep = ""))
}
 
...takes you right to the online package.  Does R have a similar function 
already that opens the detailed pdf as the vignette function does.  I don't 
know if the help manuals are downloaded automatically when I download a package 
but this would be even better as I would not require internet access to retieve 
the help manual.  If r doesn't have a function to do this but does download the 
help manuals automatically when I download a package I could use shell.exec()  
with the library file path to do the same thing as the function above.  Again 
this is all provided that R does not already have a function to do this, 
however, I'm guessing there is because of the existance of the vignette() 
function
 
Cheers
Tyler

 

> CC: gunter.ber...@gene.com; r-help@r-project.org
> From: dwinsem...@comcast.net
> To: tyler_rin...@hotmail.com
> Subject: Re: [R] Opening package manual from within R
> Date: Tue, 23 Aug 2011 18:22:38 -0400
> 
> 
> Try:
> 
> help(package=tm)
> 
> (You do not need library(). )
> -- 
> David.
> 
> On Aug 23, 2011, at 6:17 PM, Tyler Rinker wrote:
> 
> >
> > I don't think help.start is what I'm looking for but I may be doing 
> > it wrong. I tried:
> >
> > library(tm)
> > help.start("tm")
> >
> > This may be inappropriate as it returns:
> >
> >> library(tm)
> >> help.start("tm")
> > Error in if (update) make.packages.html(temp = TRUE) :
> > argument is not interpretable as logical
> >
> > Just typing help.start() takes me to a web page but I still have to 
> > search.
> >
> > I wrote a function to do what I want that I could place in 
> > my .First() or a premade package but why bother if there's a way to 
> > already do this?
> > #=
> > # FUNCTION
> > #=
> > manual <- function(library){
> >
> > LIB <- substitute(library)
> > LIB <- as.character(LIB)
> > browseURL(paste("http://cran.r-project.org/web/ 
> > packages/",LIB,"/",LIB,".pdf", sep = ""))
> > }
> >
> > #=
> > # EXAMPLES
> > #=========
> > manual(plyr)
> > manual(tm)
> >
> >
> >
> >
> >
> >> Date: Tue, 23 Aug 2011 15:10:51 -0700
> >> Subject: Re: [R] Opening package manual from within R
> >> From: gunter.ber...@gene.com
> >> To: tyler_rin...@hotmail.com
> >> CC: r-help@r-project.org
> >>
> >> After loading the package, does help.start() do what you want?
> >>
> >> -- Bert
> >>
> >> On Tue, Aug 23, 2011 at 2:32 PM, Tyler Rinker  >> > wrote:
> >>>
> >>> Simple question but searching rseek did not yield the results I 
> >>> wanted.
> >>>
> >>> Question: Is there a way to open a help manual for a package from 
> >>> within R.
> >>>
> >>> For instance I would like to type a function in r for the tm 
> >>> package and R would open that PDF as seen here:
> >>> http://cran.r-project.org/web/packages/tm/tm.pdf
> >>>
> >>> -The vignette function exists for vignettes 
> >>> [vignette("package.name")] so I assume the same exists for manuals.
> >>>
> >>> -I do not want library(help="package.name") as this is not 
> >>> detailed enough.
> >>>
> >>> I am running R 2.14.0 beta on a windows 7 machine
> >>> Reproducible code does not seem appropriate in this case.
> >>> [[alternative HTML version deleted]]
> >>>
> >>> __
> >>> R-help@r-project.org mailing list
> >>> 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
> > 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.
> 
> David Winsemius, MD
> West Hartford, CT
> 
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Opening package manual from within R

2011-08-23 Thread Tyler Rinker

I don't think help.start is what I'm looking for but I may be doing it wrong.  
I tried:
 
library(tm)
help.start("tm")
 
This may be inappropriate as it returns:
 
> library(tm)
> help.start("tm")
Error in if (update) make.packages.html(temp = TRUE) : 
  argument is not interpretable as logical
 
Just typing help.start() takes me to a web page but I still have to search.
 
I wrote a function to do what I want that I could place in my  .First() or a 
premade package but why bother if there's a way to already do this?
#=
#   FUNCTION
#=
manual <- function(library){

LIB <- substitute(library)
LIB <- as.character(LIB)
browseURL(paste("http://cran.r-project.org/web/packages/",LIB,"/",LIB,".pdf";, 
sep = ""))
}
 
#=
#EXAMPLES
#=
manual(plyr)
manual(tm)
 
 

 

> Date: Tue, 23 Aug 2011 15:10:51 -0700
> Subject: Re: [R] Opening package manual from within R
> From: gunter.ber...@gene.com
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> 
> After loading the package, does help.start() do what you want?
> 
> -- Bert
> 
> On Tue, Aug 23, 2011 at 2:32 PM, Tyler Rinker  
> wrote:
> >
> > Simple question but searching rseek did not yield the results I wanted.
> >
> > Question:  Is there a way to open a help manual for a package from within R.
> >
> > For instance I would like to type a function in r for the tm package and R 
> > would open that PDF as seen here:
> > http://cran.r-project.org/web/packages/tm/tm.pdf
> >
> > -The vignette function exists for vignettes [vignette("package.name")] so I 
> > assume the same exists for manuals.
> >
> > -I do not want library(help="package.name") as this is not detailed enough.
> >
> > I am running R 2.14.0 beta on a windows 7 machine
> > Reproducible code does not seem appropriate in this case.
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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
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] Opening package manual from within R

2011-08-23 Thread Tyler Rinker

Simple question but searching rseek did not yield the results I wanted.
 
Question:  Is there a way to open a help manual for a package from within R.
 
For instance I would like to type a function in r for the tm package and R 
would open that PDF as seen here:
http://cran.r-project.org/web/packages/tm/tm.pdf
 
-The vignette function exists for vignettes [vignette("package.name")] so I 
assume the same exists for manuals.
 
-I do not want library(help="package.name") as this is not detailed enough.
 
I am running R 2.14.0 beta on a windows 7 machine
Reproducible code does not seem appropriate in this case.   
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Renaming levels of a factor in a dataframe

2011-08-14 Thread Tyler Rinker

Here's an example of relevel used to relevel and combine groups
 
InsectSprays2<-InsectSprays
levels(InsectSprays2$spray)
levels(InsectSprays2$spray)<-list(new1=c("A","C"),YEPS=c("B","D","E"),LASTLY="F")
levels(InsectSprays2$spray)
InsectSprays2

So for you try...
levels (Data1$Site) <- list(Fw =c( "AB"), Est = c("DE"))
 

> From: deel...@hotmail.com
> To: r-help@r-project.org
> Date: Sun, 14 Aug 2011 12:56:25 -0300
> Subject: [R] Renaming levels of a factor in a dataframe
> 
> 
> 
> Dear Helplist:
> 
> 
> 
> I am trying, unsuccessfully, to rename levels of a factor in a dataframe. The 
> dataframe consists of two factor variables and one numeric variable as 
> follows:
> 
> Factor Site has 2 levels AB and DE, factor Fish has 30 levels, 15 associated 
> with each Site e.g. 1-1, 1-2,.2-1, 2-2 I am trying to rename the 
> levels of factor Site from AB to Fw and DE to Est while keeping them as 
> factors. The following 2 approaches do not work, each giving a NULL response 
> and creating a character string. 
> 
> 
> 
> levels (Data1$Site <- c("Fw", "Est")) This simply gives an alternating list 
> of Fw, Est, Fw, Est... not the desired 15 concurrent rows of Fw followed by 
> 15 of Est.
> 
> 
> 
> #levels (Data1$Site <- list(Fw = "AB", Est = "DE")) This gives the same 
> result. I have tried other approaches to no avail. It seems a simple problem 
> but has not been so. 
> 
> 
> 
> Any suggestions for solving this problem would be much appreciated.
> 
> 
> 
> Regards,
> 
> BJ 
> __
> R-help@r-project.org mailing list
> 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
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] plotting many unique colors with categorical data

2011-08-05 Thread Tyler Rinker

col=sample(colors()[-1], ncol(dataframe), replace = FALSE)
 
This may help but since it's randomized it's a crap shoot but the colors are 
likely to be more distinct.
  

> Date: Fri, 5 Aug 2011 15:38:57 -0400
> From: sarah.gos...@gmail.com
> To: rloise...@usgs.gov
> CC: r-help@r-project.org
> Subject: Re: [R] plotting many unique colors with categorical data
> 
> That's far too many to easily distinguish by color, especially if they
> need to be
> distinct, and not levels within a larger class. For the latter, you could get
> by with say 10 shades of red, 10 shades of blue, etc for related factors.
> But it doesn't sound like that's what you have. I don't think there's any
> way to create a palette of 75 distinguishable colors.
> 
> If you really want to try, colors() gives you all the named colors. You
> can also use c() to combine several brewer palettes.
> 
> One thing that I've done in similar cases (for viewing and data snooping,
> not for presentation), is to set up a loop through all the factor levels.
> Set par(ask=TRUE), and for each iteration plot all the points in black,
> except make that level a brighter color, and maybe larger symbol.
> 
> It gives you a quick way to start to see the differences between groups,
> though obviously isn't suitable for publication.
> 
> Sarah
> 
> On Fri, Aug 5, 2011 at 1:46 PM, SavageMaDaMe  wrote:
> > Hi- I am trying to plot a matrix of categorical values across time using
> > color to represent each individual factor. For example:
> >
> >   1982 1983 1984 1985 1986 1987
> > 119   19   68   68   19   19   68
> > 268   68   19   19   68   68   19
> > 326   26   34   34   26   26   26
> > 457   34   57   57   34   57   34
> > 534   57   26   26   57   34   57
> > 628   28   28   28   28   58   58
> > 760   10   58   58   58   28   28
> > 858   58   42   27   10   39   39
> > 922   39   22   42   42   27   42
> > 10   39   22   10   39   39   20   10
> >
> >
> >  I have 75 factors which could be in different positions through out time
> > (26 years).  I've successfully created a plot using both ggplot() and
> > color2D.matplot(), but can not select enough distinct colors from the
> > default color palettes available to be able to view differences in the data.
> > I've tried messing with RGB values, Brewer palettes, etc.
> >
> > How can I select colors from a list of available colors without choosing
> > ones which are too close in similarity to each other. For instance, I could
> > have several very similar blues, but if the Hue or saturation was different
> > on each, it would be fairly easy to tell the difference?
> >
> > Maybe there are too many factors to make this visual representation
> > effective?
> >
> > Thanks in advance for your help!
> >
> -- 
> Sarah Goslee
> http://www.functionaldiversity.org
> 
> __
> R-help@r-project.org mailing list
> 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
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] excel dates and times in R

2011-08-05 Thread Tyler Rinker

You can also make the change in the excel file first. 
 
In excel highlight the date column-> right click-> format cells ->under number 
tab click custom ->in the Type field type the following "-mm-dd"
 
Now save and import.
 

> Date: Fri, 5 Aug 2011 13:59:16 +0100
> From: ted.hard...@wlandres.net
> To: r-help@r-project.org
> CC: emma.ra...@jbaconsulting.co.uk
> Subject: Re: [R] excel dates and times in R
> 
> On 05-Aug-11 10:27:28, bevare wrote:
> > Hello,
> > I am having some fun dealing with dates and times. My input
> > is a excel csv file with two columns with data in the following
> > format: 
> > 
> > date time
> > 25-Jun-1961 04:00:00
> > 
> > i.e. day - month - year hour:min:sec
> > 
> > I would like to have a single object in R that combines these
> > and converts them into a sensible R format (e.g.
> > ISOdatetime(1961,06,25,04,00,00,tz="GMT").
> > 
> > I have played with the function chron and also strptime but
> > can't seem to get them to work. 
> > 
> > Can anybody help me out please? 
> > 
> > Thanks
> > Bevare
> 
> I know almost nothing about using the "time" functions in R,
> but since I see that I get:
> 
> ISOdatetime(1961,06,25,04,00,00,tz="GMT")
> # [1] "1961-06-25 04:00:00 GMT"
> 
> it would seem that you already have it almost made in the
> original Excel fields, namely:
> 
> paste("1961-06-25","04:00:00","GMT",sep=" ")
> # [1] "1961-06-25 04:00:00 GMT"
> 
> So you could write this as a function
> 
> getISOdt <- function(date,time,zone){
> paste(date,time,zone,sep=" ")
> }
> 
> where the parameters date, time and zone are supplied as
> character strings:
> 
> getISOdt("1961-06-25","04:00:00","GMT")
> [1] "1961-06-25 04:00:00 GMT"
> 
> Then you can apply() this to the two comlumns in the dataframe
> you get when reading in the Excel CSV file, with zone being
> supplied independently.
> 
> Hoping this helps,
> Ted.
> 
> 
> E-Mail: (Ted Harding) 
> Fax-to-email: +44 (0)870 094 0861
> Date: 05-Aug-11 Time: 13:59:14
> -- XFMail --
> 
> __
> R-help@r-project.org mailing list
> 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
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] ifelse returns

2011-07-29 Thread Tyler Rinker

Thanks toy Jim and Michael for their response.  The suggestion to use regular 
if/else was spot on.
 

> From: tyler_rin...@hotmail.com
> To: r-help@r-project.org
> Date: Sat, 30 Jul 2011 01:48:21 -0400
> Subject: [R] ifelse returns
> 
> 
> Greetings R Community,
> 
> I am working with the ifelse function and it is returning something 
> unexpected. In the code the line with the MODE1 assignment the output is a 
> vector [1] 4 5 6 but when I put the MODE1 object into the ifelse function 
> [R}'s output for MODE1 is the first number from the string (4). Why is this? 
> Given the supplied vector of x I would assume both the MODE1 and ifelse() 
> lines to return the same result. I would like the ifelse to return the entire 
> vector [1] 4 5 6 as in the previous line.
> 
> OS: Win7
> R version 2.14 beta
> 
> 
> #===
> # Beginning of code
> #===
> x<-c(2,3,4,4,5,5,6,6,8,10)
> 
> df<-as.data.frame(table(x)) 
> df<-df[order(df$Freq),] 
> m<-max(df$Freq) 
> (MODE1<-as.vector(as.numeric(as.character(subset(df,Freq==m)[,1]
> ifelse(sum(df$Freq)/length(df$Freq)==1,warning("No Mode: Frequency of all 
> values is 1", call. = FALSE),MODE1)
> #===
> # End of code
> #===
> 
> R Console Output
> > (MODE1<-as.vector(as.numeric(as.character(subset(df,Freq==m)[,1]
> [1] 4 5 6
> > ifelse(sum(df$Freq)/length(df$Freq)==1,warning("No Mode: Frequency of all 
> > values is 1", call. = FALSE),MODE1)
> [1] 4
> 
> Thank you in advance,
> Tyler 
> [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] ifelse returns

2011-07-29 Thread Tyler Rinker

Greetings R Community,
 
I am working with the ifelse function and it is returning something unexpected. 
 In the code the line with the MODE1 assignment the output is a vector [1] 4 5 
6  but when I put the MODE1 object into the ifelse function [R}'s output for 
MODE1 is the first number from the string (4).  Why is this?  Given the 
supplied vector of x I would assume both the MODE1 and ifelse() lines to return 
the same result.  I would like the ifelse to return the entire vector [1] 4 5 6 
as in the previous line.
 
OS: Win7
R version 2.14 beta


#===
#Beginning of code
#===
x<-c(2,3,4,4,5,5,6,6,8,10)
  
df<-as.data.frame(table(x))   
df<-df[order(df$Freq),] 
m<-max(df$Freq)
(MODE1<-as.vector(as.numeric(as.character(subset(df,Freq==m)[,1]
ifelse(sum(df$Freq)/length(df$Freq)==1,warning("No Mode: Frequency of all 
values is 1", call. = FALSE),MODE1)
#===
# End of code
#===
 
R Console Output
> (MODE1<-as.vector(as.numeric(as.character(subset(df,Freq==m)[,1]
[1] 4 5 6
> ifelse(sum(df$Freq)/length(df$Freq)==1,warning("No Mode: Frequency of all 
> values is 1", call. = FALSE),MODE1)
[1] 4
 
Thank you in advance,
Tyler 
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] color of math annotation in legend

2011-07-28 Thread Tyler Rinker

Use the text.col argument as below
?legend
 
x=y=1:100
z=seq(0.5,50,by=0.5)
plot(x,y,type='l',col='black')
lines(x,z,col='red')
legend('topleft',c(expression(paste(alpha," = ", 1)),
expression(paste(alpha," = ", 2))),text.col=c("black","red"))
 
 

 

> Date: Thu, 28 Jul 2011 02:32:04 -0500
> From: zhongyi-y...@uiowa.edu
> To: r-help@r-project.org
> Subject: [R] color of math annotation in legend
> 
> Dear useRs,
> 
> Can someone help me to adjust the color of math annotation in a legend? The
> following code gives me a black "alpha = 2".
> 
> x=y=1:100
> z=seq(0.5,50,by=0.5)
> plot(x,y,type='l',col='black')
> lines(x,z,col='red')
> legend('topleft',c(expression(paste(alpha," = ", 1)),
> expression(paste(alpha," = ", 2))),col=c('black','red'))
> 
> Is it possible to make it red? Thanks in advance for your help.
> 
> Best,
> Zhongyi Yuan
> 
> [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] (no subject)

2011-07-14 Thread Tyler Rinker


Good Afternoon R Community,
 
I often work with very large data bases and want to search for select cases by 
a particular word or numeric value.  I created the following simple function to 
do just that.  It searchs a particular column for the phrase and returns a data 
frame with the rows that contain that phrase (for a particular column).  
 
Search<-function(term, dataframe, column.name, variation=.02,...){
te<-substitute(term)
   te<-as.character(te)
   cn<-substitute(column.name)
  cn<-as.character(cn)
  HUNT<-agrep(te,dataframe[,cn],ignore.case 
=TRUE,max.distance=variation,...)
   dataframe[c(HUNT),]
}
 
I would like to modify this to search all columns for the phrase keep only the 
unique rows and return a data frame for any columns (minus repeated rows) that 
contain the phrase.
 
I assumed this would be an easy task for me using sapply() and unique() or 
union().  Because this argument takes more than one argument (vector{column} is 
not the only argument) I don’t know how to set it up.  Could someone tell me 
how to apply this function to multiple columns and return one data frame with 
all the agrep matches (I’ll figure out how to deal with duplicates after that; 
that’s the easy part).
 
Thank you in advance for your help,
Tyler Rinker
 
PS if your idea is a for loop please explain it well or provide the code 
because I do not have a programming background and for loops are very difficult 
to wrap my head around.
 
Running windows 7
R version 2.14.0 (beta)   
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Storing and managing custom R functions for re-use

2011-07-09 Thread Tyler Rinker

I personally place functions like this in my .First function under the 
.Rprofile, making them instantly accessible.  I also keep a function called 
my.fun() which lists a data frame containing a column of all the function 
names, one for arguments, and a brief description.  This also goes in .First.  
Again, this makes it easy to quickly reference what you have and makes all your 
functions quickly accessible.
 
Tyler 
 

> Date: Sat, 9 Jul 2011 13:30:51 +0200
> From: s.chamai...@yahoo.fr
> To: r-help@r-project.org
> Subject: [R] Storing and managing custom R functions for re-use
> 
> Dear all,
> 
> sorry if this is a bit on the sidetrack for R-help.
> 
> As a regular R user I have developed quite a lot of custom R functions, 
> to the point of not always remembering what I have already programmed, 
> where the file is and so on.
> I was wondering what other people do in this regards. A basic file with 
> all your functions, or a custom R package, or directly integrated into a 
> profile file ??? I'm considering that a blog with tagged posts may be a 
> good solution (and really good ones could join R-bloggers maybe).
> 
> If someone is happy to share what (s)he considers good practice, thanks.
> 
> simon
> 
> __
> R-help@r-project.org mailing list
> 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
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] library(doBy) will not load

2011-06-28 Thread Tyler Rinker

Problem solved.  I lazily forgot to clean up my workspace with rm(list=ls()).  
A good reminder to do so after each exit.  Sorry for the wasted server space.
 

From: tyler_rin...@hotmail.com
To: r-help@r-project.org
Date: Tue, 28 Jun 2011 22:58:47 -0400
Subject: Re: [R] library(doBy) will not load

 
This is the error I get when I try to load snow.
 
> library(snow)
Error in as.character(t) : 't' is missing
Error in library(snow) : .First.lib failed for ‘snow’
 
 
From: tyler_rin...@hotmail.com
To: r-help@r-project.org
Date: Tue, 28 Jun 2011 22:47:06 -0400
Subject: [R] library(doBy) will not load
 
 
Greetings R Community,
 
One of my favorite packages won't load and I'm not sure why.  It loaded earlier 
today. The problem appears with the snow package, which doBy requires.  I tried 
reinstalling both packages again ,shutting [R] down, reinstalling [R] in the 
workspace (shortcut). Here's the weird thing.  The same exact library loads in 
another workspace using the same version of [R] with no problem.
 
OS:  Windows 7 
R version 2.14 (in development)
 
> library(doBy)
Loading required package: survival
Loading required package: splines
Loading required package: R2HTML
Loading required package: multcomp
Loading required package: mvtnorm
Loading required package: lme4
Loading required package: Matrix
Loading required package: lattice
Attaching package: ‘Matrix’
The following object(s) are masked from ‘package:base’:
det
 
Attaching package: ‘lme4’
The following object(s) are masked from ‘package:stats’:
AIC, BIC
Loading required package: snow
Error in as.character(t) : 't' is missing
Error: package ‘snow’ could not be loaded
> recodeVar
Error: object 'recodeVar' not found
 
Thank you in advance,
Tyler
  
[[alternative HTML version deleted]]
 
 
__ R-help@r-project.org mailing 
list 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 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
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] library(doBy) will not load

2011-06-28 Thread Tyler Rinker

This is the error I get when I try to load snow.
 
> library(snow)
Error in as.character(t) : 't' is missing
Error in library(snow) : .First.lib failed for ‘snow’
 

From: tyler_rin...@hotmail.com
To: r-help@r-project.org
Date: Tue, 28 Jun 2011 22:47:06 -0400
Subject: [R] library(doBy) will not load

 
Greetings R Community,
 
One of my favorite packages won't load and I'm not sure why.  It loaded earlier 
today. The problem appears with the snow package, which doBy requires.  I tried 
reinstalling both packages again ,shutting [R] down, reinstalling [R] in the 
workspace (shortcut). Here's the weird thing.  The same exact library loads in 
another workspace using the same version of [R] with no problem.
 
OS:  Windows 7 
R version 2.14 (in development)
 
> library(doBy)
Loading required package: survival
Loading required package: splines
Loading required package: R2HTML
Loading required package: multcomp
Loading required package: mvtnorm
Loading required package: lme4
Loading required package: Matrix
Loading required package: lattice
Attaching package: ‘Matrix’
The following object(s) are masked from ‘package:base’:
det
 
Attaching package: ‘lme4’
The following object(s) are masked from ‘package:stats’:
AIC, BIC
Loading required package: snow
Error in as.character(t) : 't' is missing
Error: package ‘snow’ could not be loaded
> recodeVar
Error: object 'recodeVar' not found
 
Thank you in advance,
Tyler
  
[[alternative HTML version deleted]]
 

__ R-help@r-project.org mailing 
list 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
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] library(doBy) will not load

2011-06-28 Thread Tyler Rinker

Greetings R Community,
 
One of my favorite packages won't load and I'm not sure why.  It loaded earlier 
today. The problem appears with the snow package, which doBy requires.  I tried 
reinstalling both packages again ,shutting [R] down, reinstalling [R] in the 
workspace (shortcut). Here's the weird thing.  The same exact library loads in 
another workspace using the same version of [R] with no problem.
 
OS:  Windows 7 
R version 2.14 (in development)
 
> library(doBy)
Loading required package: survival
Loading required package: splines
Loading required package: R2HTML
Loading required package: multcomp
Loading required package: mvtnorm
Loading required package: lme4
Loading required package: Matrix
Loading required package: lattice
Attaching package: ‘Matrix’
The following object(s) are masked from ‘package:base’:
det

Attaching package: ‘lme4’
The following object(s) are masked from ‘package:stats’:
AIC, BIC
Loading required package: snow
Error in as.character(t) : 't' is missing
Error: package ‘snow’ could not be loaded
> recodeVar
Error: object 'recodeVar' not found
 
Thank you in advance,
Tyler
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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 simulate Likert-type data using R

2011-06-26 Thread Tyler Rinker

?sample
 

Date: Sun, 26 Jun 2011 02:26:10 -0700
From: wjca...@hotmail.com
To: r-help@r-project.org
Subject: [R] how to simulate Likert-type data using R

Dear R members 
 
Could someone tell me how to simulate Likert-type data using the rnorm
function. 
 
Let's say, 200*15 random numbers in a variable that goes from 1 to 4 in
steps of 
1 (i.e., 1, 2, 3, 4)  belonging to a normal distribution? 
 
random.data <— matrix(rnorm(200 * 15), nrow = 200, ncol = 15) 
random.data 
 
The result cannot be reached.
 
could one help me revise the syntax?
 
Cheers 
 
cao
 
 
--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-simulate-Likert-type-data-using-R-tp3625664p3625664.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]
 

__ R-help@r-project.org mailing 
list 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
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] Somers Dyx

2011-06-12 Thread Tyler Rinker

Hello R Community,
 
I'm continuing to work through logistic regression (thanks for all the help on 
score test) and have come up against a new opposition.
 
I'm trying to compute Somers Dyx as some suggest this is the preferred method 
to Somers Dxy (Demaris, 1992).  I have searchered the [R] archieves to no avail 
for a function or code to compute Dyx (not Dxy).  The overview of Hmisc has 
mention of Dyx for the rcorr.cens function but this appears to be a misprint 
because the manual states the function finds Dxy.  Peng and So (1998) state 
that the Dyx is easily calculated in SAS (which tells me the same is possible 
for [R]).  
 
Yang, K., Miller, G. J., & Miller, G. state that:
 
(Tau-b)^2=Somers Dxy * Somers Dyx 
 
…so maybe an approach would be to write a function that is:
 
Somers Dyx<-(Tau-b)^2/Somers Dxy  
 
I just don't want to waste time if this is incorrect logic and/or there's an 
easier way to calculate this thing; perhaps there’s a ‘golden’ function already 
created in an [R] package that I'm overlooking.
 
Thanks in advance,
Tyler 
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Score Test Function

2011-06-11 Thread Tyler Rinker

Greeting R Community,
 
I'm trying to learn Logistic Regression on my own and am using An Introduction 
to Logistic Regression Analysis and Reporting (Peng, C., Lee, K., & Ingersoll, 
G. ,2002). This article uses a Score Test Stat as a measure of overall fit for 
a logistic regression model.  The author calculates this statistic using SAS.  
I am looking for an [R] function that can compute this stat and a p=value 
(please don't critique the stat itself).  As far as I can tell glm.scoretest() 
from library(statmod) is the only function for this but it does not give a 
pvalue and appears to not correspond with the author's example.  Some chat on 
the discussion board a while back indicated that this was a well known test 
Click here for that thread but difficult to calculate in [R].  I'm wondering if 
there is a way to do this fairly easily in [R] at this time?
 
I am working with the data set from the study and am looking to get close to 
the 9.5177 score test stat and .0086 p-value with 2 degrees freedom.
Below is the code for the data set and some descriptives so you can see the 
data set is the same as  from the study.  I highlighted my attempt to get a 
score test statistic and am curious if this is it (minus the p-value).
 
#BEGINNING OF CODE
id<-factor(1:189)
gender<-factor(c("Boy","Boy","Girl","Girl","Girl","Boy","Girl","Boy","Girl","Girl","Boy","Boy","Boy","Boy","Girl","Girl","Boy","Girl","Boy","Girl","Boy","Girl","Girl",
"Boy","Boy","Girl","Girl","Girl","Boy","Boy","Boy","Girl","Boy","Girl","Boy","Girl","Girl","Girl","Girl","Girl","Boy","Girl","Boy","Girl","Girl","Girl",
"Girl","Boy","Girl","Boy","Girl","Boy","Girl","Girl","Boy","Boy","Boy","Boy","Boy","Boy","Boy","Boy","Boy","Girl","Boy","Boy","Boy","Boy","Girl","Boy",
"Girl","Boy","Boy","Boy","Girl","Boy","Girl","Girl","Boy","Girl","Girl","Girl","Boy","Boy","Boy","Boy","Boy","Girl","Girl","Girl","Girl","Boy","Girl",
"Girl","Girl","Girl","Girl","Girl","Girl","Girl","Girl","Girl","Boy","Girl","Boy","Boy","Girl","Girl","Girl","Boy","Girl","Boy","Girl","Girl","Girl","Boy",
"Girl","Boy","Girl","Boy","Girl","Boy","Girl","Girl","Girl","Girl","Girl","Girl","Girl","Girl","Boy","Girl","Boy","Boy","Boy","Boy","Boy","Boy","Boy","Girl",
"Girl","Girl","Boy","Boy","Girl","Girl","Boy","Girl","Boy","Boy","Boy","Girl","Girl","Girl","Girl","Boy","Boy","Girl","Boy","Boy","Girl","Boy","Boy","Boy",
"Boy","Girl","Boy","Boy","Girl","Girl","Boy","Boy","Boy","Boy","Boy","Girl","Girl","Girl","Girl","Boy","Boy","Boy","Girl","Boy","Girl","Boy","Boy","Boy","Girl"))
reading.score<-c(91.0,77.5,52.5,54.0,53.5,62.0,59.0,51.5,61.5,56.5,47.5,75.0,47.5,53.5,50.0,50.0,49.0,59.0,60.0,60.0,
60.5,50.0,101.0,60.0,60.0,83.5,61.0,75.0,84.0,56.5,56.5,45.0,60.5,77.5,62.5,70.0,69.0,62.0,107.5,54.5,92.5,94.5,65.0,
80.0,45.0,45.0,66.0,66.0,57.5,42.5,60.0,64.0,65.0,47.5,57.5,55.0,55.0,76.5,51.5,59.5,59.5,59.5,55.0,70.0,66.5,84.5,
57.5,125.0,70.5,79.0,56.0,75.0,57.5,56.0,67.5,114.5,70.0,67.0,60.5,95.0,65.5,85.0,55.0,63.5,61.5,60.0,52.5,65.0,87.5,
62.5,66.5,67.0,117.5,47.5,67.5,67.5,77.0,73.5,73.5,68.5,55.0,92.0,55.0,55.0,60.0,120.5,56.0,84.5,60.0,85.0,93.0,60.0,
65.0,58.5,85.0,67.0,67.5,65.0,60.0,47.5,79.0,80.0,57.5,64.5,65.0,60.0,85.0,60.0,58.0,61.5,60.0,65.0,93.5,52.5,42.5,
75.0,48.5,64.0,66.0,82.5,52.5,45.5,57.5,65.0,46.0,75.0,100.0,77.5,51.5,62.5,44.5,51.0,56.0,58.5,69.0,65.0,60.0,65.0,
65.0,40.0,55.0,52.5,54.5,74.0,55.0,60.5,50.0,48.0,51.0,55.0,93.5,61.0,52.5,57.5,60.0,71.0,65.0,60.0,55.0,60.0,77.0,
52.5,95.0,50.0,47.5,50.0,47.0,71.0,65.0)
reading.recommendation<-as.factor(c(rep("no",130),rep("yes",59)))
DF<-data.frame(id,gender,reading.score,reading.recommendation)
head(DF)
#=
#  DESCRIPTIVES
#=
table(DF[2:4])  #BREAKDOWN OF SCORES BY GENDER AND REMEDIAL READING 
RECOMENDATIONS
table(DF[c(2)])  #TABLE OF GENDER
print(table(DF[c(2)])/sum(table(DF[c(4)]))*100,digits=4)#PERCENT GENDER 
BREAKDOWN
table(DF[c(4)])  #TABLE RECOMENDDED FOR REMEDIAL READING
print(table(DF[c(4)])/sum(table(DF[c(4)]))*100,digits=4)#Probability of 
Reccomended
table(DF[c(2,4)])  #TABLE OF GIRLS AND BOYS RECOMENDDED FOR REMEDIAL READING
print(prop.table(table(DF[c(2,4)]),1)*100,digits=4)#Probability of Reccomended
#=
#ANALYSIS
#=
(mod1<-glm(reading.recommendation~reading.score+gender,family=binomial,data=DF))
 
library(statmod)
with(DF,glm.scoretest(mod1, c(0,2,3), dispersion=NULL))^2
#If I move the decimal over 2 to the right I get close to the 9.5177 from the 
study
(with(DF,glm.scoretest(mod1, c(0,2,3), dispersion=NULL))^2)*100 #is this it?
#END OF CODE
 
I am running R 2.13.0 in a windows 7 machine.
 
Peng, C., Lee, K., & Ingersoll, G. (2002). An Introduction to Logistic 
Regression Analy

Re: [R] draw text outside plot boundaries

2011-06-06 Thread Tyler Rinker

Erik,
 
To add to what epter said...
I created this little function for clicking text anywhere on the plot (I 
probably stole the idea from a list serve or Dalgaard's book or someplace like 
that).  Anyway it is helpful to me and may be of use to you too.  Very basic 
but I use it a ton.  You modify to suit your needs.
 
#TEXT CLICK FUNCTION
textClick<-function(express,col="black",cex=NULL){
par(mar = rep(0, 4),xpd=NA)
text(locator(1),express,col=col,cex=cex)
}
 
#EXAMPLE
frame()
par(mfrow=c(2,2))
with(mtcars,plot(mpg~cyl));with(mtcars,plot(mpg~cyl))
with(mtcars,plot(mpg~cyl));with(mtcars,plot(mpg~cyl))
textClick(expression(sum((bar(X)-X^2))),"pink",.5)
 
Cheers
Tyler
 
> Date: Mon, 6 Jun 2011 15:09:29 -0700
> From: ehl...@ucalgary.ca
> To: e...@q32.com
> CC: r-help@r-project.org
> Subject: Re: [R] draw text outside plot boundaries
> 
> On 2011-06-06 08:44, Erik Aronesty wrote:
> > i'd like to use the text() function to annotate some points, but the
> > labels get cropped, if the point is on the right
> >
> > is there a way to prevent this, and tell the text() function to allow
> > writing outside the boundaries of the current plot?
> 
> Go to ?par and check out the 'xpd' parameter.
> 
> Peter Ehlers
> 
> >
> > i don't mind if it looks "messy" and steps on the margin a bit.
> >
> > - erik
> >
> > __
> > R-help@r-project.org mailing list
> > 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
> 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
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] Simple Missing cases Function

2011-04-19 Thread Tyler Rinker

I use the following code/function which gives me some quick descriptives about 
each variable (ie. n of missing values, % missing, case #'s missing, etc.):
Fairly quick, maybe not pretty but effective on either single variables or 
entire data sets.
 
NAhunter<-function(dataset)
{
find.NA<-function(variable)
{
if(is.numeric(variable)){
n<-length(variable)
mean<-mean(variable, na.rm=T)
median<-median(variable, na.rm=T)
sd<-sd(variable, na.rm=T)
NAs<-is.na(variable)
total.NA<-sum(NAs)
percent.missing<-total.NA/n
descriptives<-data.frame(n,mean,median,sd,total.NA,percent.missing)
rownames(descriptives)<-c(" ")
Case.Number<-1:n
Missing.Values<-ifelse(NAs>0,"Missing Value"," ")
missing.value<-data.frame(Case.Number,Missing.Values)
missing.values<-missing.value[ which(Missing.Values=='Missing Value'),]
list("NUMERIC DATA","DESCRIPTIVES"=t(descriptives),"CASE # OF MISSING 
VALUES"=missing.values[,1])
}
else{
n<-length(variable)
NAs<-is.na(variable)
total.NA<-sum(NAs)
percent.missing<-total.NA/n
descriptives<-data.frame(n,total.NA,percent.missing)
rownames(descriptives)<-c(" ")
Case.Number<-1:n
Missing.Values<-ifelse(NAs>0,"Missing Value"," ")
missing.value<-data.frame(Case.Number,Missing.Values)
missing.values<-missing.value[ which(Missing.Values=='Missing Value'),]
list("CATEGORICAL DATA","DESCRIPTIVES"=t(descriptives),"CASE # OF MISSING 
VALUES"=missing.values[,1])
}
}
dataset<-data.frame(dataset)
options(scipen=100)
options(digits=2)
lapply(dataset,find.NA)
}

 
> From: tesut...@hku.hk
> To: r-help@r-project.org
> Date: Tue, 19 Apr 2011 15:29:08 +0800
> Subject: [R] Simple Missing cases Function
> 
> Dear all
> 
> 
> 
> I have written a function to perform a very simple but useful task which I
> do regularly. It is designed to show how many values are missing from each
> variable in a data.frame. In its current form it works but is slow because I
> have used several loops to achieve this simple task. 
> 
> 
> 
> Can anyone see a more efficient way to get the same results? Or is there
> existing function which does this?
> 
> 
> 
> Thanks for your help
> 
> Tim
> 
> 
> 
> Function:
> 
> miss <- function (data) 
> 
> {
> 
> miss.list <- list(NA)
> 
> for (i in 1:length(data)) {
> 
> miss.list[[i]] <- table(is.na(data[i]))
> 
> }
> 
> for (i in 1:length(miss.list)) {
> 
> if (length(miss.list[[i]]) == 2) {
> 
> miss.list[[i]] <- miss.list[[i]][2]
> 
> }
> 
> }
> 
> for (i in 1:length(miss.list)) {
> 
> if (names(miss.list[[i]]) == "FALSE") {
> 
> miss.list[[i]] <- 0
> 
> }
> 
> }
> 
> data.frame(names(data), as.numeric(miss.list))
> 
> }
> 
> 
> 
> Example:
> 
> data(ToothGrowth)
> 
> data.m <- ToothGrowth
> 
> data.m$supp[sample(1:nrow(data.m), size=25)] <- NA
> 
> miss(data.m)
> 
> 
> [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] My added packages won't load in r.2.13.0

2011-04-16 Thread Tyler Rinker

Problem:
 
I updated from r.2.12 to r.2.13 and when I use library(car) for example it says:
 
> library(car)
Error in library(car) : there is no package called 'car'
 
So I found that the packages I had before are located in:
C:\Users\Documents\R\win-library\2.12
 
Now they're in:
C:\Users\Documents\R-2.13.0\src\library
 
I tried to use control+a and drag them over to the folder 
C:\Users\Documents\R-2.13.0\src\library
 
and then  load car.
 
I still get the same error message.
 
How do I move my packages so the new version of R can find them?
 
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Automated Fixed Order Stepwise Regression Function

2011-04-07 Thread Tyler Rinker

Greetings,
 
I am interested in creating a stepwise fixed order regression function.  
There's a function for this already called add1( ).  The F statistics are 
calculated using type 2 anova (the SS and the F changes don't match SPSS's).  
You can see my use of this at the very end of the email.
 
What I want: a function to make an anova table with f changes and delt R^2.  
 
I ran into 10 snags to making this a fully automated function using the full 
linear model (order matters here).  Each snag is marked with a Comment #.  Some 
snags are repeated because I couldn't do the first time and certainly couldn't 
do it after that. Help with any/all snags would be very appreciated. 
 
I'm a 2 1/2 month [R] user who's reading everything online (incl. manuals) & 
ordering every book I can (looking at Dalgaard, Crawly's and Teetor's very 
helpful books right now).  Loops and their usage is a foreign thing to me, 
despite studying them, and unfortunately I think that my function may call for 
them.  I also realize that beyond 10 predictors may make this function way to 
bulky.
 
I'm running the latest version of R (2.12.2)on a windows 7 machine.

DATASET
 
mtcars
full.model<-lm(mpg~cyl+disp+hp+drat, data=mtcars)
 
CODE

stepFO<-function(model)
{
m<-data.frame(model.frame(model))
num.of.var<-length(colnames(m))
mod1<-lm(m[,1]~m[,2])
mod2<-lm(m[,1]~m[,2]+m[,3])
mod3<-lm(m[,1]~m[,2]+m[,3]+m[,4])
mod4<-lm(m[,1]~m[,2]+m[,3]+m[,4]+m[,5])
#Comment 1--I don't know how to automated this process(above) of adding 
#...additional variables.  Probably a loop is needed but I don't understand 
#...how to apply it here.  Maybe update.model [1:num.ofvar]?
a1<-anova(mod1)
a2<-anova(mod2)
a3<-anova(mod3)
a4<-anova(mod4)
#Comment 2--SAME AS COMMENT 1 except applied to the anova tables.  How do I make
#...[R] add a5, a6...an   as necessary?

rb<-rbind(a1,a2,a3,a4)
#Comment 3--again I can't automate this to make the  addition of a's automated

anova1<-rbind(rb[1,],rb[4,],rb[8,],rb[13,],rb[14,])
#Comment 4--the rb's follow a pattern of 1+3+4+5...+n variables
#then I row bind these starting with 1 and rowbind one more after the last 
#...rb to include the bottom piece of the anova table that tells 
#...about residuals (how do I aoutomate this?)

anova<-anova1[,1:num.of.var]
anova.table<-data.frame(anova)
#Comment 5--Something that bugs me here is that I have to turn it into a 
dataframe to 
#...add the totals row and the delta R^2 (tried playing w/ tkinsert to no avail)
#...I miss the stuff that's at the bottom of the anova table (sig values)
#Comment 6--I'd love to turn the place value to round to 2 after the decimal.
#...I've worked this many ways including changing my options but this does 
#...not seem to apply to a data frame

Total<-c(sum(anova[,1]),sum(anova[,2])," ", " ", " ")
anova.table<-rbind(anova.table,Total)
R1<-summary(mod1)[[8]][[1]]
R2<-summary(mod2)[[8]][[1]]
R3<-summary(mod3)[[8]][[1]]
R4<-summary(mod4)[[8]][[1]]
#Comment 7--SAME AS COMMENT 2.  How do I make
#...[R] add R5, R6...Rn   as necessary?

deltaR.1<-R1
deltaR.2<-R2-R1
deltaR.3<-R3-R2
deltaR.4<-R4-R3
#Comment 8--SAME AS COMMENT 7.  How would I aoutomate this process?

Delta.R.Squared<-c(deltaR.1,deltaR.2,deltaR.3,deltaR.4," ","")
#Comment 9--I need a way to add as many deltaR's as 
#...necessary(n of R = n of predictors)

anova.table<-cbind(anova.table, Delta.R.Squared)
colnames(anova.table)<-c("df","Sum Sq","Mean Sq","F-change",
"P-value","Delta.R.Squared")
rownames(anova.table)<-c("X1", "X2 elminating for X1", 
"X3 eliminating for X2 & X3", "X4 eliminating for X1,X2, & X3","Residuals",
 "Total")
anova.table
}
#Comment 10--Again I would need [R] to automate the list for row names as we 
#...add more predictors.
#See the final product below I'm after (with two places after the decimal)
> anova.table
df   Sum Sq  Mean Sq 
F-changeP-value Delta.R.Squared
X1   1 817.712952354614 817.712952354614 
79.5610275293349 6.112687142581e-10   0.726180005093805
X2 elminating for X1 1 37.5939529324851 37.5939529324851  
4.0268283172755 0.0541857201845285  0.0333857704630917
X3 eliminating for X2 & X3   1 9.37092926438942 9.37092926438942 
1.00388976918267  0.324951851250774 0.00832196853596723
X4 eliminating for X1,Xx2, & X3  1 16.4674349222492 16.4674349222492 
1.81550535203668  0.189048514740917  0.0146241073243205
Residuals   27 244.901918026262 9.07044140838007

Total   31 1126.0471875  
 
 
USING THE ADD1() FUNCTION>  NOT WHAT I WANT> 
 
mod1<-lm(mpg~cyl, data=mtcars)
add1(mod1,~cyl+disp+hp+drat, data=mtcars, test="F")

Model:
mpg ~ cyl
   Df Sum of SqRSSAIC F value   Pr(F)  
  308.33 76.494  
disp137.594 270.74 74.334  4.0268 0.05419 .
hp  116.360 291.98 76.750  1.6249 0.21253  
drat115.841 292.4

Re: [R] Function for finding NA's

2011-04-03 Thread Tyler Rinker

aThanks David,
 
After seeing the simplicity of your function versus the convoluted mess I 
worked up I now understand why it's not necessary to have a package to find 
NA's (and from what you said is a part of other packages such as Hmisc 
already).  
 
I am at the 2 1/2 month mark as an R user and have loads to learn.  Simpler is 
better.  Thanks David for your time and I will take the information you gave 
and put it to use in new situations.
 
Tyler
 
> CC: r-help@r-project.org
> From: dwinsem...@comcast.net
> To: tyler_rin...@hotmail.com
> Subject: Re: [R] Function for finding NA's
> Date: Sun, 3 Apr 2011 14:19:40 -0400
> 
> 
> On Apr 3, 2011, at 1:44 PM, Tyler Rinker wrote:
> 
> >
> > Quick question,
> >
> > I tried to find a function in available packages to find NA's for an 
> > entire data set (or single variables) and report the row of missing 
> > values (NA's for each column). I searched the typical routes 
> > through the blogs and the help manuals for 15 minutes. Rather than 
> > spend any more time searching I created my own function to do this 
> > (probably in less time than it would have taken me to find the 
> > function).
> >
> > Now I still have the same question: Is this function (NAhunter I 
> > call it) already in existence? If so please direct me (because I'm 
> > sure they've written better code more efficiently). I highly doubt 
> > I'm this first person to want to find all the missing values in a 
> > data set so I assume there is a function for it but I just didn't 
> > spend enough time looking. If there is no existing function (big if 
> > here), is this something people feel is worthwhile for me to put 
> > into a package of some sort?
> 
> I'm not sure that it would have occurred to people to include it in a 
> package. Consider:
> 
> getNa <- function(dfrm) lapply(dfrm, function(x) which(is.na(x) ) )
> 
> > cities
> long lat city pop
> 1 -58.38194 -34.59972 Buenos Aires NA
> 2 14.25000 40.8  NA
> > getNa(cities)
> $long
> integer(0)
> 
> $lat
> integer(0)
> 
> $city
> [1] 2
> 
> $pop
> [1] 1 2
> 
> There are several packages with functions by the name `describe` that 
> do most or all of rest of what you have proposed. I happen to use 
> Harrell's Hmisc but the other versions should also be reviewed if you 
> want to avoid re-inventing the wheel.
> -- 
> David.
> 
> >
> > Tyler
> >
> > Here's the code:
> >
> > NAhunter<-function(dataset)
> > {
> > find.NA<-function(variable)
> > {
> > if(is.numeric(variable)){
> > n<-length(variable)
> > mean<-mean(variable, na.rm=T)
> > median<-median(variable, na.rm=T)
> > sd<-sd(variable, na.rm=T)
> > NAs<-is.na(variable)
> > total.NA<-sum(NAs)
> > percent.missing<-total.NA/n
> > descriptives<-data.frame(n,mean,median,sd,total.NA,percent.missing)
> > rownames(descriptives)<-c(" ")
> > Case.Number<-1:n
> > Missing.Values<-ifelse(NAs>0,"Missing Value"," ")
> > missing.value<-data.frame(Case.Number,Missing.Values)
> > missing.values<-missing.value[ which(Missing.Values=='Missing 
> > Value'),]
> > list("NUMERIC DATA","DESCRIPTIVES"=t(descriptives),"CASE # OF 
> > MISSING VALUES"=missing.values[,1])
> > }
> > else{
> > n<-length(variable)
> > NAs<-is.na(variable)
> > total.NA<-sum(NAs)
> > percent.missing<-total.NA/n
> > descriptives<-data.frame(n,total.NA,percent.missing)
> > rownames(descriptives)<-c(" ")
> > Case.Number<-1:n
> > Missing.Values<-ifelse(NAs>0,"Missing Value"," ")
> > missing.value<-data.frame(Case.Number,Missing.Values)
> > missing.values<-missing.value[ which(Missing.Values=='Missing 
> > Value'),]
> > list("CATEGORICAL DATA","DESCRIPTIVES"=t(descriptives),"CASE # OF 
> > MISSING VALUES"=missing.values[,1])
> > }
> > }
> > dataset<-data.frame(dataset)
> > options(scipen=100)
> > options(digits=2)
> > lapply(dataset,find.NA)
> > } 
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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.
> 
> David Winsemius, MD
> West Hartford, CT
> 
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Function for finding NA's

2011-04-03 Thread Tyler Rinker

Quick question,
 
I tried to find a function in available packages to find NA's for an entire 
data set (or single variables) and report the row of missing values (NA's for 
each column).  I searched the typical routes through the blogs and the help 
manuals for 15 minutes.  Rather than spend any more time searching I created my 
own function to do this (probably in less time than it would have taken me to 
find the function).  
 
Now I still have the same question:  Is this function (NAhunter I call it) 
already in existence?  If so please direct me (because I'm sure they've written 
better code more efficiently).  I highly doubt I'm this first person to want to 
find all the missing values in a data set so I assume there is a function for 
it but I just didn't spend enough time looking.  If there is no existing 
function (big if here), is this something people feel is worthwhile for me to 
put into a package of some sort?  
 
Tyler
 
Here's the code:
 
NAhunter<-function(dataset)
{
find.NA<-function(variable)
{
if(is.numeric(variable)){
n<-length(variable)
mean<-mean(variable, na.rm=T)
median<-median(variable, na.rm=T)
sd<-sd(variable, na.rm=T)
NAs<-is.na(variable)
total.NA<-sum(NAs)
percent.missing<-total.NA/n
descriptives<-data.frame(n,mean,median,sd,total.NA,percent.missing)
rownames(descriptives)<-c(" ")
Case.Number<-1:n
Missing.Values<-ifelse(NAs>0,"Missing Value"," ")
missing.value<-data.frame(Case.Number,Missing.Values)
missing.values<-missing.value[ which(Missing.Values=='Missing Value'),]
list("NUMERIC DATA","DESCRIPTIVES"=t(descriptives),"CASE # OF MISSING 
VALUES"=missing.values[,1])
}
else{
n<-length(variable)
NAs<-is.na(variable)
total.NA<-sum(NAs)
percent.missing<-total.NA/n
descriptives<-data.frame(n,total.NA,percent.missing)
rownames(descriptives)<-c(" ")
Case.Number<-1:n
Missing.Values<-ifelse(NAs>0,"Missing Value"," ")
missing.value<-data.frame(Case.Number,Missing.Values)
missing.values<-missing.value[ which(Missing.Values=='Missing Value'),]
list("CATEGORICAL DATA","DESCRIPTIVES"=t(descriptives),"CASE # OF MISSING 
VALUES"=missing.values[,1])
}
}
dataset<-data.frame(dataset)
options(scipen=100)
options(digits=2)
lapply(dataset,find.NA)
} 
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Sequential multiple regression

2011-03-31 Thread Tyler Rinker

Bert and anyone else with info,
 
First, Bert thank you for your quick reply.  drop1 gives the results as a type 
II anova.  Is there a way to make drop1 give you type I anova (the args don't 
appear to have a way to do so)?  Another package/function perhaps?
 
Tyler 
 
> Date: Thu, 31 Mar 2011 09:32:02 -0700
> Subject: Re: [R] Sequential multiple regression
> From: gunter.ber...@gene.com
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> 
> ?drop1
> 
> -- Bert
> 
> On Thu, Mar 31, 2011 at 9:24 AM, Tyler Rinker  
> wrote:
> >
> > Hello,
> >
> > In the past I have tended to reside more in the ANOVA camp but am trying to 
> > become more familiar with regression techniques in R.  I would like to get 
> > the F change from a model as I take away factors:
> >
> > SO...
> >
> > mod1<-lm(y~x1+x2+x3)...mod2<-lm(y~x1,x2)...mod3<-lm(y~x1)
> >
> >
> > I can do this by hand by running several models in R and taking the 
> > MSr1/MSe1, MSr2/MSe2...  This is slow and I know there's a better way.
> >
> > In SPSS (which I no longer use) I could easily obtain these results 
> > (F-change) as documented by Professor Andy Fields:
> > http://www.statisticshell.com/multireg.pdf
> >
> > You can see the F changes for his two IV model yielding 2 F changes.  Maybe 
> > it's the language I'm using (sequential multiple regression) that yields me 
> > poor results in searching the archives and Rseek.  The results tend to be 
> > around hierarchal regression (I'm not familiar with this terminology being 
> > in the ANOVA camp).  When I look at the hier.part package and run the 
> > examples it doesn't seem to give me the F change I'm looking for.  The step 
> > function in the base program reduces the model but takes away the non sig. 
> > IV's (which is a great approach but I'm really after those F changes).  As 
> > is the usually the case I'm sure R does this simply and beautifully, I'm 
> > just not experienced with the statistical vocabulary and techniques around 
> > regression to find what I'm looking for.
> >
> > F-change values with R:  Any help would be appreciated.
> >
> > Thank you in advance,
> > Tyler
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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.
> >
> 
> 
> 
> -- 
> "Men by nature long to get on to the ultimate truths, and will often
> be impatient with elementary studies or fight shy of them. If it were
> possible to reach the ultimate truths without the elementary studies
> usually prefixed to them, these would not be preparatory studies but
> superfluous diversions."
> 
> -- Maimonides (1135-1204)
> 
> Bert Gunter
> Genentech Nonclinical Biostatistics
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Sequential multiple regression

2011-03-31 Thread Tyler Rinker

Hello,
 
In the past I have tended to reside more in the ANOVA camp but am trying to 
become more familiar with regression techniques in R.  I would like to get the 
F change from a model as I take away factors:
 
SO...
 
mod1<-lm(y~x1+x2+x3)...mod2<-lm(y~x1,x2)...mod3<-lm(y~x1)
 
 
I can do this by hand by running several models in R and taking the MSr1/MSe1, 
MSr2/MSe2...  This is slow and I know there's a better way.
 
In SPSS (which I no longer use) I could easily obtain these results (F-change) 
as documented by Professor Andy Fields:
http://www.statisticshell.com/multireg.pdf
 
You can see the F changes for his two IV model yielding 2 F changes.  Maybe 
it's the language I'm using (sequential multiple regression) that yields me 
poor results in searching the archives and Rseek.  The results tend to be 
around hierarchal regression (I'm not familiar with this terminology being in 
the ANOVA camp).  When I look at the hier.part package and run the examples it 
doesn't seem to give me the F change I'm looking for.  The step function in the 
base program reduces the model but takes away the non sig. IV's (which is a 
great approach but I'm really after those F changes).  As is the usually the 
case I'm sure R does this simply and beautifully, I'm just not experienced with 
the statistical vocabulary and techniques around regression to find what I'm 
looking for.
 
F-change values with R:  Any help would be appreciated.
 
Thank you in advance,
Tyler 
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Using the mahalanobis( ) function

2011-03-22 Thread Tyler Rinker

In my haste I did not include the full printout of my R session.  My apologies.
 
 nd<-read.table("ex20.csv", header=TRUE, sep=",",na.strings="NA")
attach(nd)
age.frame<-data.frame(Age, Friend.Agression, Parent.Agression, 
Stranger.Agression)
> age.frame
   Age Friend.Agression Parent.Agression Stranger.Agression
1y87  8
2y56  8
3y63  7
4y55  7
5m   15   13 10
6m   13   11  9
7m   12   12  9
8m   18   10  7
9o   11   11 10
10   o   104 12
11   o   129 12
12   o98 14
13   y   137  7
14   y95 10
15   y   114  4
16   y   153  4
17   m   14   12  8
18   m   10   15 11
19   m   12   11  8
20   m   109  9
21   o   108 11
22   o   13   11 13
23   o98 12
24   o79 16
ay<-subset(nd,Age=="y")
> ay
   Gender Age Friend.Agression Parent.Agression Stranger.Agression
1   f   y87  8
2   f   y56  8
3   f   y63  7
4   f   y55  7
13  m   y   137  7
14  m   y95 10
15  m   y   114  4
16  m   y   153  4
> am<-subset(nd,Age=="m")
> am
   Gender Age Friend.Agression Parent.Agression Stranger.Agression
5   f   m   15   13 10
6   f   m   13   11  9
7   f   m   12   12  9
8   f   m   18   10  7
17  m   m   14   12  8
18  m   m   10   15 11
19  m   m   12   11  8
20  m   m   109  9
> ao<-subset(nd,Age=="o")
> ao
   Gender Age Friend.Agression Parent.Agression Stranger.Agression
9   f   o   11   11 10
10  f   o   104 12
11  f   o   129 12
12  f   o98 14
21  m   o   108 11
22  m   o   13   11 13
23  m   o98 12
24  m   o79 16
> amm<-cbind(am$Friend.Agression, am$Parent.Agression,am$Stranger.Agression)
> amm
 [,1] [,2] [,3]
[1,]   15   13   10
[2,]   13   119
[3,]   12   129
[4,]   18   107
[5,]   14   128
[6,]   10   15   11
[7,]   12   118
[8,]   1099
> aym<-cbind(ay$Friend.Agression, ay$Parent.Agression,ay$Stranger.Agression)
> aym
 [,1] [,2] [,3]
[1,]878
[2,]568
[3,]637
[4,]557
[5,]   1377
[6,]95   10
[7,]   1144
[8,]   1534
> aom<-cbind(ao$Friend.Agression, ao$Parent.Agression,ao$Stranger.Agression)
> aom
 [,1] [,2] [,3]
[1,]   11   11   10
[2,]   104   12
[3,]   129   12
[4,]98   14
[5,]   108   11
[6,]   13   11   13
[7,]98   12
[8,]79   16

> mean(aym)
[1] 6.958333
> mean(amm)
[1] 11.16667
> mean(aom)
[1] 10.375
> ascores<-cbind(Friend.Agression, Parent.Agression, Stranger.Agression)
> ascores
  Friend.Agression Parent.Agression Stranger.Agression
 [1,]87  8
 [2,]56  8
 [3,]63  7
 [4,]55  7
 [5,]   15   13 10
 [6,]   13   11

[R] Using the mahalanobis( ) function

2011-03-22 Thread Tyler Rinker

I want to calculate the Manhalanobis D as an effect size for a follow up to a 
MANOVA.  I think I'm getting further but still not there.  No one has weighed 
in yet to lend help and I would much appreciate it, particulalry those who are 
familiar with cluster analysis or MANOVA follow up/effect sizes.  
 
According to my stats professor I know the Mahalanobis D should be 3.93 & 3.04 
for the distance between the center of the y to m cluster and the center of the 
m to o cluster respectively (groups under the Age variable).  I get 4.233462 &  
3.857911 respectively.  I'm still messing it up.

So far here is what I've done:
 
> am
   Gender Age Friend.Agression Parent.Agression Stranger.Agression
5   f   m   15   13 10
6   f   m   13   11  9
7   f   m   12   12  9
8   f   m   18   10  7
17  m   m   14   12  8
18  m   m   10   15 11
19  m   m   12   11  8
20  m   m   109  9
> ao<-subset(nd,Age=="o")
> ao
   Gender Age Friend.Agression Parent.Agression Stranger.Agression
9   f   o   11   11 10
10  f   o   104 12
11  f   o   129 12
12  f   o98 14
21  m   o   108 11
22  m   o   13   11 13
23  m   o98 12
24  m   o79 16
> amm<-cbind(am$Friend.Agression, am$Parent.Agression,am$Stranger.Agression)
> amm
 [,1] [,2] [,3]
[1,]   15   13   10
[2,]   13   119
[3,]   12   129
[4,]   18   107
[5,]   14   128
[6,]   10   15   11
[7,]   12   118
[8,]   1099
> aym<-cbind(ay$Friend.Agression, ay$Parent.Agression,ay$Stranger.Agression)
> aym
 [,1] [,2] [,3]
[1,]878
[2,]568
[3,]637
[4,]557
[5,]   1377
[6,]95   10
[7,]   1144
[8,]   1534
> aom<-cbind(ao$Friend.Agression, ao$Parent.Agression,ao$Stranger.Agression)
> aom
 [,1] [,2] [,3]
[1,]   11   11   10
[2,]   104   12
[3,]   129   12
[4,]98   14
[5,]   108   11
[6,]   13   11   13
[7,]98   12
[8,]79   16

> mean(aym)
[1] 6.958333
> mean(amm)
[1] 11.16667
> mean(aom)
[1] 10.375
> ascores<-cbind(Friend.Agression, Parent.Agression, Stranger.Agression)
> ascores
  Friend.Agression Parent.Agression Stranger.Agression
 [1,]87  8
 [2,]56  8
 [3,]63  7
 [4,]55  7
 [5,]   15   13 10
 [6,]   13   11  9
 [7,]   12   12  9
 [8,]   18   10  7
 [9,]   11   11 10
[10,]   104 12
[11,]   129 12
[12,]98 14
[13,]   137  7
[14,]95 10
[15,]   114  4
[16,]   153  4
[17,]   14   12  8
[18,]   10   15 11
[19,]   12   11  8
[20,]   109  9
[21,]   108 11
[22,]   13   11 13
[23,]98 12
[24,]79 16
> mean(ascores)
[1] 9.5
meany<-colMeans(aym, na.rm = FALSE, dims = 1)
meany
meanm<-colMeans(amm, na.rm = FALSE, dims = 1)
meanm
meano<-colMeans(aom, na.rm = FALSE, dims = 1)
meano
> S<-cov(ascores)
> S
   Friend.Agression Parent.Agression Stranger.Agression
Friend.Agression  10.476449 4.461957  -2.003623
Parent.Agression   4.46195710.940217   3.489130
Stranger.Agression-2.003623 3.489130   8.427536
> meany<-colMeans(x, na.rm = FALSE, dims = 1)
Error in inherits(x, "data.frame") : object 'x' not found
> meany<-colMeans(aym, na.rm = FALSE, dims = 1)
> meany
[1] 9.000 5.000 6.875
> meanm<-colMeans(amm, na.rm = 

Re: [R] Looking for a repeated measure two groups comparison and a two factor ANOVA in Circular distribution

2011-03-22 Thread Tyler Rinker

I don't know if this is what you're looking for but it describes how to do a 2 
way repeated measures with R.  You problem may be different and I lack the 
stats knowledge to know that.  If that's the case I apoligize:

http://rtutorialseries.blogspot.com/2011/02/r-tutorial-series-two-way-repeated.html
 
Tyler
 
From: tintin...@hotmail.com
To: r-help@r-project.org
Date: Tue, 22 Mar 2011 15:56:27 +0100
Subject: [R] Looking for a repeated measure two groups comparison and a two 
factor ANOVA in Circular distribution

 
Hi,
I am looking for a way to study some phase data with a circular distribution 
measured in rad.I would like to do a two way ANOVA (if possible mixed, with 
inter and intrasubject).I haven´t found a package that does that in R?Does 
sombeody know if there is one or how to do the analysis.Thanks in advance
J ToledoCNDR UPenn
[[alternative HTML version deleted]]
 

__ R-help@r-project.org mailing 
list 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
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] Using the mahalanobis( ) function

2011-03-21 Thread Tyler Rinker

This is what I've tried so far and just can't get it.  I know I want a value of 
3.93 (for Age= y and m) using mahalanobis d as an effect size for a follow up 
to an MANOVA:
 
age.frame<-data.frame(Age, Friend.Agression, Parent.Agression, 
Stranger.Agression)
> age.frame
   Age Friend.Agression Parent.Agression Stranger.Agression
1y87  8
2y56  8
3y63  7
4y55  7
5m   15   13 10
6m   13   11  9
7m   12   12  9
8m   18   10  7
9o   11   11 10
10   o   104 12
11   o   129 12
12   o98 14
13   y   137  7
14   y95 10
15   y   114  4
16   y   153  4
17   m   14   12  8
18   m   10   15 11
19   m   12   11  8
20   m   109  9
21   o   108 11
22   o   13   11 13
23   o98 12
24   o79 16
 
ay<-subset(nd,Age=="y")
> ay
   Gender Age Friend.Agression Parent.Agression Stranger.Agression
1   f   y87  8
2   f   y56  8
3   f   y63  7
4   f   y55  7
13  m   y   137  7
14  m   y95 10
15  m   y   114  4
16  m   y   153  4
> am<-subset(nd,Age=="m")
> am
   Gender Age Friend.Agression Parent.Agression Stranger.Agression
5   f   m   15   13 10
6   f   m   13   11  9
7   f   m   12   12  9
8   f   m   18   10  7
17  m   m   14   12  8
18  m   m   10   15 11
19  m   m   12   11  8
20  m   m   109  9
> ao<-subset(nd,Age=="o")
> ao
   Gender Age Friend.Agression Parent.Agression Stranger.Agression
9   f   o   11   11 10
10  f   o   104 12
11  f   o   129 12
12  f   o98 14
21  m   o   108 11
22  m   o   13   11 13
23  m   o98 12
24  m   o79 16
> amm<-cbind(am$Friend.Agression, am$Parent.Agression,am$Stranger.Agression)
> amm
 [,1] [,2] [,3]
[1,]   15   13   10
[2,]   13   119
[3,]   12   129
[4,]   18   107
[5,]   14   128
[6,]   10   15   11
[7,]   12   118
[8,]   1099
> aym<-cbind(ay$Friend.Agression, ay$Parent.Agression,ay$Stranger.Agression)
> aym
 [,1] [,2] [,3]
[1,]878
[2,]568
[3,]637
[4,]557
[5,]   1377
[6,]95   10
[7,]   1144
[8,]   1534
> aom<-cbind(ao$Friend.Agression, ao$Parent.Agression,ao$Stranger.Agression)
> aom
 [,1] [,2] [,3]
[1,]   11   11   10
[2,]   104   12
[3,]   129   12
[4,]98   14
[5,]   108   11
[6,]   13   11   13
[7,]98   12
[8,]79   16
 
 
> mean(aym)
[1] 6.958333
> mean(amm)
[1] 11.16667
> mean(aom)
[1] 10.375
 
> ascores<-cbind(Friend.Agression, Parent.Agression, Stranger.Agression)
> ascores
  Friend.Agression Parent.Agression Stranger.Agression
 [1,]87  8
 [2,]56  8
 [3,]63  7
 [4,]55  7
 [5,]   15   13 10
 [6,]  

[R] Using the mahalanobis( ) function

2011-03-21 Thread Tyler Rinker

Hello all,
 
I am a 2 month newbie to R and am stumped.  I have a data set that I've run 
multivariate stats on using the manova function (I included the data set).  Now 
it comes time for a table of effect sizes with significance.  The univariate 
tests are easy.  Where I run into trouble filling in the table of effect sizes 
is the Mahalanobis D as an effect size.  I've included the table so you can see 
what group's I'm comparing.  I know there's a great function for filling in ?1 
and ?2 : mahalanobis(x, center, cov, inverted=FALSE, ...)  I need to turn the 
sub groups scores for y (young), m (middle) and o (old) into clusters.

The problem is I lack the knowledge around cluster analysis of what goes into 
the function for [x, center, & cov.]  I have only a basic understanding of this 
topic (a picture of a measured distance between two clusters on a graph).  I 
think I have to turn the data into a matrix but lack direction.  Could someone 
please use my data set or a similar one (a multivariate with at least 3 outcome 
variables) and actually run this function (mahalanobis).  Then please send me 
your output from [R] starting from the data set all the way to the statistic.  
PS I know the Mahalanobis D should be ?1=3.93 & ?2=3.04.
 
I’ve read and reread the manual around mahalanobis() and have searched through 
the list serve for information.  The info is for people who already have a 
grasp of how to implement this concept.
 
I am running the latest version of R on a windows 7 machine.  
 
Effect Sizes 
Contrasts|   Dependent Variables
  Friends  ParentsStrangersAll  
 
Young-Middle  -1.8768797* -3.2842941* -1.1094004*  ?1   
 
Middle-Old1.34900725* 1.54919532* -2.0107882*  ?2   

 
(sorry the column names and values don’t line up)
Age  Friend Agression Parent Agression Stranger Agression
y  8  7  8
y  5  6  8
y  6  3  7
y  5  5  7
m 151310
m 13119
m 12129
m 18107
o  111110
o  104  12
o  129  12
o  9  8  14
y  137  7
y  9  5  10
y  114  4
y  153  4
m 14128
m 101511
m 12118
m 109  9
o  108  11
o  131113
o  9  8  12
o  7  9  16   
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Using the Mahalanobis Function

2011-03-20 Thread Tyler Rinker

My aplogies:
 
The Table of effects did not come through as I had intended them to.  HEre they 
are reformatted:
Again I would like to see someone actually run mahalanobis() for this data set 
to arrive at ?1 and ?2.  I do not know what exactly (after reading the manual) 
goes in for x,center,or cov.  Seeing an actual [R] printout of it being done 
(from start to finish) would go a long way towards my learning.
 
 
 
Effect Sizes 
Contrasts|   Dependent Variables
  Friends  Parents  Strangers All   

Young-Middle  -1.8768797*   -3.2842941*   -1.1094004*   ?1
Middle-Old1.34900725*   1.54919532*   -2.0107882*   ?2
 
 
 
 
Gender Age, Friend.Agression, Parent.Agression, Stranger.Agression
1 f y 8 7 8
2 f y 5 6 8
3 f y 6 3 7
4 f y 5 5 7
5 f m 15 13 10
6 f m 13 11 9
7 f m 12 12 9
8 f m 18 10 7
9 f o 11 11 10
10 f o 10 4 12
11 f o 12 9 12
12 f o 9 8 14
13 m y 13 7 7
14 m y 9 5 10
15 m y 11 4 4
16 m y 15 3 4
17 m m 14 12 8
18 m m 10 15 11
19 m m 12 11 8
20 m m 10 9 9
21 m o 10 8 11
22 m o 13 11 13
23 m o 9 8 12
24 m o 7 9 16

 
> From: tyler_rin...@hotmail.com
> To: r-help@r-project.org
> Date: Sun, 20 Mar 2011 01:53:47 -0400
> Subject: [R] Using the Mahalanobis Function
> 
> 
> 
> 
> 
> Hello all,
> 
> I am a 2 month newbie to R and am stumped. I have a data set that I've run 
> multivariate stats on using the manova function (I included the data set). 
> Now it comes time for a table of effect sizes with significance. The 
> univariate tests are easy. Where I run into trouble filling in the table of 
> effect sizes is the Mahalanobis D as an effect size. I've included the table 
> so you can see what group's I'm comparing. I know there's a great function 
> for filling in ?1 and ?2 : mahalanobis(x, center, cov, inverted=FALSE, ...)
> 
> The problem is I lack the knowledge around cluster analysis of what goes into 
> the function for [x, center, & cov.] I have only a basic understanding of 
> this topic (a picture of a measured distance between two clusters on a 
> graph). Could someone please use my data set or a similar one (a multivariate 
> with at least 3 outcome variables) and actually run this function 
> (mahalanobis). Then please send me your output from [R] starting from the 
> data set all the way to the statistic. PS I know the Mahalanobis D should be 
> ?1=3.93 & ?2=3.04.
> 
> The Y,M,O in the data set stands for young, middle, old.
> 
> I am running the latest version of R on a windows 7 machine. 
> 
> 
> 
> 
> 
> 
> Effect Sizes
> 
> 
> 
> Contrasts
> 
> Dependent Variables
> 
> 
> 
> 
> 
> 
> Friends
> 
> Parents
> 
> Strangers
> 
> All
> 
> 
> Young-Middle
> 
> -1.8768797*
> 
> -3.2842941*
> 
> -1.1094004*
> 
> ?1
> 
> 
> Middle-Old
> 
> 1.34900725*
> 
> 1.54919532*
> 
> -2.0107882*
> 
> ?2
> 
> Gender Age Friend.Agression Parent.Agression Stranger.Agression
> 1 f y 8 7 8
> 2 f y 5 6 8
> 3 f y 6 3 7
> 4 f y 5 5 7
> 5 f m 15 13 10
> 6 f m 13 11 9
> 7 f m 12 12 9
> 8 f m 18 10 7
> 9 f o 11 11 10
> 10 f o 10 4 12
> 11 f o 12 9 12
> 12 f o 9 8 14
> 13 m y 13 7 7
> 14 m y 9 5 10
> 15 m y 11 4 4
> 16 m y 15 3 4
> 17 m m 14 12 8
> 18 m m 10 15 11
> 19 m m 12 11 8
> 20 m m 10 9 9
> 21 m o 10 8 11
> 22 m o 13 11 13
> 23 m o 9 8 12
> 24 m o 7 9 16
> 
> [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] Using the Mahalanobis Function

2011-03-19 Thread Tyler Rinker




Hello all,
 
I am a 2 month newbie to R and am stumped.  I have a data set that I've run 
multivariate stats on using the manova function (I included the data set).  Now 
it comes time for a table of effect sizes with significance.  The univariate 
tests are easy.  Where I run into trouble filling in the table of effect sizes 
is the Mahalanobis D as an effect size.  I've included the table so you can see 
what group's I'm comparing.  I know there's a great function for filling in ?1 
and ?2 : mahalanobis(x, center, cov, inverted=FALSE, ...)

The problem is I lack the knowledge around cluster analysis of what goes into 
the function for [x, center, & cov.]  I have only a basic understanding of this 
topic (a picture of a measured distance between two clusters on a graph).  
Could someone please use my data set or a similar one (a multivariate with at 
least 3 outcome variables) and actually run this function (mahalanobis).  Then 
please send me your output from [R] starting from the data set all the way to 
the statistic.  PS I know the Mahalanobis D should be ?1=3.93 & ?2=3.04.
 
The Y,M,O in the data set stands for young, middle, old.
 
I am running the latest version of R on a windows 7 machine.  
 





Effect Sizes



Contrasts

Dependent Variables

 

 


Friends

Parents

Strangers

All


Young-Middle

-1.8768797*

-3.2842941*

-1.1094004*

?1


Middle-Old

1.34900725*

1.54919532*

-2.0107882*

?2
 
  Gender Age Friend.Agression Parent.Agression Stranger.Agression
1   f   y87  8
2   f   y56  8
3   f   y63  7
4   f   y55  7
5   f   m   15   13 10
6   f   m   13   11  9
7   f   m   12   12  9
8   f   m   18   10  7
9   f   o   11   11 10
10  f   o   104 12
11  f   o   129 12
12  f   o98 14
13  m   y   137  7
14  m   y95 10
15  m   y   114  4
16  m   y   153  4
17  m   m   14   12  8
18  m   m   10   15 11
19  m   m   12   11  8
20  m   m   109  9
21  m   o   108 11
22  m   o   13   11 13
23  m   o98 12
24  m   o79 16
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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 do I delete multiple blank variables from a data frame?

2011-03-19 Thread Tyler Rinker

I actually prefer to do this portion of the work (data prep) inside of excel.  
When you export the data as an cvs doc the NA's will be in the excel 
spreadsheet.  Now the search and/or the search and replace option become very 
handy.  Probably a better way in [R] though.
 
Tyler

 
> Date: Fri, 18 Mar 2011 18:35:20 -0700
> From: jwiley.ps...@gmail.com
> To: ritacarre...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] How do I delete multiple blank variables from a data frame?
> 
> Hi Rita,
> 
> This is far from the most efficient or elegant way, but:
> 
> ## two column data frame, one all NAs
> d <- data.frame(1:10, NA)
> ## use apply to create logical vector and subset d
> d[, apply(d, 2, function(x) !all(is.na(x)))]
> 
> I am just apply()ing to each column (the 2) of d, the function
> !all(is.na(x)) which will return FALSE if all of x is missing and TRUE
> otherwise. The result is a logical vector the same length as the
> number of columns in d that is used to subset only the d columns with
> at least some non-missing values. For documentation see:
> 
> ?apply
> ?is.na
> ?all
> ?"["
> ?Logic
> 
> HTH,
> 
> Josh
> 
> On Fri, Mar 18, 2011 at 3:35 PM, Rita Carreira  
> wrote:
> >
> > Dear List Members,I have 55 data frames, each of which with 272 variables 
> > and 267 observations. Some of these variables are blanks but the blanks are 
> > not the same for every data frame. I would like to write a procedure in 
> > which I import a data frame, see which variables are blank, and delete 
> > those variables. My data frames have variables named P1 to P136 and Q1 to 
> > Q136.
> > I have a couple of questions regarding this issue:
> > 1) Is a loop an efficient way to address this problem? If not, what are my 
> > alternatives and how do I implement them?2) I have been playing with a 
> > single data frame to try to figure out a way of having R go through the 
> > columns and see which ones it should delete. I have figured out how to 
> > delete rows with missing data (newdata <- na.omit(olddata)) but how do I do 
> > it for columns???
> > Thank you very much for your help and have a great weekend!
> > Rita  "If you think education is 
> > expensive, try ignorance"--Derek Bok
> >
> >
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > 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.
> >
> 
> 
> 
> -- 
> Joshua Wiley
> Ph.D. Student, Health Psychology
> University of California, Los Angeles
> http://www.joshuawiley.com/
> 
> __
> R-help@r-project.org mailing list
> 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
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] AOV() may misslabel random effects.

2011-03-15 Thread Tyler Rinker

Mr. Giles Crane,
 
I am new to R (only a month in).  My response is as best as I understand the 
workings of R (so if I'm wrong more experienced people plese help me out).
 
AOV is not really appropriate for an unbalanced model.  This is where you can 
rely on the lm() function using these steps:
(I find it easiest to show you with a real data set)
student gender male female computer
11   male  7.09.5  6.0
22   male  7.57.0  4.0
33   male  6.07.0  2.5
44   male  4.08.0  3.0
55   male  7.5   10.0  3.5
.
.
n  etc...
 
1)  Create a vector of levels for the measurement  points (1 for each 
measurement point):
 
meals <- c(1, 2, 3)
 
Where meals is the new vector name (a factor), and the numbers represent each 
measurement point.
 
2)  Create a within groups measurement point factor to house the levels you 
just created (this will be used later in our data frame(matrix style)) and in 
our Anova anaylsis):
 
meal.factor<- as.factor(meals)
 
Where meal.factor is the new factor with n levels to house our levels that 
describe our n numeric columns(measurement points).
 
3)  Create a matrix style data frame from the factor and levels that will 
be used to describe our numeric columns(measurement points):
 
meal.frame <- data.frame(meal.factor)
 
4)  Now create a bound vector containing the n numeric columns for later 
use in the linear model:
 
meal.bind<-cbind(breakfast , lunch, dinner)
 
5)  Create a linear model with the bound vector you just created.
 
meal.model<-lm(meal.bind~1)
 
6)  Use the Anova function from the car package to analyze our data (notice 
we are using the measurement point matrix style data frame and corresponding 
within groups factors as well as the linear model we just created):

 
analysis3 <- Anova(meal.model, idata = meal.frame, idesign = ~meal.factor) 
 
Note: we could have added the argument ,type=”III” but the default of Anova is 
to switch from type II to type III SS when there is only one intercept
 
7)  Now create a summary of the anova tables and information:
   summary(analysis)Look below at the summary:
 
NOTE: Aova (from car) will give you type II SS and you can also specify type 
III SS using the ,type=”III” argument at the end of step 6.  The function anove 
on step 6 gives you type I SS.  Research each one of these SS and detemrine 
what works best for you.   

 
 
 
 
> From: pda...@gmail.com
> Date: Mon, 14 Mar 2011 20:58:17 +0100
> To: gilescr...@verizon.net
> CC: r-help@r-project.org
> Subject: Re: [R] AOV() may misslabel random effects.
> 
> 
> On Mar 14, 2011, at 17:57 , Giles Crane wrote:
> 
> > Greetings,
> > 
> > The aov() function may mislabel
> > the random effects as in the example below:
> > Has anybody else noticed this?
> 
> What's "mislabeled" about it??? Looks like you nave an unbalanced design (in 
> which case, aov() may be the wrong tool.)
> 
> -pd
> 
> > 
> > Cordially,
> > Giles Crane, MPH, ASA, NJPHA
> > gilescr...@verizon.net
> > 
> > > m2
> > 
> > Call:
> > aov(formula = y ~ ap + pe + Error(ju), data = d)
> > 
> > Grand Mean: 77.50667
> > 
> > Stratum 1: ju
> > 
> > Terms:
> > ap
> > Sum of Squares 4322.538
> > Deg. of Freedom 12
> > 
> > 13 out of 25 effects not estimable
> > Estimated effects may be unbalanced
> > 
> > Stratum 2: Within
> > 
> > Terms:
> > ap pe Residuals
> > Sum of Squares 7047.885 255.034 2981.290
> > Deg. of Freedom 25 2 35
> > 
> > Residual standard error: 9.229285
> > Estimated effects may be unbalanced
> > 
> > __
> > R-help@r-project.org mailing list
> > 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.
> 
> -- 
> Peter Dalgaard
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd@cbs.dk Priv: pda...@gmail.com
> 
> __
> R-help@r-project.org mailing list
> 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
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] Passing a character argument onto a function

2011-03-11 Thread Tyler Rinker

I am a new R user and am beginning to employ function creation in my 
statistical work.  I am running into a problem when I want to pass on a 
character (text) to the function as an argument.  I have a simple example below 
to demonstrate this problem.  I cannot seem to find a fix in my R book or in 
the blog posts.  I'm sure this has been covered before but my newbie status 
means I lack the R vocabulary to even search for this problem (I've tried for a 
few days to no avail).  Someone has already attempted to explain this to me.  I 
learn best by seeing.  Could someone rewrite my code so that the function 
works.  The function is very simple as is the data set so it should be pretty 
easy for an experienced R user to correct.  The problem is that R doesn't 
transfer the "blue" subgroup from the argument to the function.  I am excited 
with the potential of R and look forward to your help.
 
I am a Windows user running R 2.12.2

 
CODE for TEST FUNCTION
> TEST<-function(DV,IV,group1) {
+  g1<-DV[IV=="group1"]
+  p<-mean(g1)
+ list(g1,p)
+ }

R's OUTPUT
> TEST(frequency,color,blue)
[[1]]
integer(0)
[[2]]
[1] NaN

 
The DATA FRAME
TEST<-read.table("TEST.csv", header=TRUE, sep=",",na.strings="999")
> attach(TEST)

  color frequency
1  blue 3
2  blue 4
3  blue 3
4 green 5
5 green 2
6 green 4
7 green 5
8 green 1
  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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 writing a Scheffe Contrast function for R

2011-03-09 Thread Tyler Rinker








Hello,
 
As a new  user of R (less than a month) I have got my hands on several books 
and am pouting through the net looking for help in gaining understanding of 
this powerful tool.  I am becoming more proficient with using basic functions 
to conduct basic statistics.  I am now looking to learn how to write code.  
After a few small worthless functions I decided to try to create a function 
that was of real use, a Scheffe test for doing post hoc comparisons.  I am not 
aware of any functions written for this though there may be some.  I wrote the 
function and have run each line of the function through R.  It seems to work 
(though can use some improvements later on by splicing code from aov or anova 
functions to eliminate the need for inputting the MSw).  The problem is when i 
try to run the code as a whole I get several error messages that I don't know 
how to fix (despite searching).  The output section seems to be error riddled.  
I wanted the output to display a message of not sig or s!
 ig as well as means and n for both groups and the total N, as well as the 
t-value and critical t.  I am using a formula supplied by a professor for 
Scheffe (when comparing two groups): 
 
critical value--> k=sqrt((J-1)FJ-1,N-J,alpha)
test stat-->(mean1-mean2)/(sqrt(MSw((1^2)/n1)+(1^2)/n2)))
 
I am a windows 7 user with the latest version of R.
 
My Question:  What do I need to do to correct the three error codes R gives me 
and make the function run correctly?
 
This is the session, code and R's error message when supplied with data: 
> rm(list=ls())
> dat1<-read.table("dat1.csv", header=TRUE, sep=",",na.strings="999")
> attach(dat1)
> dat1
   student  rti score
11   ns 2
22   ns 5
33   ns 2
44   ns11
55 wk2o10
66 wk2o11
77 wk2o 7
88 wk2o12
99 wk5o12
10  10 wk5o12
11  11 wk2w 5
12  12 wk2w 6
13  13 wk2w12
14  14 wk5w 5
15  15 wk5w 6
16  16 wk5w13
> anova(lm(score~rti))
Analysis of Variance Table
Response: score
  Df  Sum Sq Mean Sq F value Pr(>F)
rti4  83.771  20.943  1.7107 0.2174
Residuals 11 134.667  12.242   
> #so MSw is 12.242
> 
> #my code for scheffe's post hoc comparison
> 
> scheffe<- function(IV,DV,data,group1,group2,MSw,alpha) {
+  result<-0
+  J<-length(levels(IV))
+  d1<-subset(data, IV == "group1") 
+  d2<-subset(data, IV == "group2")
+  g1<-d1$DV
+  g2<-d2$DV
+  y.1<-mean(g1)
+  y.2<-mean(g2) 
+  n1<- length(g1)
+  n2<- length(g2)
+  N<-length(IV)
+  psi.hat<-y.1-y.2
+  se.psi.hat<- sqrt(MSw*((1/n1)+(1/n2)))
+  t<- psi.hat/se.psi.hat
+  t.compare<-abs(t)
+  k<-sqrt((J-1)*( qf((1-alpha),(J-1),(N-J
+   if(t.compare > k) return<-c("reject H0") else result<- c("accept H0")
+   return(list(cbind(result)), Mean.Group.1 = y.1,n.for.1=n1,   
+   Mean.Group.2=y.2,n.for.2=n2,N.Data=N,tValue=t,critical.value=k)
+  }
> #
> #doesn't seem to be a problem thus far
> #let's enter some data
> 
> #scheffe(IV,DV,data,group1,group2,MSw,alpha)
> 
> scheffe(rti,score,dat1,ns,wk5o,12.242,.05)
Error in if (t.compare > k) return <- c("reject H0") else result <- c("accept 
H0") : 
  missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(g1) : argument is not numeric or logical: returning NA
2: In mean.default(g2) : argument is not numeric or logical: returning NA
> 

  
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.