Re: [R] [EXTERNAL] Attribute Combinations

2020-05-21 Thread Dalthorp, Daniel via R-help
# assuming your data frame is named "x", you can get the counts of each combo:

table(do.call(paste0, x)) 

# and to get the proportions:

table(do.call(paste0, x))/nrow(x)


-Original Message-
From: R-help  On Behalf Of Jeff Reichman
Sent: Thursday, May 21, 2020 10:22 AM
To: R-help@r-project.org
Subject: [EXTERNAL] [R] Attribute Combinations

R-help forum

 

Looking for a function or some guidance for obtaining the percentage of 
attribute combinations, for example

 

V1   V2   V3

A A B

A B C

A A D 

A A B

A A B

A B C

A C B 

A C B

A B C

A C C

 

Results

A,A,B 0.30

A,B,C 0.30

A,A,D0.10

A,C,B 0.20 etc

 

Sincerely

 

Jeff Reichman

(314) 457-1966

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [EXTERNAL] Re: "chi-square" | "chi-squared" | "chi squared" | "chi square" ?

2019-10-21 Thread Dalthorp, Daniel via R-help
Interesting!

Both UK and US show quite a bit more "square" than "squared" in your
sample, with maybe an even stronger tendency for "square" in US than in UK.

I like "squared" better because it fits better with standard English
pronunciation of, say, \sigma^2 or x^2 or r^2.




On Mon, Oct 21, 2019 at 9:46 AM Ivan Krylov  wrote:

> On Fri, 18 Oct 2019 15:25:59 -0700
> "Dalthorp, Daniel via R-help"  wrote:
>
> > I'd like to see the statistics on it before jumping to a conclusion
> > that the American preference is "chi-square" and the British
> > preference is "chi-squared".
>
> One way to get some data on this would be to count Scopus hits for
> various usages in articles with different affiliations, with a query
> like this:
>
> {}
> AND PUBYEAR > 1980
> AND AFFILCOUNTRY()
> AND NOT (
>  AFFILCOUNTRY()
>  OR {} OR {} OR {}
> )
>
> The year cutoff is here to show only the "modern usage" (the trends
> look the same whether I leave it in or not). Intersections (papers with
> authors from both countries and/or using more than one form) are a
> minority and don't seem to reverse any trends, either. Here are the
> results:
>
>   UKUS
> chi-square  4666 30159
> chi-squared 1374  4798
> chi square   769  3844
> chi squared  142   197
>
> "chi-square" seems to be the most popular form.
>
> --
> Best regards,
> Ivan
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 311
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [EXTERNAL] Re: "chi-square" | "chi-squared" | "chi squared" | "chi square" ?

2019-10-18 Thread Dalthorp, Daniel via R-help
oh my...

I'd like to see the statistics on it before jumping to a conclusion that
the American preference is "chi-square" and the British preference is
"chi-squared". I don't see that at all.

--
In keeping with the pronunciation of x^2 and 3^2, maybe "chi-squared" makes
the most sense,.

The "chi-square"? Because the iterated dentals in "chi-squared
distribution" and "chi-squared test" are a little cumbersome to pronounce,
an even slightly lazy pronunciation would sound like "chi-square
distribution" and "chi-square test". There's no need to write it that way
though.

-Dan



On Fri, Oct 18, 2019 at 2:28 PM Richard M. Heiberger  wrote:

> What a delightful question.  Bill Cochran discussed this in class
> one day about 50 years ago.  He said the British usage (which I think
> he said was chi-squared,
> as is consistent with the other memories in this thread)
> is what he learned and previously used.  But he had been in the US for
> so long that he was now using
> the American preference (chi-square).
>
> Rich
>
> On Fri, Oct 18, 2019 at 8:51 AM Martin Maechler
>  wrote:
> >
> > As it's Friday ..
> >
> > and I also really want to clean up help files and similar R documents,
> > both in R's own sources and in my new 'DPQ' CRAN package :
> >
> > As a trained mathematician, I'm uneasy if a thing has
> > several easily confusable names, .. but as somewhat
> > humanistically educated person, I know that natural languages,
> > English in this case, are much more flexible than computer
> > languages or math...
> >
> > Anyway, back to the question(s) .. which I had asked myself a
> > couple of months ago, and already remained slightly undecided:
> >
> > The 0-th (meta-)question of course is
> >
> >   0. Is it worth using only one written form for the
> >  χ² - distribution, e.g. "everywhere" in R?
> >
> > The answer is not obvious, as already the first few words of the
> > (English) Wikipedia clearly convey:
> >
> > The URL is  https://en.wikipedia.org/wiki/Chi-squared_distribution
> > and the main title therefore also
> > "Chi-squared distribution"
> >
> > Then it reads
> >
> > > This article is about the mathematics of the chi-squared
> > > distribution. For its uses in statistics, see chi-squared
> > > test. For the music [...]
> >
> > > In probability theory and statistics, the chi-square
> > > distribution (also chi-squared or χ2-distribution) with k
> > > degrees of freedom is the distribution of a sum of the squares
> > > of k independent standard normal random variables.
> >
> > > The chi-square distribution is a special case of the gamma
> > > distribution and is one of the most widely used probability
> > > distributions in inferential statistics, notably in hypothesis
> > > testing []
> > > []
> >
> > So, in title and 1st paragraph its "chi-squared", but then
> > everywhere(?) the text used "chi-square".
> >
> > Undoubtedly, Wilson & Hilferty (1931) has been an important
> > paper and they use "Chi-square" in the title;
> > also  Johnson, Kotz & Balakrishnan (1995)
> > see R's help page ?pchisq use  "Chi-square" in the title of
> > chapter 18 and then, diplomatically for chapter 29,
> >  "Noncentral χ²-Distributions" as title.
> >
> > So it seems, that historically and using prestigious sources,
> > "chi-square" to dominate (notably if we do not count "χ²" as an
> > alternative).
> >
> > Things look a bit different when I study R's sources; on one
> > hand, I find all 4 forms (s.Subject); then in the "R source
> > history", I see
> >
> >   $ svn log -c11342
> >
>  
> >   r11342 | <> | 2000-11-14 ...
> >
> >   Use `chi-squared'.
> >
>  
> >
> > which changed 16 (if I counted correctly) cases of 'chi-square' to
> 'chi-squared'.
> >
> > I have not found any R-core internal (or public) reasoning about
> > that change, but had kept it in mind and often worked along that "goal".
> >
> > As a consequence, "statistically" speaking, much of R's own use has been
> > standardized to use "chi-squared"; but as I mentioned, I still
> > find all  4  variants even in "R base" package help files
> > (which of course I now could quite quickly change  (using Emacs M-x
> grep, plus a script);
> > but
> >
> > ... "as it is Friday" ... I'm interested to hear what others
> > think, notably if you are native English (or "American" ;-)
> > speaking and/or have some extra good knowledge on such
> > matters...
> >
> > Martin Maechler
> > ETH Zurich
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list 

[R] cannot install gsl from source?

2019-06-18 Thread Dalthorp, Daniel via R-help
I've been working on a fairly extensive R package for a few years with
ongoing testing with Travis CI. Today, though, I'm seeing an error in
installing the gsl package both at Travis and from the Windows GUI:

install.packages("gsl",repos = getOption("repos"), repo=NULL, type="source")

# gives the following error sequence:

Installing package into ‘C:/Users/ddalthorp/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'http://cran.at.r-project.org/src/contrib/gsl_2.1-6.tar.gz'
Content type 'application/x-gzip' length 189794 bytes (185 KB)
downloaded 185 KB

* installing *source* package 'gsl' ...
** package 'gsl' successfully unpacked and MD5 sums checked

   **
   WARNING: this package has a configure script
 It probably needs manual configuration
   **

** libs

*** arch - i386
c:/Rtools/mingw_32/bin/gcc  -I"C:/PROGRA~1/R/R-35~1.2/include" -DNDEBUG
-I/include -O3 -Wall  -std=gnu99 -mtune=generic -c airy.c -o airy.o
airy.c:1:29: fatal error: gsl/gsl_sf_airy.h: No such file or directory
 #include 
 ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-35~1.2/etc/i386/Makeconf:208: airy.o] Error 1
ERROR: compilation failed for package 'gsl'


Any ideas?


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 311
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] [EXTERNAL] Re: create

2019-04-13 Thread Dalthorp, Daniel via R-help
how about one of the following?

vdat$xy <- 2 * (ifelse(is.na(vdat$x1), 0, vdat$x1)) + 5 *
(ifelse(is.na(vdat$x2),
0, vdat$x2)) + 3 * (ifelse(is.na(vdat$x3), 0, vdat$x3))

vdat$xy <- ifelse(is.na(as.matrix(vdat[, paste0("x", 1:3)])), 0,
as.matrix(vdat[, paste0("x", 1:3)])) %*% c(2, 5, 3)

On Sat, Apr 13, 2019 at 9:02 PM Val  wrote:

> Sorry for the confusion, my sample data  does not represent  the
> actual data set.
>
> The range of  value can be  from -ve to +ve values and 0 could be a
> true value of an observation. So, instead of replacing  missing value
> by zero, I want  exclude them  from the  calculation.
>
> On Sat, Apr 13, 2019 at 10:42 PM Jeff Newmiller
>  wrote:
> >
> > Looks to me like your initial request contradicts your clarification.
> Can you explain this discrepancy?
> >
> > On April 13, 2019 8:29:59 PM PDT, Val  wrote:
> > >Hi Bert and Jim,
> > >Thank you for the suggestion.
> > >However, those missing values should not be replaced by 0's.
> > >I want exclude those missing values from the calculation and create
> > >the index using only the non-missing values.
> > >
> > >
> > >On Sat, Apr 13, 2019 at 10:14 PM Jim Lemon 
> > >wrote:
> > >>
> > >> Hi Val,
> > >> For this particular problem, you can just replace NAs with zeros.
> > >>
> > >> vdat[is.na(vdat)]<-0
> > >> vdat$xy <- 2*(vdat$x1) + 5*(vdat$x2) + 3*(vdat$x3)
> > >> vdat
> > >>  obs Year x1 x2 x3  xy
> > >> 1   1 2001 25 10 10 130
> > >> 2   2 2001  0 15 25 150
> > >> 3   3 2001 50 10  0 150
> > >> 4   4 2001 20  0 60 220
> > >>
> > >> Note that this is not a general solution to the problem of NA values.
> > >>
> > >> Jim
> > >>
> > >> On Sun, Apr 14, 2019 at 12:54 PM Val  wrote:
> > >> >
> > >> > Hi All,
> > >> > I have a data frame  with several  columns  and I want to  create
> > >> > another  column  by using  the values of the other columns.  My
> > >> > problem is that some the row values  for some columns  have missing
> > >> > values  and I could not get  the result I waned .
> > >> >
> > >> > Here is the sample of my data and my attempt.
> > >> >
> > >> > vdat<-read.table(text="obs, Year, x1, x2, x3
> > >> > 1,  2001, 25 ,10, 10
> > >> > 2,  2001,  ,  15, 25
> > >> > 3,  2001,  50, 10,
> > >> > 4,  2001,  20, , 60",sep=",",header=TRUE,stringsAsFactors=F)
> > >> > vdat$xy <- 0
> > >> > vdat$xy <- 2*(vdat$x1) + 5*(vdat$x2) + 3*(vdat$x3)
> > >> > vdat
> > >> >
> > >> >  obs Year x1 x2 x3  xy
> > >> > 1   1 2001 25 10 10 130
> > >> > 2   2 2001 NA 15 25  NA
> > >> > 3   3 2001 50 10 NA  NA
> > >> > 4   4 2001 20 NA 60  NA
> > >> >
> > >> > The desired result si this,
> > >> >
> > >> >obs Year x1 x2 x3   xy
> > >> > 1   1 2001 25 10 10   130
> > >> > 2   2 2001 NA 15 25  150
> > >> > 3   3 2001 50 10 NA  150
> > >> > 4   4 2001 20 NA 60  220
> > >> >
> > >> > How do I get my desired result?
> > >> > Thank you
> > >> >
> > >> > __
> > >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > >> > https://stat.ethz.ch/mailman/listinfo/r-help
> > >> > PLEASE do read the posting guide
> > >http://www.R-project.org/posting-guide.html
> > >> > and provide commented, minimal, self-contained, reproducible code.
> > >
> > >__
> > >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > >https://stat.ethz.ch/mailman/listinfo/r-help
> > >PLEASE do read the posting guide
> > >http://www.R-project.org/posting-guide.html
> > >and provide commented, minimal, self-contained, reproducible code.
> >
> > --
> > Sent from my phone. Please excuse my brevity.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 311
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Getting Started

2017-01-10 Thread Dalthorp, Daniel
By "contribute", do you mean you have a package (or potential package) that
you'd like to share? Or do you have something else in mind?

-Dan

On Tue, Jan 10, 2017 at 9:33 AM, Lakshya Agrawal 
wrote:

> Hello,
>  I would like to contribute to R i have gone over the development page but
> could find anything on how to get started .Please can someone help me
> getting started. Sorry if i have overlooked something.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] transpose rows and columns for large data

2016-11-29 Thread Dalthorp, Daniel
Try David's suggestion to spell the argument "stringsAsFactors" correctly.
Then:

data <- read.table("your_file_location", sep ="\t", comment.char = "",
stringsAsFactors = F, header = T)
transpose_data <- t(data)

-Dan

On Tue, Nov 29, 2016 at 9:56 AM, Elham - via R-help 
wrote:

> yes you have right about excel.by R,what should I do for transposing row
> and column?
>
> On Tuesday, November 29, 2016 9:13 PM, David Winsemius <
> dwinsem...@comcast.net> wrote:
>
>
>
> > On Nov 29, 2016, at 9:22 AM, Elham - via R-help 
> wrote:
> >
> > Hi,
> >
> > I am trying to transpose large datasets inexcel (44 columns and 57774
> rows) but it keeps giving me the message we can'tpaste because copy area
> and paste area aren't the same size. Is there a way totranspose all the
> data at one time instead of piece by piece? One dataset has agreat amount
> of rows and columns.
> >
> > I tried this R function to transpose the datamatrix:
> >
> > data <- read.table("your_file_location", sep ="\t", comment.char = "",
> stringAsFactors = F, header = T)
> >
> >
> >
> > transpose_data <- t(data)
> >
> > But I received tis error:
> >
> > unused argument (stringAsFactors = F)
> >
>
> You misspelled that argument's name. And do learn to use FALSE and TRUE.
>
> >
> > Is there another way (I prefer a way with Excel)?
>
> This is not a help list for Excel.
>
>
> --
>
> David Winsemius
> Alameda, CA, USA
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tcltk table "validateCommand"

2016-11-17 Thread Dalthorp, Daniel
Yes, Peter's suggestion worked just right.

Here's an example that prints out the proposed cell content and will not
allow 'w' or '\n' to be entered into the table:

require(tcltk2)
tt<-tktoplevel(); tfr<-tkframe(tt); tkgrid(tfr)
tableData<-tclArray()

valChar<-function(S){
  print(S); flush.console()
  if (length(grep("\n",S))>0){ #
return(tcl("expr", FALSE))
  } else if (length(grep("w",S))>0){ #
return(tcl("expr", FALSE))
  } else {
return(tcl("expr", TRUE))# but other kinds of space are not-->
error-checking if good value is added
  }
}

table1<-tk2table(tfr,
  rows = 1,cols = 1,
  variable = tableData,
  validate = T,
  vcmd = valChar
)

tcl(table1, "tag", "configure", "active", fg='black', bg='yellow')
tkgrid(table1)

# I believe when you define vcmd, it has the effect of reserving the %
arguments for their meanings as defined "in the manual"
# there's no need to think about the %'s thereafter.
# for some arguments, it doesn't seem to work as expected

-Dan


On Thu, Nov 17, 2016 at 3:12 PM, Cleber N.Borges via R-help <
r-help@r-project.org> wrote:

> Hi Dan
> Were you able to find a way to access the % S values ??
>
> Do you have any examples of how this works?
>
> Thank you for your attention.
> Cleber
>
>
> Em 25/01/2016 08:21, peter dalgaard escreveu:
> > It's been so long that I have forgotten how to get the package with the
> table widget installed on OSX, so I cannot check things for you. However,
> the canonical way to handle %S type arguments is to pass them as formal
> arguments to the callback, e.g.
> >
> >> .Tcl.callback(function(x,y)x+y)
> > [1] "R_call 0x7f9a34806ca0 %x %y"
> >
> > so I would assume that you should just define your
> >
> > CellValidation <- function(S){}
> >
> > and then just access S as a variable inside the function.
> >
> > As far as I remember, this only works at entry completion, though. That
> does sort of make sense since not every prefix of a valid entry is valid
> ("1e-2" is a double, "1e-" is not). If you want to actually disable certain
> keys during entry, then you have a larger task on your hand.
> >
> > -pd
> >
> > On 22 Jan 2016, at 21:25 , Dalthorp, Daniel <ddalth...@usgs.gov> wrote:
> >
> >> I'd like to allow users to edit data in tcltk tables and to use vcmd to
> >> validate data entry, e.g., not allowing non-numbers to be entered in
> >> numeric cells and not allowing '\n' to be entered in text cells.
> >>
> >> The problem is that I can't figure out how to "see" their data entry
> before
> >> it is entered, although it looks like %S can be somehow used in vcmd to
> get
> >> this information.
> >>
> >> Example: to disallow '\n' to be entered into a cell in an editable
> table:
> >>
> >> require(tcltk2)
> >> tt<-tktoplevel(); tfr<-tkframe(tt); tkgrid(tfr)
> >> tableData<-tclArray()
> >> tableData[[0,0]]<-"junk"
> >>
> >> CellValidation<-function(){
> >>
> >> ## http://www.tcl.tk/community/hobbs/tcl/capp/tkTable/tkTable.html
> says:
> >> ## *%S* For *ValidateCommand*, it is the potential new value of the cell
> >> being validated.
> >> ## which is exactly what I want, but I can't figure out how to do that.
> >> ## The following allows one bad character and then disallows further
> edits
> >>
> >>   testval<-tclvalue(tcl(table1,"curvalue"))
> >>
> >>   if (length(grep("\n",testval))>0)  return(tcl("expr", FALSE))  else
> >> return(tcl("expr", TRUE))
> >> }
> >>
> >> table1<<-tk2table(tfr,
> >>   rows=1,cols=1,
> >>   selectmode="extended",
> >>   variable=tableData,
> >>   validate=T,
> >>   vcmd=CellValidation
> >> )
> >>
> >> tcl(table1,"tag","configure", "active", fg='black',bg=colors()[411])
> >> tkgrid(table1)
> >>
> >> How can I get the %S value rather than the tcl(table1,"curvalue")?
> >>
> >> Much thanks for any help.
> >>
> >> -Dan
> >>
>
>
> ---
> Este email foi escaneado pelo Avast antivírus.
> https://www.avast.com/antivirus
>
> [[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Average every 4 columns

2016-11-09 Thread Dalthorp, Daniel
Better is...

rowMeans(x[0:((dim(x)[1]-1)/4)*4+1, ])

On Wed, Nov 9, 2016 at 9:00 AM, Miluji Sb <miluj...@gmail.com> wrote:

> Thanks a lot for your quick reply. I made a mistake in the question, I
> meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!
>
> Sincerely,
>
> Milu
>
> On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel <ddalth...@usgs.gov>
> wrote:
>
>> Hi Milu,
>> The following should work for an array x (provided dim(x)[2] is divisible
>> by 4):
>>
>> colMeans(x[,0:(dim(x)[2]/4-1)*4+1])
>>
>> -Dan
>>
>> On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb <miluj...@gmail.com> wrote:
>>
>>> Dear all,
>>>
>>> I have a dataset with hundreds of columns, I am only providing only 12
>>> columns. Is it possible to take the mean of every four (or 12) columns
>>>  (value601, value602, value603, value604 etc.in this case) and repeat
>>> for
>>> the hundreds of columns? Thank you.
>>>
>>> Sincerely,
>>>
>>> Milu
>>>
>>> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
>>> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
>>> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
>>> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
>>> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
>>> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
>>> c(22.0399188995361,
>>> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
>>> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
>>> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
>>> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
>>> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
>>> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
>>> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
>>> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
>>> c(33.9698333740234,
>>> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
>>> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
>>> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
>>> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
>>> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
>>> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
>>> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
>>> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
>>> c(27.5402088165283,
>>> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
>>> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
>>> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
>>> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
>>> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
>>> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
>>> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
>>> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
>>> c(9.12979793548584,
>>> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
>>> 7.55471754074097, -5.58141136169434, -0.566209673881531,
>>> 12.3264112472534,
>>> 6.65576601028442)), .Names = c("value601", "value602", "value603",
>>> "value604", "value605", "value606", "value607", "value608", "value609",
>>> "value610", "value611", "value612"), row.names = c("1", "2",
>>> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>>
>> --
>> Dan Dalthorp, PhD
>> USGS Forest and Rangeland Ecosystem Science Center
>> Forest Sciences Lab, Rm 189
>> 3200 SW Jefferson Way
>> Corvallis, OR 97331
>> ph: 541-750-0953
>> ddalth...@usgs.gov
>>
>>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Average every 4 columns

2016-11-09 Thread Dalthorp, Daniel
rowMeans(x[0:(dim(x)[1]/4-1)*4+1, ])

On Wed, Nov 9, 2016 at 9:00 AM, Miluji Sb <miluj...@gmail.com> wrote:

> Thanks a lot for your quick reply. I made a mistake in the question, I
> meant to ask every 4 (or 12) rows not columns. Apologies. Thanks again!
>
> Sincerely,
>
> Milu
>
> On Wed, Nov 9, 2016 at 5:45 PM, Dalthorp, Daniel <ddalth...@usgs.gov>
> wrote:
>
>> Hi Milu,
>> The following should work for an array x (provided dim(x)[2] is divisible
>> by 4):
>>
>> colMeans(x[,0:(dim(x)[2]/4-1)*4+1])
>>
>> -Dan
>>
>> On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb <miluj...@gmail.com> wrote:
>>
>>> Dear all,
>>>
>>> I have a dataset with hundreds of columns, I am only providing only 12
>>> columns. Is it possible to take the mean of every four (or 12) columns
>>>  (value601, value602, value603, value604 etc.in this case) and repeat
>>> for
>>> the hundreds of columns? Thank you.
>>>
>>> Sincerely,
>>>
>>> Milu
>>>
>>> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
>>> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
>>> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
>>> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
>>> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
>>> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
>>> c(22.0399188995361,
>>> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
>>> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
>>> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
>>> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
>>> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
>>> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
>>> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
>>> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
>>> c(33.9698333740234,
>>> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
>>> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
>>> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
>>> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
>>> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
>>> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
>>> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
>>> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
>>> c(27.5402088165283,
>>> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
>>> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
>>> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
>>> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
>>> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
>>> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
>>> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
>>> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
>>> c(9.12979793548584,
>>> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
>>> 7.55471754074097, -5.58141136169434, -0.566209673881531,
>>> 12.3264112472534,
>>> 6.65576601028442)), .Names = c("value601", "value602", "value603",
>>> "value604", "value605", "value606", "value607", "value608", "value609",
>>> "value610", "value611", "value612"), row.names = c("1", "2",
>>> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>>
>> --
>> Dan Dalthorp, PhD
>> USGS Forest and Rangeland Ecosystem Science Center
>> Forest Sciences Lab, Rm 189
>> 3200 SW Jefferson Way
>> Corvallis, OR 97331
>> ph: 541-750-0953
>> ddalth...@usgs.gov
>>
>>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Average every 4 columns

2016-11-09 Thread Dalthorp, Daniel
Hi Milu,
The following should work for an array x (provided dim(x)[2] is divisible
by 4):

colMeans(x[,0:(dim(x)[2]/4-1)*4+1])

-Dan

On Wed, Nov 9, 2016 at 8:29 AM, Miluji Sb  wrote:

> Dear all,
>
> I have a dataset with hundreds of columns, I am only providing only 12
> columns. Is it possible to take the mean of every four (or 12) columns
>  (value601, value602, value603, value604 etc.in this case) and repeat for
> the hundreds of columns? Thank you.
>
> Sincerely,
>
> Milu
>
> structure(list(value601 = c(10.1738710403442, 3.54112911224365,
> 12.9192342758179, 3.17447590827942, 11.7332258224487, 7.68282270431519,
> -7.11564493179321, 0.987620949745178, 13.0476207733154, 6.36939525604248
> ), value602 = c(13.0642414093018, 5.53129482269287, 16.0519638061523,
> 2.88946437835693, 14.9204912185669, 9.42428588867188, -6.80674123764038,
> -0.614241063594818, 16.7947769165039, 7.9541072845459), value603 =
> c(22.0399188995361,
> 14.398024559021, 24.9523792266846, 12.0878629684448, 23.6459674835205,
> 18.3277816772461, -2.54092741012573, 10.5550804138184, 25.1016540527344,
> 16.2166938781738), value604 = c(27.7165412902832, 20.3255825042725,
> 30.8430004119873, 16.6856250762939, 29.2485408782959, 24.3775005340576,
> 6.47758340835571, 15.5897912979126, 30.7387924194336, 22.3637084960938
> ), value605 = c(31.6644763946533, 23.4093952178955, 35.1488723754883,
> 19.7132263183594, 33.3924179077148, 29.5846366882324, 10.2083873748779,
> 19.3551616668701, 35.3076629638672, 27.4299201965332), value606 =
> c(33.9698333740234,
> 26.8574161529541, 36.8900833129883, 22.8604583740234, 34.8642921447754,
> 33.8158760070801, 14.7055835723877, 22.1144580841064, 37.0545425415039,
> 32.1087913513184), value607 = c(36.0279846191406, 26.9297180175781,
> 38.2701225280762, 23.2643146514893, 36.7398796081543, 34.1216125488281,
> 17.1387901306152, 24.0419750213623, 37.8542327880859, 32.7677421569824
> ), value608 = c(34.0242347717285, 25.7720966339111, 36.4897193908691,
> 22.0332260131836, 34.8011703491211, 32.6856842041016, 16.6232261657715,
> 21.5571365356445, 36.1491546630859, 31.1716938018799), value609 =
> c(27.5402088165283,
> 21.7590408325195, 30.5214176177979, 18.4252090454102, 29.1156253814697,
> 26.9878330230713, 12.4962501525879, 17.7259578704834, 30.9099159240723,
> 25.4832077026367), value610 = c(23.4706859588623, 17.0126209259033,
> 26.8166942596436, 15.297459602356, 25.1733055114746, 23.5616931915283,
> 8.86995983123779, 13.5793552398682, 27.5732250213623, 22.1691932678223
> ), value611 = c(14.5820417404175, 9.08279132843018, 17.8419170379639,
> 8.36016654968262, 16.5633754730225, 14.8123331069946, 1.32095837593079,
> 5.73408317565918, 18.9752082824707, 13.572542236), value612 =
> c(9.12979793548584,
> 2.79943537712097, 11.6504030227661, 2.21584677696228, 10.5404834747314,
> 7.55471754074097, -5.58141136169434, -0.566209673881531, 12.3264112472534,
> 6.65576601028442)), .Names = c("value601", "value602", "value603",
> "value604", "value605", "value606", "value607", "value608", "value609",
> "value610", "value611", "value612"), row.names = c("1", "2",
> "3", "4", "5", "6", "7", "8", "9", "10"), class = "data.frame")
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (no subject)

2016-10-06 Thread Dalthorp, Daniel
The answer is 42 (in base 13). The question is "What do you get when you
multiply six by nine?"

On Thu, Oct 6, 2016 at 3:54 PM, Jim Lemon <drjimle...@gmail.com> wrote:

> No, I'm quite certain that the answer is:
>
> 7*6 = 3*2^4 - 36/6
>
> but I don't know the question
>
> Jim
>
> On Fri, Oct 7, 2016 at 9:48 AM, Dalthorp, Daniel <ddalth...@usgs.gov>
> wrote:
> > Question and answer:
> >
> > 6*9 = (4)*13^1 + (2)*13^0
> >
> > On Thu, Oct 6, 2016 at 3:26 PM, Jim Lemon <drjimle...@gmail.com> wrote:
> >>
> >> It certainly does. As we are often confronted with requests for
> >> solutions of problems so minimally defined as to challenge the most
> >> eminent mindreader, this excels. We have a meta-problem as the
> >> supplicant him- (or her-, I cannot even ascertain this) does not
> >> appear to know what it is. Thus me are asked to both pose and solve
> >> the problem. While this may seem trivial to the casual reader, we must
> >> recall Adams' Paradox, that we might supply an answer, but be unable
> >> to state the question.
> >>
> >> Pardon the enthusiasm - I have just solved two gratuitous problems and
> >> I was, so to speak, primed for this message.
> >>
> >> Jim
> >>
> >> On Fri, Oct 7, 2016 at 7:20 AM, Rolf Turner <r.tur...@auckland.ac.nz>
> >> wrote:
> >> > On 06/10/16 20:55, abhishek pandey wrote:
> >> >>
> >> >> kindly solve my problem sir.
> >> >
> >> >
> >> > That's it, in its entirety.  Shouldn't that win some sort of prize?
> >> >
> >> > cheers,
> >> >
> >> > Rolf Turner
> >> >
> >> > --
> >> > Technical Editor ANZJS
> >> > Department of Statistics
> >> > University of Auckland
> >> > Phone: +64-9-373-7599 ext. 88276
> >> >
> >> >
> >> > __
> >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > PLEASE do read the posting guide
> >> > http://www.R-project.org/posting-guide.html
> >> > and provide commented, minimal, self-contained, reproducible code.
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center
> > Forest Sciences Lab, Rm 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (no subject)

2016-10-06 Thread Dalthorp, Daniel
Question and answer:

6*9 = (4)*13^1 + (2)*13^0

On Thu, Oct 6, 2016 at 3:26 PM, Jim Lemon  wrote:

> It certainly does. As we are often confronted with requests for
> solutions of problems so minimally defined as to challenge the most
> eminent mindreader, this excels. We have a meta-problem as the
> supplicant him- (or her-, I cannot even ascertain this) does not
> appear to know what it is. Thus me are asked to both pose and solve
> the problem. While this may seem trivial to the casual reader, we must
> recall Adams' Paradox, that we might supply an answer, but be unable
> to state the question.
>
> Pardon the enthusiasm - I have just solved two gratuitous problems and
> I was, so to speak, primed for this message.
>
> Jim
>
> On Fri, Oct 7, 2016 at 7:20 AM, Rolf Turner 
> wrote:
> > On 06/10/16 20:55, abhishek pandey wrote:
> >>
> >> kindly solve my problem sir.
> >
> >
> > That's it, in its entirety.  Shouldn't that win some sort of prize?
> >
> > cheers,
> >
> > Rolf Turner
> >
> > --
> > Technical Editor ANZJS
> > Department of Statistics
> > University of Auckland
> > Phone: +64-9-373-7599 ext. 88276
> >
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Rotating points, preferably in grid

2016-08-24 Thread Dalthorp, Daniel
Silly? Not really.

It's simple. It works.

You could jump into unicode for your text and make it look nicer, e.g.,
using '\u2191' or some other shape in place of 'T'

http://unicode.org/charts/
http://unicode.org/charts/PDF/U2190.pdf

-Dan

On Wed, Aug 24, 2016 at 7:16 PM, Thomas Levine <_...@thomaslevine.com> wrote:

> I want to make a plot in polar coordinates. I want to use pch with
> shapes that do not have radial symmetry, so I want to rotate them such
> that they face inwards. I am using grid for my plotting, but I provide
> motivating examples in graphics.
>
> The following plot almost gets me what I want.
>
>   theta <- 2*pi*seq(0,7/8,1/8)
>   plot(cos(theta), sin(theta), pch=2, axes=F, asp=1)
>
> But I want the points to face inwards. I can do something like this with
> text, but I can set only a constant rotation
>
>   plot.new()
>   plot.window(c(-1,1),c(-1,1), asp=1)
>   text(cos(theta), sin(theta), 'Tom', srt
>  =runif(1,0,360))
>
> To rotate all of the points, I can do something like this.
>
>   plot.new()
>   plot.window(c(-1,1),c(-1,1), asp=1)
>   for (the.theta in theta)
> text(cos(the.theta), sin(the.theta), 'Tom',
>  srt=(360/(2*pi))*(the.theta-(1/4)*2*pi))
>
> So perhaps I could use a "T" instead of a numeric pch and consequently
> do something like this.
>
>   plot.new()
>   plot.window(c(-1,1),c(-1,1), asp=1)
>   for (the.theta in theta)
> text(cos(the.theta), sin(the.theta), 'T',
>  srt=(360/(2*pi))*(the.theta+(1/4)*2*pi))
>
> But that seems a bit silly.
>
> Is there a more declarative way of doing this, preferably in grid?
>
> Thanks
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] I'm getting confused with notation and terminology in output from weibull parametric survival model from survreg()

2016-07-29 Thread Dalthorp, Daniel
The parameterization for Weibull in the 'survival' package corresponds to
base R's dweibull, etc. suite as 1/scale --> shape and exp(coef[1]) -->
scale

On Fri, Jul 29, 2016 at 1:07 PM, Christopher W. Ryan 
wrote:

> I'm trying to run a Weibull parametric survival model for recurrent event
> data, with subject-specific frailties, using survreg() in the survival
> package, and I'm having trouble understanding the output and its notation,
> and how that translates to some of the books I am using as references (DF
> Moore, Applied Survival Analysis Using R; and Kleinbaum and Klein, Survival
> Analysis A Self-Learning Text). I understand there are different notations
> for different ways of parameterizing a Weibull or a gamma distribution, and
> perhaps that's where I am getting hung up. I also may be confusing "scale"
> for the Weibull distribution of the survial times with "scale" for the
> gamma distribution of the frailties.
>
> My ultimate goal is to display example survival curves: say, one for
> "typically frail" subjects, one for "extra-frail" subjects, and one for
> "not-so-frail" subjects. I'd like to get estimated "frailty" for each of my
> subjects; or at least the distribution of those frailties. Do I need the
> parameters of the gamma distribution to do that? If so, how do I extract
> them? Or are they readily available in the survreg object?
>
> Here is what I have tried so far:
>
> ## create some data similar to my real data, in which
> ## vast majority of subjects had no event
> id <- c(1:600, rep(601:630, each=1), rep(631:650, each=2), rep(651:656,
> each=3), rep(677:679, each=4), rep(680, 5))
> time <- c(rpois(lambda=800, 600), rpois(lambda=600, length(601:630)),
> rpois(lambda=600, length(631:650)*2), rpois(lambda=600, length(651:656)*3),
> rpois(lambda=600, length(677:679)*4), rpois(lambda=600, 5))
> event <- c(rep(0, 600), rep(1, (length(id) - 600)))
> dd <- data.frame(id=id, time=time, event=event)
> dd.2 <- dd[order(id, time), ]
> str(dd.2)
> table(table(dd.2$id))
> # time until censoring, for those without events
> summary(subset(dd.2, event==0, select=time))
>
> library(survival)
> Surv.1 <- Surv(time, event)
>
> # model without frailties
> model.1 <- survreg(Surv.1 ~ 1, data=dd.2, dist="weibull")
>
> # add frailty term
> model.2 <- survreg(Surv.1 ~ 1 + frailty(id), data=dd.2, dist="weibull")
>
> # should be same as above line
> model.2.b <- survreg(Surv.1 ~ 1 + frailty(id, distribution="gamma"),
> data=dd.2, dist="weibull")
>
> # I don't know if this is the right way to go about it
> a.scale <- model.2$scale
> var.X <- model.2$history$frailty$theta
> s.shape <- sqrt(var.X/a.scale)
>
> gamma.frail.x <- function(a,s,q){ 1/((s^a) * gamma(a)) * (q^(a-1) *
> exp(-(q/s))) }
> q <- seq(0.1, 10, by=0.2)
>
> maybe.my.frailties <- gamma.frail.x(a.scale, s.shape, q)))
> plot(density(maybe.my.frailties))
>
> ## end code
>
>
> Or, would I be better off changing tactics and using frailtypack?
>
> Thanks for any help.  Session info is below, in case it is relevant.
>
> --Chris Ryan
>
>
>
> > sessionInfo()
> R version 3.3.1 (2016-06-21)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] survival_2.39-5
>
> loaded via a namespace (and not attached):
> [1] compiler_3.3.1  Matrix_1.2-6tools_3.3.1 splines_3.3.1
> [5] grid_3.3.1  lattice_0.20-33
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] font size in graphs...can R read Windows settings?

2016-07-28 Thread Dalthorp, Daniel
The trouble is getting the figs to look right for different users who
happen to have different display settings. Nearly all my users will be on
MS Windows, and, for the parameter set you gave, the figs will look
different, depending on which "display size" parameter value is active and
the screen resolution (for Windows 7 --- Control Panel | Appearance and
Personalization | Display | Make text and other items larger or smaller).

For example, the following gives different look (for text(), mtext(), axis
labels, etc.) "smaller" than for "larger" or for fine resolution vs. coarse
resolution. Getting it wrong makes the figs look sloppy and hard to read.
If I knew users' display parameters ahead of time, I could adjust the
drawing algorithms using par parameters, but I don't know the display
parameters. 'din' values at time of package attachment (and after closing
of open devices) gives a reasonable proxy in a lot of cases but not always.

par(mfrow = c(1,1),
 las = 1,
 mai = c(0.85, 0.85, 0.32, 0.12),
 font.main = 1,
 cex.main = 1.0,
 cex.lab  = 1.0,
 cex.axis = 0.9)
plot(0,0)
plot(0,0, type='n')
text(0,0, 'junk')
mtext(side = 3, line = .5, "more junk")


On Thu, Jul 28, 2016 at 6:15 PM, Duncan Mackay <dulca...@bigpond.com> wrote:

> Hi Dan
>
>
>
> This is one of  the features/problems of proportional graphing – getting
> it exactly right.
>
>
>
> Anyway good graphs usually take time
>
>
>
> I wonder if aspect in both base and lattice may be of use.
>
> Also I have a default par settings for base graphics where I sometimes
> change the mai command for multiple graphs and rarely the font size.
>
>
>
> par(mfrow = c(1,1),
>
> las = 1,
>
> mai = c(0.85, 0.85, 0.32, 0.12),
>
> font.main = 1,
>
> cex.main = 1.0,
>
> cex.lab  = 1.0,
>
> cex.axis = 0.9)
>
>
>
> Duncan
>
>
>
> *From:* Dalthorp, Daniel [mailto:ddalth...@usgs.gov]
> *Sent:* Friday, 29 July 2016 09:22
> *To:* Duncan Mackay
> *Cc:* R
> *Subject:* Re: [R] font size in graphs...can R read Windows settings?
>
>
>
> Thanks, Duncan. This is close to what I was looking for. But I'm not using
> lattice. And the fontsize$text and fontsize$points are independent of
> display settings in Windows (screen resolution and 'size of objects').
>
>
>
> I need to make my graphs [esp. placement and size of text(), mtext()] look
> good regardless of display settings.
>
>
>
> Here's what I'm working with at the moment...
>
>
>
> When package is loaded, I store the default graph size ('din') which is
> correlated with OS display parameters. Then, I simply multiple my current
> 'cex' values by the stored 'din' divided by 7 (which is the 'din'
> associated with the display parameters that I created the figs in
> initially). It seems to work just fine for my text() and mtext() text
> sizes.
>
>
>
> But some of my algorithms for placing text and subfigs in margins still
> need fixing...combinations of 'plt' and 'usr' seem to be working, but it's
> tedious.
>
>
>
> -Dan
>
>
>
> On Wed, Jul 27, 2016 at 8:43 PM, Duncan Mackay <dulca...@bigpond.com>
> wrote:
>
> Hi  Dan
>
> For devices png, pdf, postscript and ? others the pointsize argument
> controls the font size which is modified by cex
>
> For lattice there are the settings in trellis.par.get()
>
> trellis.par.get()$fontsize
> $text
> [1] 12
>
> $points
> [1] 8
>
> which you can set and there is no real need to change font size except if
> you need to change main.
> trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
> text
>
> these could be set globally by trellis.par.set() or individually with
> argument par.settings eg
> xyplot(y ~ x, data = datm,
>  par.settings = list(strip.background = list(col =
> "transparent"),
>  fontsize = list(text = 16,
>
> points = 12),  # large size;  need to refine
>     superpose.polygon= list(col
> = c("red","blue"),
>
> border = c("red","blue"))),
> type = "b")
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
> Daniel
> Sent: Thursday, 28 July 2016 07:02
> To: r-help@R-project.org (r-help@r-project.org)
> Subject: [R] font size in graphs...can R read Windows settings?
>
&

Re: [R] font size in graphs...can R read Windows settings?

2016-07-28 Thread Dalthorp, Daniel
Thanks, Duncan. This is close to what I was looking for. But I'm not using
lattice. And the fontsize$text and fontsize$points are independent of
display settings in Windows (screen resolution and 'size of objects').

I need to make my graphs [esp. placement and size of text(), mtext()] look
good regardless of display settings.

Here's what I'm working with at the moment...

When package is loaded, I store the default graph size ('din') which is
correlated with OS display parameters. Then, I simply multiple my current
'cex' values by the stored 'din' divided by 7 (which is the 'din'
associated with the display parameters that I created the figs in
initially). It seems to work just fine for my text() and mtext() text
sizes.

But some of my algorithms for placing text and subfigs in margins still
need fixing...combinations of 'plt' and 'usr' seem to be working, but it's
tedious.

-Dan

On Wed, Jul 27, 2016 at 8:43 PM, Duncan Mackay <dulca...@bigpond.com> wrote:

> Hi  Dan
>
> For devices png, pdf, postscript and ? others the pointsize argument
> controls the font size which is modified by cex
>
> For lattice there are the settings in trellis.par.get()
>
> trellis.par.get()$fontsize
> $text
> [1] 12
>
> $points
> [1] 8
>
> which you can set and there is no real need to change font size except if
> you need to change main.
> trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
> text
>
> these could be set globally by trellis.par.set() or individually with
> argument par.settings eg
> xyplot(y ~ x, data = datm,
>  par.settings = list(strip.background = list(col =
> "transparent"),
>  fontsize = list(text = 16,
>
> points = 12),  # large size;  need to refine
> superpose.polygon= list(col
> = c("red","blue"),
>
> border = c("red","blue"))),
> type = "b")
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
> Daniel
> Sent: Thursday, 28 July 2016 07:02
> To: r-help@R-project.org (r-help@r-project.org)
> Subject: [R] font size in graphs...can R read Windows settings?
>
> Hi All,
> I am putting together a package that (among other things) draws some nice
> graphs for users. I place some explanatory text on figs using "text" and
> "mtext". But the size of the text depends on the Windows display settings:
> Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
> panel | Appearance and personalization | Display | Make text and other
> items smaller or larger). If I create figs that look good with one setting,
> the text is too big (or too small) if another setting is used in Windows.
> If I know the Windows setting, I can use cex in R to make the right sized
> labels, but if I don't know a user's Windows display size setting...is
> there a way for R to read the setting? Or is there another way to control
> label size so that text labels on graphs look good regardless of WIndows
> display size setting?
>
> Many thanks for Ideas,
>
> -Dan
> --
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalth...@usgs.gov
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] font size in graphs...can R read Windows settings?

2016-07-27 Thread Dalthorp, Daniel
Hi All,
I am putting together a package that (among other things) draws some nice
graphs for users. I place some explanatory text on figs using "text" and
"mtext". But the size of the text depends on the Windows display settings:
Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
panel | Appearance and personalization | Display | Make text and other
items smaller or larger). If I create figs that look good with one setting,
the text is too big (or too small) if another setting is used in Windows.
If I know the Windows setting, I can use cex in R to make the right sized
labels, but if I don't know a user's Windows display size setting...is
there a way for R to read the setting? Or is there another way to control
label size so that text labels on graphs look good regardless of WIndows
display size setting?

Many thanks for Ideas,

-Dan
-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tclArray() --- "active"?!

2016-07-06 Thread Dalthorp, Daniel
Thanks, Peter.

When it comes time to read the array back to R, I can explicitly delete the
"active" cell first...

On Wed, Jul 6, 2016 at 8:35 AM, peter dalgaard <pda...@gmail.com> wrote:

> I am not up to speed on Tcl/Tk these days, but I would suspect that the
> issue lies in tkTable and not in tclArray. The table widget has the notion
> of an active cell, which can be used in indexing operations. According to
> the widget documentation
>
> --
> Command-Line Name:-variable
> Database Name: variable
> Database Class: Variable
>
> Global Tcl array variable to attach to the table's C array. It will be
> created if it doesn't already exist or is a simple variable. Keys used by
> the table in the array are of the form row,col for cells and the special
> key active which contains the value of the active cell buffer. [...]
> --
>
> I think this suggests that you just need to assume that the "active"
> element might be there when you deal with the tclArray and work around it
> if it gets in the way.
>
> (A conjecture as to why it appears in your example could be that you
> deleted the row with the active cell, and that the widget needs to record
> the fact that there is now no active cell.)
>
> -pd
>
>
> > On 06 Jul 2016, at 16:18 , Dalthorp, Daniel <ddalth...@usgs.gov> wrote:
> >
> > Sometimes when working with tclArray's, an empty element called "active"
> is
> > appended to the array. Does anyone know when (and why) this happens? And
> > how to prevent it (or at least predict it so that it can be removed by
> > hand)?
> >
> > E.g.,
> > library(tcltk); library(tcltk2)
> > tt<-tktoplevel()
> > dat<-tclArray()
> > tab<-tk2table(tt, variable = dat)
> > tkgrid(tab)
> > dat[[0,0]]<-5
> > dat[[1,0]]<-4
> > dat[[2,0]]<-56
> > tkdelete(tab,"rows",2, 8)
> > names(dat)
> >
> > Any help would be greatly appreciated!
> >
> > -Dan
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center
> > Forest Sciences Lab, Rm 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] tclArray() --- "active"?!

2016-07-06 Thread Dalthorp, Daniel
Sometimes when working with tclArray's, an empty element called "active" is
appended to the array. Does anyone know when (and why) this happens? And
how to prevent it (or at least predict it so that it can be removed by
hand)?

E.g.,
library(tcltk); library(tcltk2)
tt<-tktoplevel()
dat<-tclArray()
tab<-tk2table(tt, variable = dat)
tkgrid(tab)
dat[[0,0]]<-5
dat[[1,0]]<-4
dat[[2,0]]<-56
tkdelete(tab,"rows",2, 8)
names(dat)

Any help would be greatly appreciated!

-Dan

-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] better loop for simulation

2016-06-18 Thread Dalthorp, Daniel
try:

n.questions <- 10  # or however many you want
mult.choice <- 2
scores <- rbinom(1000, size = n.questions, prob = 1/mult.choice)


On Sat, Jun 18, 2016 at 3:12 PM, Naresh Gurbuxani <
naresh_gurbux...@hotmail.com> wrote:

> I want to calculate a function many times over.  My solution below works,
> but does not seem very elegant.
>
> # my function to run many times over
> stud.score <- function(n.questions, mult.choice = 2) {
> prob.success <- 1 / mult.choice
> answers <- (runif(n.questions) < prob.success)
> return(sum(answers))
> }
>
> # my method to run above function 1000 times and store results
> count.df <- data.frame(n.count = rep(10, 1000))
> scores.df <- apply(count.df, 1, function(x) return(stud.score(x)))
>
> Creating a data frame just to repeat the the count seems wasteful.  How
> can I generate scores.df without count.df?
>
> Thanks,
> Naresh
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Fwd: tcltk: click and return table cell index

2016-05-06 Thread Dalthorp, Daniel
Thanks, John.

The trouble with that solution is that it gives the index for where the
cursor was before clicking rather than the cell that was clicked. The
solution is that the  binding gives the x, y pixel coordinates of
the click to the callback, and those just need to be translated to cell
index via tkindex ( My (almost) solution gives the pixel coordinates of the
mouse click. There is a function that converts the coords to cell index,
but I was having trouble figuring out the format of parameters, but the
following works:

tcl(table1, "index", as.tclObj(paste0("@",x, ",", y)))

I.e., to retrieve the index of the cell that is clicked on:

# create table
tt<-tktoplevel()
tclRequire("Tktable")
table1<-tkwidget(tt,"table",rows=3,cols=3)
tkgrid(table1)

tkbind(table1, "", function(x, y){
  cellIndex<-tcl(table1, "index", as.tclObj(paste0("@",x, ",", y)))
  print(tclvalue(cellIndex))
})

Thanks again!

-Dan


On Sat, Apr 30, 2016 at 6:43 AM, Fox, John <j...@mcmaster.ca> wrote:

> Dear Daniel,
>
> Try
>
> tkbind(table1, "", function(){
>  res <- try(tclvalue(tkindex(table1, "active")), silent=TRUE)
>if (inherits(res, "try-error")) print (NULL)
>else print(res)
> })
>
> I put in the calls to print() so that you could see how it works.
>
> I hope this helps,
>  John
>
> -
> John Fox, Professor
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> Web: socserv.mcmaster.ca/jfox
>
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> Dalthorp,
> > Daniel
> > Sent: April 29, 2016 1:42 PM
> > To: r-help@R-project.org (r-help@r-project.org) <r-help@r-project.org>
> > Subject: [R] tcltk: click and return table cell index
> >
> > I'm struggling mightily with what should be a simple task...when a user
> clicks
> > on a cell in a tcltk table widget, I need to know which cell was clicked.
> >
> > One idea that gives a cryptic error:
> > tkbind(table1, "", function(x, y){
> >   tcl(table1, "index", x, y)
> > }
> >
> > # x, y give pixel coordinates; "index" should give cell coordinates, but
> format
> > must be correct
> >
> > I get an error message:
> >
> > wrong # args: should be ".25.1 index  ?row|col?".
> >
> > To which I respond, "Yes, I know I have the format wrong, but how can I
> make
> > sense of THAT?"
> >
> > Does anyone know a simple fix?
> >
> > Much appreciated!
> >
> > -Dan
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center Forest Sciences Lab,
> Rm
> > 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tcltk: click and return table cell index

2016-05-02 Thread Dalthorp, Daniel
Thanks, John.

The trouble with that solution is that it gives the index for where the
cursor was before clicking rather than the cell that was clicked. The
solution is that the  binding gives the x, y pixel coordinates of
the click to the callback, and the pixel coordinates can be translated to
cell index via:

tkindex(table1, as.tclObj(paste0("@",x, ",", y)))

Or, showing the whole example:

# create table
tt<-tktoplevel()
table1<-tkwidget(tt,"table", rows=3,cols=3)
tkgrid(table1)

# bind the mouse click to printing out cell index:
tkbind(table1, "", function(x, y) print(tcl(table1, "index",
as.tclObj(paste0("@",x, ",", y)

Thanks again!

-Dan

On Sat, Apr 30, 2016 at 6:43 AM, Fox, John <j...@mcmaster.ca> wrote:

> Dear Daniel,
>
> Try
>
> tkbind(table1, "", function(){
>  res <- try(tclvalue(tkindex(table1, "active")), silent=TRUE)
>if (inherits(res, "try-error")) print (NULL)
>else print(res)
> })
>
> I put in the calls to print() so that you could see how it works.
>
> I hope this helps,
>  John
>
> -
> John Fox, Professor
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> Web: socserv.mcmaster.ca/jfox
>
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> Dalthorp,
> > Daniel
> > Sent: April 29, 2016 1:42 PM
> > To: r-help@R-project.org (r-help@r-project.org) <r-help@r-project.org>
> > Subject: [R] tcltk: click and return table cell index
> >
> > I'm struggling mightily with what should be a simple task...when a user
> clicks
> > on a cell in a tcltk table widget, I need to know which cell was clicked.
> >
> > One idea that gives a cryptic error:
> > tkbind(table1, "", function(x, y){
> >   tcl(table1, "index", x, y)
> > }
> >
> > # x, y give pixel coordinates; "index" should give cell coordinates, but
> format
> > must be correct
> >
> > I get an error message:
> >
> > wrong # args: should be ".25.1 index  ?row|col?".
> >
> > To which I respond, "Yes, I know I have the format wrong, but how can I
> make
> > sense of THAT?"
> >
> > Does anyone know a simple fix?
> >
> > Much appreciated!
> >
> > -Dan
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center Forest Sciences Lab,
> Rm
> > 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] tcltk: click and return table cell index

2016-04-29 Thread Dalthorp, Daniel
I'm struggling mightily with what should be a simple task...when a user
clicks on a cell in a tcltk table widget, I need to know which cell was
clicked.

One idea that gives a cryptic error:
tkbind(table1, "", function(x, y){
  tcl(table1, "index", x, y)
}

# x, y give pixel coordinates; "index" should give cell coordinates, but
format must be correct

I get an error message:

wrong # args: should be ".25.1 index  ?row|col?".

To which I respond, "Yes, I know I have the format wrong, but how can I
make sense of THAT?"

Does anyone know a simple fix?

Much appreciated!

-Dan

-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to use vectorization instead of for loop

2016-03-21 Thread Dalthorp, Daniel
or simpler and faster:

dat[,4] <- sign(dat[,2])/dat[,3] # your original loop

dat <- cbind(dat, dat[,2] == Inf)  # append a new column with indicator for
which rows have dat[,2] = Inf


On Mon, Mar 21, 2016 at 2:45 PM,  wrote:

> Hello,
>
> Use combined ifelses, more or less like the following.
>
> ifelse(dat[, 2] == Inf, do this, ifelse(dat[, 2] > 0, 1 * (1/dat[,3]),
> -1* (1/dat[,3])))
>
> Rui Barradas
>
>
> Citando Stephen HK WONG :
>
> > So much thanks Rui, the code can be so simple and fast.
> >
> > By the way, ifelse is good for two conditions, in my case, either
> > >0, or <0, I found there's a lot of row with value "Inf", I want to
> > keep it in new column, how do I do that using ifelse ?
> >
> > Thanks.
> >
> > 
> > From: ruipbarra...@sapo.pt 
> > Sent: Monday, March 21, 2016 11:50 AM
> > To: Stephen HK WONG
> > Cc: r-help@r-project.org
> > Subject: Re: [R] how to use vectorization instead of for loop
> >
> > Hello,
> >
> > I've renamed your dataframe to 'dat'. Since ?ifelse is vectorized, try
> >
> > dat[, 4] <- ifelse(dat[, 2] > 0, 1 * (1/dat[,3]), -1* (1/dat[,3]))
> >
> > Oh, and why do you multiply by 1 and by -1?
> > It would simply be 1/dat[,3] and -1/dat[,3].
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> > Quoting Stephen HK WONG :
> >> Dear All,
> >>
> >> I have a dataframe like below but with many thousands rows,
> >>
> >> structure(list(gene_id = structure(1:6, .Label = c("0610005C13Rik",
> >> "0610007P14Rik", "0610009B22Rik", "0610009L18Rik", "0610009O20Rik",
> >> "0610010B08Rik,OTTMUSG0016609"), class = "factor"),
> >> log2.fold_change. = c(0.0114463,
> >> -0.0960262, 0.00805151, -0.179981, -0.0629098, 0.155979), p_value = c(1,
> >> 0.77915, 0.98265, 0.68665, 0.85035, 0.72235), new.value = c("NA",
> >> "NA", "NA", "NA", "NA", "NA")), .Names = c("gene_id",
> "log2.fold_change.",
> >> "p_value", "new.value"), row.names = c(NA, 6L), class = "data.frame")
> >>
> >> I want to check if second column is positive or negative value, then
> >> I will do some calculation and put the new value in last column. I
> >> can do this with for loop like below but it is not efficient. Is
> >> there a better way to use a vectorization method instead of loop?
> >> Many thanks!
> >>
> >> for (i in 1:nrow(dataframe)) {
> >>
> >> if dataframe[i, 2]>0 {
> >>
> >> dataframe[i, 4]<- 1 * (1/dataframe[i,3])} else{
> >>
> >> dataframe[i, 4] <- -1* (1/dataframe[i,3])}
> >>
> >> }
> >>
> >> ---
> >>
> >> Stephen H.K. WONG, PhD.
> >>
> >> Stanford University
> >>
> >>   [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.htmland provide commented,
> >> minimal, self-contained, reproducible code.
> >
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Error in make.names(col.names, unique = TRUE) : invalid multibyte string at '14 <4a>ULY 2012'

2016-03-10 Thread Dalthorp, Daniel
Hi Ken,
Without seeing your .csv file or how you are trying to read it, it's tough
to diagnose the trouble. I inserted commas between the columns in your data
snippet, pasted into Excel, saved as .csv file called "datesfile.csv" in
the R working directory. Then, the following worked fine for me:

junk<-read.csv("datesfile.csv", header = TRUE)
junk # is a dataframe with headers Gender, DOB, etc.

 # Age at screening (in days):
as.Date(junk$Screen.Date,format="%d %B %Y")-as.Date(junk$DOB,format="%d %B
%Y")

# Age at screening (in years):
as.numeric(as.Date(junk$Screen.Date,format="%d %B
%Y")-as.Date(junk$DOB,format="%d %B %Y"))/365.2425

I hope this helps.

-Dan


On Thu, Mar 10, 2016 at 11:34 AM, KMNanus  wrote:

> I’m trying to read in the data below from an Excel file (as a .csv file)
> in  order to create an age (in years.%years) but am getting the error
> message in the subject line.
>
> I’ve tried saving the dates as dates in Excel and tried saving the dates
> as text, both give me the same error message.  Can someone pls tell me what
> I’m doing wrong?
>
> Gender  DOB Diagnosis   Screen Date
> Male 14 JULY 2012   No   05 OCTOBER 2015
> Female   31 OCTOBER 2009No   30 NOVEMBER 2015
> Female   08 JULY 2009   No   06 DECEMBER 2015
> Male 04 JUNE 2011   NA   11 JANUARY 2016
> Female   21 AUGUST 2009 Yes  01 FEBRUARY 2016
> Male 05 NOVEMBER 2007   No   16 FEBRUARY 2016
> Male 01 JUNE 2009   NA   29 FEBRUARY 2016
>
>
>
> Ken
> kmna...@gmail.com
> 914-450-0816 (tel)
> 347-730-4813 (fax)
>
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] extracting months from a data

2016-03-09 Thread Dalthorp, Daniel
How about the following, which is both faster and simpler than either the
as.Date(...) or sub(...) solutions discussed earlier:

substring(x,first=nchar(x)-2)

require(microbenchmark)
microbenchmark(format(as.Date(paste0(x,"-2016"),format='%d-%b-%Y'),'%b'))
# 59.3 microseconds on my computer
microbenchmark(sub( "^\\d+-([A-Za-z]{3})$", "\\1", x ))
# 17.4 microseconds
microbenchmark(substring(x,first=nchar(x)-2))
# 3.6 microseconds

-Dan

On Wed, Mar 9, 2016 at 5:08 PM, Jeff Newmiller <jdnew...@dcn.davis.ca.us>
wrote:

> How about slower? That is objective.
>
> I use dates all the time so I am quite familiar with what they are good
> for. However, I prefer to avoid inventing information such as which year
> the date should have included unless I have to based on knowledge of the
> data source. It is not good to mislead the consumer of output about the
> existence of year information if it wasn't there to begin with.
> --
> Sent from my phone. Please excuse my brevity.
>
> On March 9, 2016 4:49:18 PM PST, "Dalthorp, Daniel" <ddalth...@usgs.gov>
> wrote:
>>
>> Good point about 29-Feb...fixed in the following:
>>
>> format(as.Date(paste0(x,"-2016"),format='%d-%b-%Y'),'%b')
>>
>> # Also: The date functions can be used to easily calculate passage of
>> time and offer good flexibility for formatting output.
>>
>> -Dan
>>
>> P.S. "harder to understand" is in the eye of the beholder (as is
>> "recommended").
>>
>>
>>
>> On Wed, Mar 9, 2016 at 4:39 PM, Jeff Newmiller <jdnew...@dcn.davis.ca.us>
>> wrote:
>>
>>> Still not recommended. That takes more steps, is harder to understand,
>>> and will break when given "29-Feb" as input.
>>> --
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> On March 9, 2016 4:15:31 PM PST, "Dalthorp, Daniel" <ddalth...@usgs.gov>
>>> wrote:
>>>>
>>>> Or:
>>>>
>>>> x <- c( "3-Oct", "10-Nov" )
>>>> format(as.Date(paste0(x,rep("-1970",length(x))),format='%d-%b-%Y'),'%b')
>>>>
>>>> # the 'paste0' appends a year to the text vector
>>>> # the 'as.Date' interprets the strings as dates with format
>>>>  10-Jun-2016 (e.g.)
>>>> # the 'format' returns a string with date in format '%b' (which is just
>>>> the name of the month)
>>>>
>>>> On Wed, Mar 9, 2016 at 3:52 PM, Jeff Newmiller <
>>>> jdnew...@dcn.davis.ca.us> wrote:
>>>>
>>>>> Your dates are incomplete (no year) so I suggest staying away from the
>>>>> date functions for this. Read ?regex and ?sub.
>>>>>
>>>>> x <- c( "3-Oct", "10-Nov" )
>>>>> m <- sub( "^\\d+-([A-Za-z]{3})$", "\\1", x )
>>>>>
>>>>> --
>>>>> Sent from my phone. Please excuse my brevity.
>>>>>
>>>>> On March 9, 2016 10:14:25 AM PST, KMNanus <kmna...@gmail.com> wrote:
>>>>> >I have a series of dates in  format 3-Oct, 10-Oct, 20-Oct, etc.
>>>>> >
>>>>> >I want to create a variable of just the month.  If I convert the date
>>>>> >to a character string, substr is ineffective because some of the dates
>>>>> >have 5 characters (3-Oct) and some have 6 (10-Oct).
>>>>> >
>>>>> >Is there a date function that accomplishes this easily?
>>>>> >
>>>>> >Ken
>>>>> >kmna...@gmail.com
>>>>> >914-450-0816 (tel)
>>>>> >347-730-4813 (fax)
>>>>> >
>>>>> >
>>>>> >
>>>>> >__
>>>>> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>> >https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> >PLEASE do read the posting guide
>>>>> >http://www.R-project.org/posting-guide.html
>>>>> >and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>> [[alternative HTML version deleted]]
>>>>>
>>>>> __
>>>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> PLEASE do read the posting guide
>>>>> http://www.R-project.org/posting-guide.html
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Dan Dalthorp, PhD
>>>> USGS Forest and Rangeland Ecosystem Science Center
>>>> Forest Sciences Lab, Rm 189
>>>> 3200 SW Jefferson Way
>>>> Corvallis, OR 97331
>>>> ph: 541-750-0953
>>>> ddalth...@usgs.gov
>>>>
>>>>
>>
>>
>> --
>> Dan Dalthorp, PhD
>> USGS Forest and Rangeland Ecosystem Science Center
>> Forest Sciences Lab, Rm 189
>> 3200 SW Jefferson Way
>> Corvallis, OR 97331
>> ph: 541-750-0953
>> ddalth...@usgs.gov
>>
>>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting months from a data

2016-03-09 Thread Dalthorp, Daniel
Good point about 29-Feb...fixed in the following:

format(as.Date(paste0(x,"-2016"),format='%d-%b-%Y'),'%b')

# Also: The date functions can be used to easily calculate passage of time
and offer good flexibility for formatting output.

-Dan

P.S. "harder to understand" is in the eye of the beholder (as is
"recommended").



On Wed, Mar 9, 2016 at 4:39 PM, Jeff Newmiller <jdnew...@dcn.davis.ca.us>
wrote:

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


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting months from a data

2016-03-09 Thread Dalthorp, Daniel
Or:

x <- c( "3-Oct", "10-Nov" )
format(as.Date(paste0(x,rep("-1970",length(x))),format='%d-%b-%Y'),'%b')

# the 'paste0' appends a year to the text vector
# the 'as.Date' interprets the strings as dates with format  10-Jun-2016
(e.g.)
# the 'format' returns a string with date in format '%b' (which is just the
name of the month)

On Wed, Mar 9, 2016 at 3:52 PM, Jeff Newmiller 
wrote:

> Your dates are incomplete (no year) so I suggest staying away from the
> date functions for this. Read ?regex and ?sub.
>
> x <- c( "3-Oct", "10-Nov" )
> m <- sub( "^\\d+-([A-Za-z]{3})$", "\\1", x )
>
> --
> Sent from my phone. Please excuse my brevity.
>
> On March 9, 2016 10:14:25 AM PST, KMNanus  wrote:
> >I have a series of dates in  format 3-Oct, 10-Oct, 20-Oct, etc.
> >
> >I want to create a variable of just the month.  If I convert the date
> >to a character string, substr is ineffective because some of the dates
> >have 5 characters (3-Oct) and some have 6 (10-Oct).
> >
> >Is there a date function that accomplishes this easily?
> >
> >Ken
> >kmna...@gmail.com
> >914-450-0816 (tel)
> >347-730-4813 (fax)
> >
> >
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] extracting months from a data

2016-03-09 Thread Dalthorp, Daniel
?as.Date

On Wed, Mar 9, 2016 at 10:14 AM, KMNanus  wrote:

> I have a series of dates in  format 3-Oct, 10-Oct, 20-Oct, etc.
>
> I want to create a variable of just the month.  If I convert the date to a
> character string, substr is ineffective because some of the dates have 5
> characters (3-Oct) and some have 6 (10-Oct).
>
> Is there a date function that accomplishes this easily?
>
> Ken
> kmna...@gmail.com
> 914-450-0816 (tel)
> 347-730-4813 (fax)
>
>
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Ruofei Mo - How can I generate correlated data with non-normal distribution?

2016-03-03 Thread Dalthorp, Daniel
Ruofei,

Ben's suggestion is simple and gets you close:

require(MASS)
nsim <- 100
rho <- -.9
Z <- mvrnorm(nsim, mu=c(0,0),Sigma = cbind(c(1,rho),c(rho, 1)))
U <- pnorm(Z);
a <- Z[,1]
b <- qunif(U[,2])
cor(a,b)

Pearson correlation characterizes the linear relationship between normal
r.v.'s, but there's always a question about what Pearson correlation means
for non-normal r.v.'sthe "close" approach that Ben gave gives a pair of
r.v.'s with a non-linear relationship (because of the pnorm non-linear
transformation), which can be seen if you plot the means of a in bins
across the range of b.

plot(0,0,type='n',xlim=range(a), ylim=c(-.2,1.1))
for (i in seq(0,.99,by=0.01)){
  ind<-which(b>min(b)+i*diff(range(b)) & b<=min(b)+(i+.01)*diff(range(b)))
  points(mean(a[ind]),i-.005,pch=3) # means of a in 100 bins that span the
range of b
}

# so Spearman rank correlation is often used for "correlation" between
non-normal r.v.'s. Exact Spearman correlations can be attained using the
same approach, but adjusting the target correlation.

# to get Spearman correlation of rho = -0.90, use 2*sin(rho*pi/6) in place
of rho in the mvrnorm simulation:
nsim <- 100
rho <- -.9
Z <- mvrnorm(nsim, mu=c(0,0),Sigma =
cbind(c(1,2*sin(rho*pi/6)),c(2*sin(rho*pi/6), 1)))
a<-Z[,1]; b<-qunif(pnorm(Z[,2]))
cor(rank(a),rank(b))

# this gives r.v.'s with exact Spearman correlations as desired, while
aiming at Pearson correlation tends to be off by some amount

TargetCorrelation<-seq(-.99, -.1, by=.01)
SimulatedCorrelationP<-numeric(length(TargetCorrelation))
SimulatedCorrelationS<-numeric(length(TargetCorrelation))

nsim<-10
for (i in 1:length(TargetCorrelation)){
  rho<-TargetCorrelation[i]
  Z <- mvrnorm(nsim, mu=c(0,0),Sigma = cbind(c(1,rho),c(rho, 1)))
  U <- pnorm(Z);
  a <- Z[,1]
  b <- qunif(U[,2])
  SimulatedCorrelationP[i]<-cor(a,b)

  Z <- mvrnorm(nsim, mu=c(0,0),Sigma =
cbind(c(1,2*sin(rho*pi/6)),c(2*sin(rho*pi/6), 1)))
  U <- pnorm(Z);
  a <- Z[,1]
  b <- qunif(U[,2])
  SimulatedCorrelationS[i]<-cor(rank(a),rank(b))
}
plot(TargetCorrelation,SimulatedCorrelationP)
points(TargetCorrelation,SimulatedCorrelationS,pch=20)
lines(c(-1,0),c(-1,0),col=2)
plot(TargetCorrelation,SimulatedCorrelationP)
points(TargetCorrelation,SimulatedCorrelationS,pch=20)
lines(c(-1,0),c(-1,0),col=2)


-Dan

On Wed, Mar 2, 2016 at 3:46 PM, Ben Bolker  wrote:

> Ruofei Mo【莫若飞】 <911mruofei  tongji.edu.cn> writes:
>
> >
> > Hi, All,
> >
> > I have a question about how to generate correlated data with non-normal
> > distribution? Basic, I have a variable a that follows a normal
> distribution,
> > a ~ N(0,1), then I want to generate another variable b that follows a
> > uniform distribution, b ~ U(0, 1). Most importantly, I want the
> correlation
> > between a and b to be fixed at -.9, cor(a,b) = -.90
> >
> > I tried the following code,
> >
> > ### Correlation matrix rmvnorm() function ###
> >
>
>   I don't know that there's a closed-form solution to this problem.
> Here's an attempt to do it by brute force.  By eyeball, you need to
> set the nominal rho to about -0.92 to get a realized rho of -0.9.
>
> simfun <- function(rho,n=1) {
> cormat <- matrix(c(1, rho, rho, 1), ncol = 2)
> dd <- setNames(data.frame(MASS::mvrnorm(1000, mu=c(0,0),
> Sigma=cormat)),
>c("a","trans"))
> dd <- transform(dd,
>b=pnorm(trans,mean(trans),sd(trans)))
> dd[,c("a","b")]
> }
>
> cvec <- seq(-0.999,-0.85,length=51)
> res <- expand.grid(rho=cvec,rep=1:10)
> set.seed(101)
> res$cor <- sapply(res$rho,
>   function(r) cor(simfun(rho=r,n1e6))[1,2])
>
> par(las=1,bty="l")
> plot(cor~rho,data=res)
> abline(a=0,b=1,col=2)
> abline(h=-0.9,col=4)
> abline(v=-0.92,col=4)
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] output my results into Excel

2016-03-02 Thread Dalthorp, Daniel
Sorry, I was assuming your data was a matrix (as you indicated in your
question).

Try:

write.table(as.matrix(PRdist), file = 'clipboard', sep = '\t', row.names =
F, col.names = F)

-Dan

On Wed, Mar 2, 2016 at 1:01 PM, Michael <elopomo...@hotmail.com> wrote:

> I got an error message.
>
>
> > write.table(PRdist, file = 'clipboard', sep = '\t', row.names = F,
> col.names = F)
> Error in as.data.frame.default(x[[i]], optional = TRUE) :
>   cannot coerce class ""dist"" to a data.frame
>
> I think because my PRdist is a value, not a data frame.  However, I am not
> sure.  Any advice?
>
>
> Thanks for your help.
>
>
> Mike
>
>
> --
> *From:* Dalthorp, Daniel <ddalth...@usgs.gov>
> *Sent:* Wednesday, March 2, 2016 3:50 PM
> *To:* Michael
> *Cc:* r-help@r-project.org
> *Subject:* Re: [R] output my results into Excel
>
> Hi Michael,
> If you are working in Windows:
>
> # You can put the matrix directly into the clipboard
> write.table(PRdist, file = 'clipboard', sep = '\t', row.names = F,
> col.names = F)
>
> The "sep" argument tells what character to use for separating columns.
> Default for Excel is tab (i.e. '\t')
>
> Default for write.table on a matrix or 2-d array is to write column names
> (as "V1", "V2", etc.) and row names ("1", "2", etc.). If you don't want
> those added to your matrix, tell R via row.names = FALSE, col.names = FALSE
>
>
>
> -Dan
>
> On Wed, Mar 2, 2016 at 12:31 PM, Michael <elopomo...@hotmail.com> wrote:
>
>> I can get R to calculate the distance that I want between my data
>> points.  However, I am stuck trying to get R to output the data so I can
>> paste it into Excel.  Instead, R outputs a matrix mess in the console.
>>
>> Below are the steps I am taking to calculate the distance between my
>> data.  Also, I have 42 different data points.
>>
>> # Calculate the Euclidean distance between each datapoint using
>> # the function dist()
>>
>> PRdist = dist(my_data) ;  PRdist
>>
>> I would greatly appreciate if someone can tell me how to output my matrix
>> from the dist function into something I can paste into Excel.
>>
>> Mike
>>
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalth...@usgs.gov
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] output my results into Excel

2016-03-02 Thread Dalthorp, Daniel
Hi Michael,
If you are working in Windows:

# You can put the matrix directly into the clipboard
write.table(PRdist, file = 'clipboard', sep = '\t', row.names = F,
col.names = F)

The "sep" argument tells what character to use for separating columns.
Default for Excel is tab (i.e. '\t')

Default for write.table on a matrix or 2-d array is to write column names
(as "V1", "V2", etc.) and row names ("1", "2", etc.). If you don't want
those added to your matrix, tell R via row.names = FALSE, col.names = FALSE



-Dan

On Wed, Mar 2, 2016 at 12:31 PM, Michael  wrote:

> I can get R to calculate the distance that I want between my data points.
> However, I am stuck trying to get R to output the data so I can paste it
> into Excel.  Instead, R outputs a matrix mess in the console.
>
> Below are the steps I am taking to calculate the distance between my
> data.  Also, I have 42 different data points.
>
> # Calculate the Euclidean distance between each datapoint using
> # the function dist()
>
> PRdist = dist(my_data) ;  PRdist
>
> I would greatly appreciate if someone can tell me how to output my matrix
> from the dist function into something I can paste into Excel.
>
> Mike
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plot multiple similar equations in r

2016-03-02 Thread Dalthorp, Daniel
Or, if you want easy labels, you can play around with contour graphs.

?contour # will give you info on how to make contour plots

The basic idea is to construct a matrix of z-values...one z for every
combination of x and y
contour(x,y,z)

The x's would then be the x-values you want in
(0.37273*log(x)-1.79389))/0.17941 for whatever range of x's you want
The y's would be values from -5 to 5 (or whatever range you want)
The z's would be values like 0.4, 0.5, etc. or exp(y + x)

?outer # will tell you how to create z from x and y

x<-seq(1,10,length=100) # values for x-axis
y<-seq(2, 10, length=100) # values for y-axis
z<-exp(outer((0.37273*log(x)-1.79389)/0.17941,y,"+"))
contour(x,y,z,levels=seq(.1,1.1,by=.1))

-Dan

On Wed, Mar 2, 2016 at 9:03 AM, Jinggaofu Shi  wrote:

> Hi, there I am new on R. I want to plot a graph like this.
>
> The curves are created by these equations :
> (log(0.4)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.5)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.6)-(0.37273*log(x)-1.79389))/0.17941, etc. The equations are
> similar, the only difference is the first log(XXX). I already manually draw
> the graph by repeating plot() for each equation. But I think there must be
> a way to just assign a simple variable like x<-c(0.4,0.5,0.6,0.7), and then
> plot all the curves automatically. I tried to use data frame to make a set
> of equations, but failed. Could somebody help me? Thank you very much!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plot multiple similar equations in r

2016-03-02 Thread Dalthorp, Daniel
A simple solution that will give you an idea of some of the plot parameters:

x<-seq(1,10,length=1000) # values for x-axis
x0<-c(0.4,0.5,0.6,0.7)
miny<-(log(min(x0))-(0.37273*log(max(x))-1.79389))/0.17941 # minimum
y-value to show on graph
maxy<-(log(max(x0))-(0.37273*log(min(x))-1.79389))/0.17941 # maximum
y-value to show on graph
plot(1,1, xlim=range(x), ylim=c(miny,maxy), type='n') # a blank figure to
put lines on
for (i in x0) lines(x,(log(i)-(0.37273*log(x)-1.79389))/0.17941) # putting
the lines on


On Wed, Mar 2, 2016 at 9:03 AM, Jinggaofu Shi  wrote:

> Hi, there I am new on R. I want to plot a graph like this.
>
> The curves are created by these equations :
> (log(0.4)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.5)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.6)-(0.37273*log(x)-1.79389))/0.17941, etc. The equations are
> similar, the only difference is the first log(XXX). I already manually draw
> the graph by repeating plot() for each equation. But I think there must be
> a way to just assign a simple variable like x<-c(0.4,0.5,0.6,0.7), and then
> plot all the curves automatically. I tried to use data frame to make a set
> of equations, but failed. Could somebody help me? Thank you very much!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Pairing and

2016-02-11 Thread Dalthorp, Daniel
Hi Val,
There are probably more elegant ways to do it, but the following is fairly
transparent:

# input data arranged as an array:
indat<-cbind(c(1,2,2,1),c(1,2,1,1),c(2,2,2,2),c(2,2,2,2),c(2,2,2,1),c(2,2,2,2),c(2,2,2,1),c(2,2,2,2),c(1,2,1,1),c(1,2,1,2))
indat

outdat<-array(dim=c(dim(indat)[1],dim(indat)[2]/2)) # output data has same
number of rows and half as many columns
for (i in 1:dim(outdat)[2]){
  outdat[,i]<-apply(indat[,(i-1)*2+1:2],F=sum,M=1) # each column of output
= sum(two columns of input)
}
outdat[outdat==2]<-0 # allele pairs that sum to 2 are genotype 0
outdat[outdat==4]<-1 # allele pairs that sum to 4 are genotype 1
# allele pairs that sum to 3 are genotype 3, so no need to change anything
with them
outdat

# faster but a little more difficult to see what is going on:
outdat<-indat %*%
array(c(rep(c(rep(1,2),rep(0,dim(indat)[2])),dim(indat)[2]/2),1,1),dim=c(dim(indat)[2],dim(indat)[2]/2))
outdat[outdat==2]<-0
outdat[outdat==4]<-1
outdat

-Dan



On Thu, Feb 11, 2016 at 2:52 PM, Val  wrote:

> Hi  all,
>
> I have SNP data set: the first column is the ID and the the
> subsequent pair of columns are the alleles for each
> SNP1, SNP2 and So on. Each SNP has two columns.  Based on the alleles
> I want make phenotype
>
> if the alleles  are 1 1then  genotype is 0
>   2 2then  genotype is 1
> and if it is  1 2 or 2 1 then  genotyep is 3
>
> This is a sample data set but the actual has 13,000 SNP(26,000columns)
>
>
> Geno data
> AB95 1 1 2 2 2 2 2 2 1 1
> AB82 2 2 2 2 2 2 2 2 2 2
> AB95 2 1 2 2 2 2 2 2 1 1
> AB59 1 1 2 2 1 2 1 2 1 2
> AB32 2 1 2 2 2 2 2 2 1 2
> AB46 2 1 2 2 1 2 1 1 2 2
> AB61 1 1 2 2 1 2 1 2 1 2
> AB32 2 2 1 2 2 2 2 2 1 2
> AB35 2 2 1 2 2 2 2 2 2 2
> AB43 2 2 1 2 2 2 2 2 2 2
>
> Desired output
> AB95  0   1   1   1   0
> AB82  1   1   1   1   1
> AB95  3   1   1   1   0
> AB59  0   1   3   3   3
> AB32  3   1   1   1   3
> AB46  3   1   3   0   1
> AB61  0   1   3   3   3
> AB32  1   3   1   1   3
> AB35  1   3   1   1   1
> AB43  1   3   1   1   1
>
> I would appreciate if you help me out here.
> Thank you in advance
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Angle between two points with coordinates

2016-01-28 Thread Dalthorp, Daniel
Gwennaël,

Does the %% operator work for you?

It gives x mod y (or the remainder after dividing x into y...result is
guaranteed to be <=0 and >y)

E.g.

 -150 %% 360  # 210
570 %% 360# 210

https://stat.ethz.ch/R-manual/R-devel/library/base/html/Arithmetic.html

-Dan

On Thu, Jan 28, 2016 at 10:38 AM, Jeff Newmiller 
wrote:

> Functions return one value.
>
> Look at ?atan2 to address ambiguity in identifying angles.
> --
> Sent from my phone. Please excuse my brevity.
>
> On January 28, 2016 9:09:53 AM PST, "Gwennaël Bataille" <
> gwennael.batai...@uclouvain.be> wrote:
> >Dear all,
> >I'd like to calculate the angle from one point (origin) to another
> >(target), whatever their coordinates.
> >But I encounter some problems (detailed below). The problem could be
> >solved if one of you could answer positively to one of the following
> >questions:
> >
> >1) Is there a function in R converting angles in a standardized manner?
> >
> >(for example, converting -150 or 570 (=210+360) into 210)
> >
> >2) If not, would you know a function arccos or arcsin returning two
> >different angles as an output instead of one?
> >
> >
> >
> >Details:
> >
> >I'd like to calculate the angle from one point (origin) to another
> >(target), whatever their coordinates.
> >For this, the acos and asin functions work pretty well when the end
> >point is located right and above the starting point (first quarter of
> >the trigonometric circle), but are problematic otherwise.
> >
> ># In the following example, the origin is (0,0) and the target
> >(0.8660254, 0.5) is located at an angle of 30° :
> >acos( (0.8660254 - 0) )*180/pi
> >asin( (0.5 - 0) )*180/pi
> ># Both acos and asin give the same answer : 30
> >
> ># If now, the origin is (0.8660254, 0.5) and the target is (0,0), the
> >target is located at an angle of -150° :
> >acos( (0 - 0.8660254) )*180/pi
> >asin( (0 - 0.5) )*180/pi
> ># Here the results are different : 150 and -30
> >
> ># In fact, there are two angle solutions giving the same cosinus : 150
> >and -(150)
> ># And for sinus as well : -30 and ( 180 - (-30) ) = 210° = -150°
> >-acos( (0 - 0.8660254) )*180/pi
> >180 - asin( (0 - 0.5) )*180/pi
> ># But I cannot test equality between the two :
> >-acos( (0 - 0.8660254) )*180/pi==180 - asin( (0 - 0.5) )*180/pi
> ># FALSE, since 210 != -150  (it's only the case when those two are
> >angles)
> >
> >
> >Thank you very much in advance for your answers!
> >
> >Best regards,
> >
> >
> >Gwennaël
> >
> >--
> >Gwennaël BATAILLE, PhD student - Teaching assistant
> >
> >Earth and Life Institute
> >Université Catholique de Louvain
> >1348 Louvain-la-Neuve
> >BELGIUM
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] tcltk table: get celltag value

2016-01-25 Thread Dalthorp, Daniel
I'm finding it very difficult to figure out how to read the value of
"celltag" for a given cell in a tktable.

I'm sure it's something like:

tcl(classTable, "get", "celltag", row, column)

but of the dozens of variations of names, options, args, and formats I've
tried, nothing is working. Any suggestions?

Much thanks.

-Dan

-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] tcltk table "validateCommand"

2016-01-22 Thread Dalthorp, Daniel
I'd like to allow users to edit data in tcltk tables and to use vcmd to
validate data entry, e.g., not allowing non-numbers to be entered in
numeric cells and not allowing '\n' to be entered in text cells.

The problem is that I can't figure out how to "see" their data entry before
it is entered, although it looks like %S can be somehow used in vcmd to get
this information.

Example: to disallow '\n' to be entered into a cell in an editable table:

require(tcltk2)
tt<-tktoplevel(); tfr<-tkframe(tt); tkgrid(tfr)
tableData<-tclArray()
tableData[[0,0]]<-"junk"

CellValidation<-function(){

## http://www.tcl.tk/community/hobbs/tcl/capp/tkTable/tkTable.html says:
## *%S* For *ValidateCommand*, it is the potential new value of the cell
being validated.
## which is exactly what I want, but I can't figure out how to do that.
## The following allows one bad character and then disallows further edits

  testval<-tclvalue(tcl(table1,"curvalue"))

  if (length(grep("\n",testval))>0)  return(tcl("expr", FALSE))  else
 return(tcl("expr", TRUE))
}

table1<<-tk2table(tfr,
  rows=1,cols=1,
  selectmode="extended",
  variable=tableData,
  validate=T,
  vcmd=CellValidation
)

tcl(table1,"tag","configure", "active", fg='black',bg=colors()[411])
tkgrid(table1)

How can I get the %S value rather than the tcl(table1,"curvalue")?

Much thanks for any help.

-Dan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tcltk tkwidget(..."table")

2016-01-22 Thread Dalthorp, Daniel
Thanks, Adrian...the discussions about  R bindings to Tcl and Tk look very
helpful!

-Dan

On Fri, Jan 22, 2016 at 2:49 AM, Adrian Waddell <adrian.wadd...@gmail.com>
wrote:

> I have written some content about the R bindings to Tcl and Tk:
>
> http://waddella.github.io/loon/learn_R_tcltk.html
>
> And the pack geometry manager
>
> http://adrian.waddell.ch/EssentialSoftware/Rtcltk_geometry.pdf
>
> But if you have no experience with building graphical user interfaces then
> you might want to look into a book on Tk. "Effective TCL/TK programming" by
> Harrison and McLennan is a good one.
>
> Greetings,
>
> Adrian
> On Jan 21, 2016 10:36 PM, "Dalthorp, Daniel" <ddalth...@usgs.gov> wrote:
>
>> >  Once you're up to speed on those issues...
>>
>> Any suggestions for getting up to speed on those issues?
>>
>>
>>
>> On Thu, Jan 21, 2016 at 11:46 AM, peter dalgaard <pda...@gmail.com>
>> wrote:
>>
>> >
>> > > On 21 Jan 2016, at 00:25 , Dalthorp, Daniel <ddalth...@usgs.gov>
>> wrote:
>> > >
>> > > Thanks, Peter.
>> > >
>> > > I'm sure that's right, but it requires knowing: (1) that there's
>> > something called the "width subcommand", and (2) how to format the call
>> to
>> > that command/subcommand.
>> > >
>> >
>> > Yes, there's a fair amount of that going on with the tcltk interface.
>> You
>> > need to both grasp the rules for passing arguments to the underlying Tcl
>> > command, and know how to find and read the Tcl/Tk documentation. Once
>> > you're up to speed on those issues it's not all that hard to find stuff
>> in
>> > (for the present case), say,
>> > http://tktable.sourceforge.net/tktable/doc/tkTable.html
>> >
>> > The situation may be unfortunate, but the alternative is for "someone"
>> to
>> > sit down an convert all relevant Tcl/Tk documentation to R help files.
>> >
>> > -pd
>> >
>> >
>> > > I was able to do it eventually but only after a few hours of effort
>> > searching the web for help.
>> > >
>> > > E.g. with a table (called table1) with 3 columns and want to set
>> widths
>> > to 30, 5, and 5:
>> > >
>> > > colwidths<-c(30, 5, 5)
>> > >
>> > > for(i in 1:3) {
>> > >   tcl(table1, "width", i - 1, colwidths[i])
>> > > }
>> > >
>> > >
>> > >
>> > > On Wed, Jan 20, 2016 at 3:07 PM, peter dalgaard <pda...@gmail.com>
>> > wrote:
>> > >
>> > > > On 19 Jan 2016, at 20:48 , Dalthorp, Daniel <ddalth...@usgs.gov>
>> > wrote:
>> > > >
>> > > > Does anyone know a simple way to create a tcltk table with columns
>> of
>> > > > varying widths?
>> > >
>> > > Create a table, then set the width of the columns with the width
>> > subcommand?
>> > >
>> > > -pd
>> > >
>> > >
>> > > pathName width ?col? ?value col value ...? If no col is specified,
>> > returns a list describing all cols for which a width has been set. If
>> col
>> > is specified with no value, it prints out the width of that col in
>> > characters (positive number) or pixels (negative number). If one or more
>> > col-value pairs are specified, then it sets each col to be that width in
>> > characters (positive number) or pixels (negative number). If value is
>> > default, then the col uses the default width, specified by -colwidth.
>> > >
>> > >
>> > >
>> > > >
>> > > > -Dan
>> > > >
>> > > >
>> > > >
>> > > > --
>> > > > Dan Dalthorp, PhD
>> > > > USGS Forest and Rangeland Ecosystem Science Center
>> > > > Forest Sciences Lab, Rm 189
>> > > > 3200 SW Jefferson Way
>> > > > Corvallis, OR 97331
>> > > > ph: 541-750-0953
>> > > > ddalth...@usgs.gov
>> > > >
>> > > >   [[alternative HTML version deleted]]
>> > > >
>> > > > __
>> > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > > > https://stat.ethz.ch/mailman/listinfo/r-help
>> > > > PLEASE do read the posting guide

Re: [R] tcltk tkwidget(..."table")

2016-01-21 Thread Dalthorp, Daniel
>  Once you're up to speed on those issues...

Any suggestions for getting up to speed on those issues?



On Thu, Jan 21, 2016 at 11:46 AM, peter dalgaard <pda...@gmail.com> wrote:

>
> > On 21 Jan 2016, at 00:25 , Dalthorp, Daniel <ddalth...@usgs.gov> wrote:
> >
> > Thanks, Peter.
> >
> > I'm sure that's right, but it requires knowing: (1) that there's
> something called the "width subcommand", and (2) how to format the call to
> that command/subcommand.
> >
>
> Yes, there's a fair amount of that going on with the tcltk interface. You
> need to both grasp the rules for passing arguments to the underlying Tcl
> command, and know how to find and read the Tcl/Tk documentation. Once
> you're up to speed on those issues it's not all that hard to find stuff in
> (for the present case), say,
> http://tktable.sourceforge.net/tktable/doc/tkTable.html
>
> The situation may be unfortunate, but the alternative is for "someone" to
> sit down an convert all relevant Tcl/Tk documentation to R help files.
>
> -pd
>
>
> > I was able to do it eventually but only after a few hours of effort
> searching the web for help.
> >
> > E.g. with a table (called table1) with 3 columns and want to set widths
> to 30, 5, and 5:
> >
> > colwidths<-c(30, 5, 5)
> >
> > for(i in 1:3) {
> >   tcl(table1, "width", i - 1, colwidths[i])
> > }
> >
> >
> >
> > On Wed, Jan 20, 2016 at 3:07 PM, peter dalgaard <pda...@gmail.com>
> wrote:
> >
> > > On 19 Jan 2016, at 20:48 , Dalthorp, Daniel <ddalth...@usgs.gov>
> wrote:
> > >
> > > Does anyone know a simple way to create a tcltk table with columns of
> > > varying widths?
> >
> > Create a table, then set the width of the columns with the width
> subcommand?
> >
> > -pd
> >
> >
> > pathName width ?col? ?value col value ...? If no col is specified,
> returns a list describing all cols for which a width has been set. If col
> is specified with no value, it prints out the width of that col in
> characters (positive number) or pixels (negative number). If one or more
> col-value pairs are specified, then it sets each col to be that width in
> characters (positive number) or pixels (negative number). If value is
> default, then the col uses the default width, specified by -colwidth.
> >
> >
> >
> > >
> > > -Dan
> > >
> > >
> > >
> > > --
> > > Dan Dalthorp, PhD
> > > USGS Forest and Rangeland Ecosystem Science Center
> > > Forest Sciences Lab, Rm 189
> > > 3200 SW Jefferson Way
> > > Corvallis, OR 97331
> > > ph: 541-750-0953
> > > ddalth...@usgs.gov
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> > --
> > Peter Dalgaard, Professor,
> > Center for Statistics, Copenhagen Business School
> > Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> > Phone: (+45)38153501
> > Office: A 4.23
> > Email: pd@cbs.dk  Priv: pda...@gmail.com
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center
> > Forest Sciences Lab, Rm 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tcltk: write '[' and ']' in a table cell

2016-01-21 Thread Dalthorp, Daniel
Many thanks, Peter.

Simple, works perfectly, and nigh on impossible to figure out without your
help.

To summarize...in my example, I need to do:

junk[[0,0]] <- as.tclObj(lbl,drop=T) # instead of junk[[0,0]]<-lbl

It works for spaces, brackets, parentheses, and all manner of special
characters.

-Dan

On Thu, Jan 21, 2016 at 12:08 PM, peter dalgaard <pda...@gmail.com> wrote:

> “Right now I’m having amnesia and déjà vu at the same time. I think I’ve
> forgotten this before.” ― Steven Wright
>
> Check if this might be the same issue as the one of embedded spaces in
>
> https://stat.ethz.ch/pipermail/r-help/2009-January/378558.html
>
> -pd
>
> > On 21 Jan 2016, at 02:12 , Dalthorp, Daniel <ddalth...@usgs.gov> wrote:
> >
> > I know it should not be difficult to write the string:
> >
> > i<-4
> > j<-17
> > lbl<-paste0("[", i, ", ", j, "]")
> >
> > # to a table, but I'm having a devil of a time trying to figure out how
> to
> > do it.
> > # the following gives lbl surrounded by braces.
> >
> > tt<-tktoplevel()
> > tfr <- tkframe(tt)
> > tkgrid(tfr)
> > junk<-tclArray()
> > junk[[0,0]]<-lbl
> > table1<-tkwidget(tfr,"table", rows=1, cols=1, variable=junk)
> > tkgrid(table1)
> >
> >
> > How to write without the braces?
> >
> > Any quick suggestions would be very much appreciated...I've burned much
> > time trying to figure this should-be-simple problem out.
> >
> > Thanks!
> >
> >
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center
> > Forest Sciences Lab, Rm 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] tcltk: write '[' and ']' in a table cell

2016-01-20 Thread Dalthorp, Daniel
I know it should not be difficult to write the string:

i<-4
j<-17
lbl<-paste0("[", i, ", ", j, "]")

# to a table, but I'm having a devil of a time trying to figure out how to
do it.
# the following gives lbl surrounded by braces.

tt<-tktoplevel()
tfr <- tkframe(tt)
tkgrid(tfr)
junk<-tclArray()
junk[[0,0]]<-lbl
table1<-tkwidget(tfr,"table", rows=1, cols=1, variable=junk)
tkgrid(table1)


How to write without the braces?

Any quick suggestions would be very much appreciated...I've burned much
time trying to figure this should-be-simple problem out.

Thanks!



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tcltk tkwidget(..."table")

2016-01-20 Thread Dalthorp, Daniel
Thanks, Peter.

I'm sure that's right, but it requires knowing: (1) that there's something
called the "width subcommand", and (2) how to format the call to that
command/subcommand.

I was able to do it eventually but only after a few hours of effort
searching the web for help.

E.g. with a table (called table1) with 3 columns and want to set widths to
30, 5, and 5:

colwidths<-c(30, 5, 5)

for(i in 1:3) {
  tcl(table1, "width", i - 1, colwidths[i])
}



On Wed, Jan 20, 2016 at 3:07 PM, peter dalgaard <pda...@gmail.com> wrote:

>
> > On 19 Jan 2016, at 20:48 , Dalthorp, Daniel <ddalth...@usgs.gov> wrote:
> >
> > Does anyone know a simple way to create a tcltk table with columns of
> > varying widths?
>
> Create a table, then set the width of the columns with the width
> subcommand?
>
> -pd
>
>
> pathName width ?col? ?value col value ...? If no col is specified, returns
> a list describing all cols for which a width has been set. If col is
> specified with no value, it prints out the width of that col in characters
> (positive number) or pixels (negative number). If one or more col-value
> pairs are specified, then it sets each col to be that width in characters
> (positive number) or pixels (negative number). If value is default, then
> the col uses the default width, specified by -colwidth.
>
>
>
> >
> > -Dan
> >
> >
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center
> > Forest Sciences Lab, Rm 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>


-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] tcltk tkwidget(..."table")

2016-01-19 Thread Dalthorp, Daniel
Does anyone know a simple way to create a tcltk table with columns of
varying widths?

-Dan



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] creating cubes

2016-01-15 Thread Dalthorp, Daniel
How about: D<-array(dim=c(d1, d2, d3))?



On Fri, Jan 15, 2016 at 2:20 PM, Matteo Richiardi <
matteo.richia...@gmail.com> wrote:

> What is the best way to store data in a cube? That is, I need to create a
> data structure D with three indexes, say i,j,h, so that I can access each
> data point D[i,j,h], and visualise sections like D[i,j,] or D[,,h].
>
> I have tried to create an array of matrixes:
>
> D <-matrix(matrix(NA,i,j),h)
>
> but then D[i] returns a number, and not a matrix.
>
> I imagine this is a dummy question, but I did search for an answer on
> various R help sites, and found nothing straightforward. Being an
> inexperienced R user, I prefer a simple solution, even at some efficiency
> cost.
>
> Many thanks for your help.
> Matteo
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] creating cubes

2016-01-15 Thread Dalthorp, Daniel
One possibility is to arrange it as a 3-dimensional array with two 5 x 5
matrices (i.e. a 5 x 5 x 2 array):

arrD3<-array(dim=c(5,5,2))

# the first matrix is (e.g.) random normal deviates:
mat1<-matrix(rnorm(25),nrow=5,ncol=5)

# the second matrix is (e.g.) random uniform deviates:
mat2<-matrix(runif(25),nrow=5,ncol=5)

# populating your 3-d array:
arrD3[,,1]<-mat1
arrD3[,,2]<-mat2

# to see what it looks like:
arrD3



On Fri, Jan 15, 2016 at 2:57 PM, Matteo Richiardi <
matteo.richia...@gmail.com> wrote:

> Hi Daniel,
> thanks for your answer. How can I populate the array with the
> matrixes? Suppose I want to populate it with 10 matrixes
>
> matrix(NA,5,5)
>
> Matteo
>
>
> On 15 January 2016 at 22:26, Dalthorp, Daniel <ddalth...@usgs.gov> wrote:
> > How about: D<-array(dim=c(d1, d2, d3))?
> >
> >
> >
> > On Fri, Jan 15, 2016 at 2:20 PM, Matteo Richiardi
> > <matteo.richia...@gmail.com> wrote:
> >>
> >> What is the best way to store data in a cube? That is, I need to create
> a
> >> data structure D with three indexes, say i,j,h, so that I can access
> each
> >> data point D[i,j,h], and visualise sections like D[i,j,] or D[,,h].
> >>
> >> I have tried to create an array of matrixes:
> >>
> >> D <-matrix(matrix(NA,i,j),h)
> >>
> >> but then D[i] returns a number, and not a matrix.
> >>
> >> I imagine this is a dummy question, but I did search for an answer on
> >> various R help sites, and found nothing straightforward. Being an
> >> inexperienced R user, I prefer a simple solution, even at some
> efficiency
> >> cost.
> >>
> >> Many thanks for your help.
> >> Matteo
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> >
> > --
> > Dan Dalthorp, PhD
> > USGS Forest and Rangeland Ecosystem Science Center
> > Forest Sciences Lab, Rm 189
> > 3200 SW Jefferson Way
> > Corvallis, OR 97331
> > ph: 541-750-0953
> > ddalth...@usgs.gov
> >
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Use SQL in R environment

2016-01-15 Thread Dalthorp, Daniel
Very general question...try searching "R SQL" on google for a start.

On Fri, Jan 15, 2016 at 9:59 AM, Amoy Yang via R-help 
wrote:

>  Hi All,
> I am new here and a beginner for R. Can I use SQL procedure in R
> environment as it can be done in SAS starting with PROC SQL;
> Thanks for helps!
>
> Amoy
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] rjags loading error

2016-01-15 Thread Dalthorp, Daniel
What has happened?!

I get the following error message when I try to load rjags package (w/
Windows 7)...


> require(rjags)
Loading required package: rjags
Error in get(method, envir = home) :
  lazy-load database 'C:/Program Files/R/R-3.2.3/library/rjags/R/rjags.rdb'
is corrupt
In addition: Warning messages:
1: In .registerS3method(fin[i, 1], fin[i, 2], fin[i, 3], fin[i, 4],  :
  restarting interrupted promise evaluation
2: In get(method, envir = home) :
  restarting interrupted promise evaluation
3: In get(method, envir = home) : internal error -3 in R_decompress1

I was able to use this package successfully a few months ago. Has something
changed?

Yes, I upgraded to R 3.2.3, but would that break the package?

Any help would be greatly appreciated!

Thanks.

-Dan

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] different coloured axis title labels for different axes

2016-01-11 Thread Dalthorp, Daniel
How about this:

plot(0,0,xlab='',ylab='')
mtext(side=1,line=3,text='x axis',col=4)
mtext(side=2,line=3,text='y axis',col=2)

-Dan

On Mon, Jan 11, 2016 at 7:44 AM, Evan Cooch  wrote:

> Consider a simple plot of X vs Y.  There are elements on the plot that
> represent X, or Y, that are presented in different colours (say, blue
> for X,   red for Y). Rather than use a legend, I would like to have the
> title label for the X-axis be in blue, and the title label for the
> Y-axis be in red.
>
> While it is trivial to change the color of the axis title labels for
> *both* axes at the same time, I haven't figured out how to trick thing
> into generating a blue title label for the X-axis, and a red title label
> for the Y- axis (i.e., different colours on different axes).
>
> I'm sure this is out there on searchable pages, but, I haven't managed
> to stumble across the appropriate search phrase(s).
>
> Pointers to the obvious solution welcomed in advance.
>
>
> Cheers
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] close specific graphics device

2015-12-15 Thread Dalthorp, Daniel
dev.off(which) can be used to close a specific graphics device where
"which" is the index of the device, but is there a way to assign a custom
number (or name) to a windows device so that specific window can be later
closed via dev.off (or some other method) if it is open?

The following does NOT work. The target device is not open when its dev.off
is called, and another window that later got assigned the original index
associated with the target device is closed instead.

plot(0,0,type='n') # target window to close
text(0,0,"close me")
targetindex<-dev.cur()

# unbeknownst to the programmer, user closes device by clicking the red "X"
or...
dev.off()

# user draws a new graph that he wants to keep open
plot(1,1,type='n')
text(1,1,"do not close me")

# now it's time for the program to close the original graphics device (if
it still happens to be open)
dev.off(targetindex)

# the wrong device has been closed because the original window had closed
and the index associated with original graph is now associated with
something else



I'm looking for something like:

dev.off(which = "original figure") or dev.off(which = n), where n is a
custom index (like 1) that will not be later assigned to a different
device [unless explicitly assigned that index].

Any help would be greatly appreciated.

Thanks!



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.