Re: [R] [External] converting MATLAB -> R | element-wise operation

2024-02-29 Thread Evan Cooch
Very interesting - thanks! Most of my problems are not limited by 
compute speed, but its clear that for some sorts of compute-intensive 
problems, sweep might be a limiting approach.

On 2/29/2024 6:12 PM, Richard M. Heiberger wrote:
> I decided to do a direct comparison of transpose and sweep.
>
>
> library(microbenchmark)
>
> NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)  # Example matrix
> lambda <- c(2, 3, 4)  # Example vector
> colNN <- t(NN)
>
> microbenchmark(
>sweep = sweep(NN, 2, lambda, "/"),
>transpose = t(t(NN)/lambda),
>colNN = colNN/lambda
> )
>
>
> Unit: nanoseconds
>expr   minlq mean median  uq   max neval cld
>   sweep 13817 14145 15115.06  14350 14657.5 75932   100 a
>   transpose  1845  1927  2151.68   2132  2214.0  7093   100  b
>   colNN82   123   141.86123   164.0   492   100   c
>
> Note that transpose is much faster than sweep because it is doing less work,
> I believe essentially just changing the order of indexing.
>
> Using the natural sequencing for column-ordered matrices is much much faster.
>
>> On Feb 28, 2024, at 18:43, peter dalgaard  wrote:
>>
>>> rbind(1:3,4:6)/t(matrix(c(2,3,4), 3,2))
>

[[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] converting MATLAB -> R | element-wise operation

2024-02-28 Thread Evan Cooch
Many thanks for the collective answers -- consider this a thank you to 
the group. I had 'guessed' it had something to do with 'columns then 
rows' or vice versa (MATLAB convention vs R convention), but had never 
heard about 'sweep' before. Most of the time when I run into 'matrix 
orientation' issues, I simply transpose as needed, but that can get 
clunky. 'sweep' has some utility I'll tuck away if needed in future.

Cheers - and thanks again.

On 2/27/2024 4:37 PM, Richard M. Heiberger wrote:
>> t(t(NN)/lambda)
>   [,1]  [,2] [,3]
> [1,]  0.5 0.667 0.75
> [2,]  2.0 1.667 1.50
> R  matrices are column-based. MATLAB matrices are row-based.
>
>> On Feb 27, 2024, at 14:54, Evan Cooch  wrote:
>>
>> So, trying to convert a very long, somewhat technical bit of lin alg
>> MATLAB code to R. Most of it working, but raninto a stumbling block that
>> is probaably simple enough for someone to explain.
>>
>> Basically, trying to 'line up' MATLAB results from an element-wise
>> division of a matrix by a vector with R output.
>>
>> Here is a simplified version of the MATLAB code I'm translating:
>>
>> NN = [1, 2, 3; 4, 5, 6];  % Example matrix
>> lambda = [2, 3, 4];  % Example vector
>> result_matlab = NN ./ lambda;
>>
>> which yields
>>
>>   0.5   0.7   0.75000
>>   2.0   1.7   1.5
>>
>>
>> So, the only way I have stumbled onto in R to generate the same results
>> is to use 'sweep'. The following 'works', but I'm hoping someone can
>> explain why I need something as convoluted as this seems (to me, at least).
>>
>> NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)  # Example matrix
>> lambda <- c(2, 3, 4)  # Example vector
>> sweep(NN, 2, lambda, "/")
>>
>>
>>   [,1]  [,2] [,3]
>> [1,]  0.5 0.667 0.75
>> [2,]  2.0 1.667 1.50
>>
>> First tried the more 'obvious' NN/lambda, but that yields 'the wrong
>> answer' (based solely on what I'm trying to accomplish):
>>
>>
>> [,1] [,2] [,3]
>> [1,] 0.50  0.5  1.0
>> [2,] 1.33  2.5  1.5
>>
>> So, why 'sweep'?
>>
>> [[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 guidehttp://www.r-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

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


[R] converting MATLAB -> R | element-wise operation

2024-02-27 Thread Evan Cooch
So, trying to convert a very long, somewhat technical bit of lin alg 
MATLAB code to R. Most of it working, but raninto a stumbling block that 
is probaably simple enough for someone to explain.

Basically, trying to 'line up' MATLAB results from an element-wise 
division of a matrix by a vector with R output.

Here is a simplified version of the MATLAB code I'm translating:

NN = [1, 2, 3; 4, 5, 6];  % Example matrix
lambda = [2, 3, 4];  % Example vector
result_matlab = NN ./ lambda;

which yields

  0.5   0.7   0.75000
  2.0   1.7   1.5


So, the only way I have stumbled onto in R to generate the same results 
is to use 'sweep'. The following 'works', but I'm hoping someone can 
explain why I need something as convoluted as this seems (to me, at least).

NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE)  # Example matrix
lambda <- c(2, 3, 4)  # Example vector
sweep(NN, 2, lambda, "/")


  [,1]  [,2] [,3]
[1,]  0.5 0.667 0.75
[2,]  2.0 1.667 1.50

First tried the more 'obvious' NN/lambda, but that yields 'the wrong 
answer' (based solely on what I'm trying to accomplish):


    [,1] [,2] [,3]
[1,] 0.50  0.5  1.0
[2,] 1.33  2.5  1.5

So, why 'sweep'?

[[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] linear programming in R | limits to what it can do, or my mistake?

2024-01-30 Thread Evan Cooch
Question for 'experts' in LP using R (using the lpSolve package, say) -- 
which does not apply to me for the sort of problem I describe below.
I've run any number of LP's using lpSolve in R, but all of them to date 
have objective and constraint functions that both contain the same 
variables. This lets you set up a LHS and RHS matrix/vector that are 
symmetrical.

But, for a problem a student posed in class, I'm stuck with how to do it 
in R, if its even possible (its trivial in Maxima, Maple...even using 
Solver in Excel, but I haven't been remotely successful in getting 
anything to work in R).

Suppose you have a production system that at 4 sequential time steps 
generate 640, 825, 580, and 925 units. At each time step, you need to 
decide how many of those units need to be 'quality control' (QC) checked 
in some fashion, subject to some constraints.

  --> at no point in time can the number of units in the system be >1000
  --> at the end of the production cycle, there can be no units left
  --> 'QC checking' costs money, varying as a function of the time step 
-- 35, 55, 50 and 65 for each unit, for each time step in turn.

Objective is to minimize total cost. The total cost objective function 
is trivial. Let p1 = number sent out time step 1, p2 number sent out at 
time step 3, and so on. So, total cost function we want to minimize is 
simply

   cost=(35*p1)+(55*p2)+(50*p3)+(65*p4)

where p1+p2+p3+p4=(640+825+580+925)=2970 (i.e., all the products get 
checked). The question is, what number do you send out at each time step 
to minimize cost?

Where I get hung up in R is the fact that if I let t(i) be the number of 
products at each time step, then

     t1=640,
     t2=t1-p1+825
     t3=t2-p2+580
     t4=t3-p3+925

such that t1+t2+t3+t4=2970 (as it must), with additional constraints being

   p1<=t1, p2<=t2, p3<=t3, p4<=t4, {t1..t4}<=1000, and t4-p4=0.

There may be algebraic ways to reduce the number of functions needed to 
describe the constraints, but I can't for the life of me see how I can 
create a coefficient matrix (typically, the LHS) since each line of said 
matrix, which corresponds to the constraints, needs to be a function of 
the unknowns in the objective function -- being, p1, p2, p3 and p4.

In Maple (for example), this is trivial:

  cost:=35*p10+55*p12+50*p14+65*p16;
cnsts:={t10=640,t12=t10-p10+825,t14=t12-p12+580,t16=t14-p14+925,t16-p16=0,p10<=t10,p12<=t12,p14<=t14,p16<=t16,t10<=1000,t12<=1000,t14<=1000,t16<=1000};
      Minimize(cost,cnsts,assume={nonnegative});

which yields (correctly):

p1=640, p2=405, p3=1000, p4=925

for minimized cost of 154800.

Took only a minute to also set this up in Maxima, and using Solver in 
Excel. But danged if I can suss out any way to do this in R.

Pointers to the obvious welcome.
[[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] reference generated var name in loop

2023-05-28 Thread Evan Cooch

Thanks very much - that does the trick. Many good suggestions.

On 5/26/2023 12:00 PM, Greg Snow wrote:

Using the `assign` function is almost always a sign that you are
making things more complicated than is needed.  It is better to work
directly with lists, which make it much easier to set and get names.

Your code and description can be done pretty simply using the `lapply
function (often easier than using a loop if the desire is to save the
output of each iteration), here is one example:

parms <- c(a=4, b=6, c=11)

tmp1 <- lapply(parms, function(mu){
   rnorm(5, mu, 0.25)
})

names(tmp1) <- paste0(names(parms), "_r")
ranvec <- as.data.frame(tmp1)
ranvec

We can skip the temporary variable(s) by using pipes like this:

parms |>
   lapply( rnorm, n=5, sd=0.25 ) |>
   setNames( paste0(names(parms), "_r")) |>
   as.data.frame()

Your line using `sub` does not do anything.  While the `=` sign was
used to create the vector with names, the vector itself does not
contain any `=` signs and so there is no reason to try to remove
anything.  The `parms` vector already contains the numbers that you
are trying to extract (plus a names attribute which will be ignored
when not needed, so usually there is no reason to remove the names).

The `lapply` function runs the function passed in (an anonymous
function in the first example, the `rnorm` function in the second) on
each element of the vector/list passed in as the first argument and
stores each result as an element in a list, which is then returned
(and in my examples named then converted to a data frame).

The `sapply` function would combine the resulting vectors into a
matrix, and would handle the naming automatically, so something as
simple as:

sapply(parms, rnorm, n=5, sd=0.25)

may do what you want (you could pipe that to `as.data.frame` if you
really need a data frame).


The purrr package (part of the tidyverse) gives some additional
functions similar to `lapply` and `sapply` but with extra bells and
whistles.

If you really want to use a loop, then take advantage of the fact that
the data frame is a special case of a list and try something like:

ranvec <- data.frame(row.names=1:5)
for(i in seq_along(parms)) {
   tmp.nm <- paste0(names(parms)[i], '_r')
   ranvec[[tmp.nm]] <- rnorm(5, parms[i], 0.25)
}

or

ranvec <- data.frame(row.names=1:5)
for(nm in names(parms)) {
   tmp.nm <- paste0(nm, '_r')
   ranvec[[tmp.nm]] <- rnorm(5, parms[nm], 0.25)
}


On Fri, May 26, 2023 at 8:50 AM Evan Cooch  wrote:

Greetings --

I'm trying to write some code that basically does the following:

1\ user inputs a list of parameter names, and parameter values.

2\ code parses this list, extracting parameter names and values separately

3\ loops over the number of parameters, and for each parameter,
generates something (say, rnorm) based on the value corresponding to
that parameter.

4\ assigns a new name to the vector of rnorm data, where the name is a
permutation of the original parameter name. In the example (below) I
simply past "_r" to the original parameter name (to indicate, say, its
some rnorm values associated that that variable).

5\the 'I'm stumped' part -- output the newly named vector into something
(say, data.frame), which requires being able to reference the newly
named vector, which is what can't figure out how to accomplish.

Here is a MWE of sorts -- the starting list of parameter names and
values is in a list I call parms.

   parms <- c(a=4,b=6,c=11) # list of parms user could pass to a function

   nvars <- names(parms)  # extract parameter names

   vals <- sub("\\=.*", "", parms) # extract parameter values

   n <- length(parms) # determine number of parameters

   ranvec <- data.frame() # to store stuff from loop

   for (i in 1:n) {
 pn <- nvars[i]; # get name of parm variable
 rn <- rnorm(5,as.numeric(vals[i]),0.25) # generate rnorm based on
parm value
 assign(paste(pn, "_r", sep=""),rn) # creates a_r, b_r, c_r...
 ** here is where I want to output to ranvec, but I can't see how to
do it since the loop doesn't know the name of the new var created in
preceding step...**
   }


In the end, I want to create a data frame containing rnorm deviates for
each of a set of user-specified variables, which I can reference in some
fashion using a permuted version of the original variable name.

Suggestions?

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





__
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] reference generated var name in loop

2023-05-26 Thread Evan Cooch

Greetings --

I'm trying to write some code that basically does the following:

1\ user inputs a list of parameter names, and parameter values.

2\ code parses this list, extracting parameter names and values separately

3\ loops over the number of parameters, and for each parameter, 
generates something (say, rnorm) based on the value corresponding to 
that parameter.


4\ assigns a new name to the vector of rnorm data, where the name is a 
permutation of the original parameter name. In the example (below) I 
simply past "_r" to the original parameter name (to indicate, say, its 
some rnorm values associated that that variable).


5\the 'I'm stumped' part -- output the newly named vector into something 
(say, data.frame), which requires being able to reference the newly 
named vector, which is what can't figure out how to accomplish.


Here is a MWE of sorts -- the starting list of parameter names and 
values is in a list I call parms.


 parms <- c(a=4,b=6,c=11) # list of parms user could pass to a function

 nvars <- names(parms)  # extract parameter names

 vals <- sub("\\=.*", "", parms) # extract parameter values

 n <- length(parms) # determine number of parameters

 ranvec <- data.frame() # to store stuff from loop

 for (i in 1:n) {
   pn <- nvars[i]; # get name of parm variable
   rn <- rnorm(5,as.numeric(vals[i]),0.25) # generate rnorm based on 
parm value

   assign(paste(pn, "_r", sep=""),rn) # creates a_r, b_r, c_r...
   ** here is where I want to output to ranvec, but I can't see how to 
do it since the loop doesn't know the name of the new var created in 
preceding step...**

 }


In the end, I want to create a data frame containing rnorm deviates for 
each of a set of user-specified variables, which I can reference in some 
fashion using a permuted version of the original variable name.


Suggestions?

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


Re: [R] extract parts of a list before symbol

2023-05-26 Thread Evan Cooch
 names in the list function

names(test2) <- 1:3 # integer
names(test2) # character
attributes(test2)$names <- 1:3 # integer
attributes(test2) # character
test2[[ "2" ]] == 2  # TRUE
test2$`2`  == 2 # TRUE



On May 25, 2023 6:17:37 PM PDT, avi.e.gr...@gmail.com wrote:

Evan,

List names are less easy than data.frame column names so try this:


test <- list(a=3,b=5,c=11)
colnames(test)

NULL

colnames(as.data.frame(test))

[1] "a" "b" "c"

But note an entry with no name has one made up for it.



test2 <- list(a=3,b=5, 666, c=11)
colnames(data.frame(test2))

[1] "a""b""X666" "c"

But that may be overkill as simply converting to a vector if ALL parts are
of the same type will work too:


names(as.vector(test))

[1] "a" "b" "c"

To get one at a time:


names(as.vector(test))[1]

[1] "a"

You can do it even simple by looking at the attributes of your list:


attributes(test)

$names
[1] "a" "b" "c"


attributes(test)$names

[1] "a" "b" "c"

attributes(test)$names[3]

[1] "c"


-Original Message-
From: R-help  On Behalf Of Evan Cooch
Sent: Thursday, May 25, 2023 1:30 PM
To: r-help@r-project.org
Subject: [R] extract parts of a list before symbol

Suppose I have the following list:

test <- list(a=3,b=5,c=11)

I'm trying to figure out how to extract the characters to the left of
the equal sign (i.e., I want to extract a list of the variable names, a,
b and c.

I've tried the permutations I know of involving sub - things like
sub("\\=.*", "", test), but no matter what I try, sub keeps returning
(3, 5, 11). In other words, even though I'm trying to extract the
'stuff' before the = sign, I seem to be successful only at grabbing the
stuff after the equal sign.

Pointers to the obvious fix? 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

and provide commented, minimal, self-contained, reproducible code.


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


[R] extract parts of a list before symbol

2023-05-25 Thread Evan Cooch

Suppose I have the following list:

test <- list(a=3,b=5,c=11)

I'm trying to figure out how to extract the characters to the left of 
the equal sign (i.e., I want to extract a list of the variable names, a, 
b and c.


I've tried the permutations I know of involving sub - things like 
sub("\\=.*", "", test), but no matter what I try, sub keeps returning 
(3, 5, 11). In other words, even though I'm trying to extract the 
'stuff' before the = sign, I seem to be successful only at grabbing the 
stuff after the equal sign.


Pointers to the obvious fix? 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.


[R] interval between specific characters in a string...

2022-12-02 Thread Evan Cooch
Was wondering if there is an 'efficient/elegant' way to do the following 
(without tidyverse). Take a string


abaaabbabaaab

Its easy enough to count the number of times the character 'b' shows up 
in the string, but...what I'm looking for is outputing the 'intervals' 
between occurrences of 'b' (starting the counter at the beginning of the 
string). So, for the preceding example, 'b' shows up in positions


2, 6, 7, 13, 17

So, the interval data would be: 2, 4, 1, 6, 4

My main approach has been to simply output positions (say, something 
like unlist(gregexpr('b', target_string))), and 'do the math' between 
successive positions. Can anyone suggest a more elegant approach?


Thanks in advance...

__
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] conditional output of string to file n times...

2021-07-07 Thread Evan Cooch
Figured it out on my own. Basically, use the replicate command for each 
line of the data.frame, then appending to a file.


On 7/6/2021 9:27 AM, Evan Cooch wrote:
Suppose I have a file with the the following structure - call the two 
space-separated fields 'label' and 'count':


ABC 3
DDG 5
ABB 2


What I need to do is parse each line of the file, and then depending 
on the value of count, write out the value of 'label' to a new file, 
but 'count' times. In other words, take the preceding, and output


ABC
ABC
ABC
DDG
DDG
DDG
DDG
DDG
ABB
ABB

I was wondering if there was an elegant/simple way to do this? I can 
do this relatively easily in perl, or awk, but am stumped by getting a 
bit of R code to accomplish the same thing.


Many thanks in advance...



__
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] conditional output of string to file n times...

2021-07-07 Thread Evan Cooch
Suppose I have a file with the the following structure - call the two 
space-separated fields 'label' and 'count':


ABC 3
DDG 5
ABB 2


What I need to do is parse each line of the file, and then depending on 
the value of count, write out the value of 'label' to a new file, but 
'count' times. In other words, take the preceding, and output


ABC
ABC
ABC
DDG
DDG
DDG
DDG
DDG
ABB
ABB

I was wondering if there was an elegant/simple way to do this? I can do 
this relatively easily in perl, or awk, but am stumped by getting a bit 
of R code to accomplish the same thing.


Many thanks in advance...

__
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] problem(s) compiling RWinEdt

2019-04-22 Thread Evan Cooch



On 4/22/2019 2:00 PM, William Dunlap wrote:
> Trying adding INSTALL_opts="--no-test-load" to your 
> install.packages(type="source",...) command.   This package is being 
> too clever in its .onAttach function.
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com 
>
>

Thanks -- solved problem #1 (being, couldn't get it to compile from 
source in the first place).

[[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] problem(s) compiling RWinEdt

2019-04-22 Thread Evan Cooch
[Note: if this should go to one of the other R maillists, 
apologies...and let me know *which* other list...]



I use the WinEdt editor for ll my TeX work, and several years back, 
installed the RWinEdt package in R to allow me to use WinEdt as my R 
edtior as well. Worked, and continues to work, perfectly (currently 
using R 3.5.3, RWinEdt 2.0, and WinEdt 6 -- WinEdt 6 being way behind 
the current release 10.x, but newer version have no new features I felt 
compelled to get by upgrading).


However, with the likelihood I'll need to move some of my Windows 7 
machines -> Windows 10, I wondered about getting the WinEdt-RWinEdt 
combination working on a new machine. So, I built a Win 10 machine, 
clean install, and then did a base install of R 3.5.3 (nothing else 
beyond base). Installed latest RTools, and put it in the path (since 
there doesn't seem to be a Windows binary for RWinEdt). Fired up R with 
admin privileges, and then tried to install RWinEdt. Tried, but...failed 
miserably (console log of one attempt, below). Got the following compile 
failures -- replete with NameSpace errors, and a strange comment that 
RWinEdt is designed for the Windows RGui only (strange, since I *am* 
installing/compiling on a Windows machine).


Being curious, I then re-tried the same exercise using a clean Windows 7 
install. Same issue. Then, retried both, using WinEdt 6. Same issue.



So, there seems to be a problem with getting RWinEdt installed. For the 
moment, I'm not too fussed, since I have it working fine on my main work 
machines. However, if I need to setup a new machine in future (Win 7 or 
Win 10), I'd like to be able to do a 'fresh' install of R, WinEdt and 
RWinEdt.


Any suggestions?

Thanks...




--- Please select a CRAN mirror for use in this session ---
Package which is only available in source form, and may need
  compilation of C/C++/Fortran: ‘RWinEdt’
installing the source package ‘RWinEdt’

trying URL 'https://cran.mtu.edu/src/contrib/RWinEdt_2.0-6.tar.gz'
Content type 'application/x-gzip' length 801476 bytes (782 KB)
downloaded 782 KB

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

*** arch - i386
c:/Rtools/mingw_32/bin/gcc  -I"C:/PROGRA~1/R/R-35~1.3/include" 
-DNDEBUG  -O3 -Wall  -std=gnu99 -mtune=generic -c ismdi.c -o ismdi.o
c:/Rtools/mingw_32/bin/gcc -shared -s -static-libgcc -o RWinEdt.dll 
tmp.def ismdi.o -lRgraphapp -LC:/PROGRA~1/R/R-35~1.3/bin/i386 -lR

installing to C:/Program Files/R/R-3.5.3/library/RWinEdt/libs/i386

*** arch - x64
c:/Rtools/mingw_64/bin/gcc  -I"C:/PROGRA~1/R/R-35~1.3/include" 
-DNDEBUG  -O2 -Wall  -std=gnu99 -mtune=generic -c ismdi.c -o ismdi.o
c:/Rtools/mingw_64/bin/gcc -shared -s -static-libgcc -o RWinEdt.dll 
tmp.def ismdi.o -lRgraphapp -LC:/PROGRA~1/R/R-35~1.3/bin/x64 -lR

installing to C:/Program Files/R/R-3.5.3/library/RWinEdt/libs/x64
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
  converting help for package 'RWinEdt'
    finding HTML links ... done
    WinEdt  html
    ismdi   html
** building package indices
** installing vignettes
   'RWinEdt.Rnw'

** testing if installed package can be loaded
*** arch - i386
Error: package or namespace load failed for 'RWinEdt':
 .onAttach failed in attachNamespace() for 'RWinEdt', details:
  call: fun(libname, pkgname)
  error:
R-WinEdt is designed only for *RGui* on Windows!
Error: loading failed
Execution halted
*** arch - x64
Error: package or namespace load failed for 'RWinEdt':
 .onAttach failed in attachNamespace() for 'RWinEdt', details:
  call: fun(libname, pkgname)
  error:
R-WinEdt is designed only for *RGui* on Windows!
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing 'C:/Program Files/R/R-3.5.3/library/RWinEdt'
In R CMD INSTALL

The downloaded source packages are in
‘C:\Users\egc\AppData\Local\Temp\RtmpiYRr5e\downloaded_packages’
Warning message:
In install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) :
  installation of package ‘RWinEdt’ had non-zero exit status

__
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] A general question about using Bayes' Theorem for calculating the probability of The End of Human Technological Civilisation

2019-03-19 Thread Evan Cooch
Just curious -- if R-help is a moderated list (which  in theory , it is 
-- my posts have been 'modertated', to the degree that they aren't 
released to the list until someone approves them), and if these 
'statistics discussion' questions are inappropriate to the mission (as 
described), then...why isn't the 'moderator' (him/her/they) blocking on 
submission?


On 3/19/2019 1:59 PM, David Winsemius wrote:
Rhelp is not a forum for discussions of statistics. Instead it is for 
persons who have specific questions about the use of R.


Please read the list info page where you started the subscription 
process. And do read the Posting Guide. Both these are linked at the 
bottom of this response.


There are Web accessible forums that are set up to statistics.



__
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] looking for 'tied rows' in dataframe

2019-03-19 Thread Evan Cooch
Good suggestion, and for my purposes, will solve the problem. Thanks!

On 3/18/2019 12:37 PM, Ben Tupper wrote:
> Hi,
>
> Might you replaced 'T' with a numeric value that signals the TRUE case 
> without rumpling your matrix?  0 might be a good choice as it is never an 
> index for a 1-based indexing system.
>
> hold=apply(test,1,which.max)
> hold[apply(test,1,isUnique)==FALSE] <- 0
> hold
> [1] 1 2 0
>   
>
>
>> On Mar 17, 2019, at 8:17 PM, Evan Cooch  wrote:
>>
>> Solved --
>>
>> hold=apply(test,1,which.max)
>>  hold[apply(test,1,isUnique)==FALSE] <- 'T'
>>
>> Now, all I need to do is figure out how to get <- 'T' from turning 
>> everything in the matrix to a string.
>>
>>
>> On 3/17/2019 8:00 PM, Evan Cooch wrote:
>>> Got relatively close - below:
>>>
>>> On 3/17/2019 7:39 PM, Evan Cooch wrote:
>>>> Suppose I have the following sort of structure:
>>>>
>>>> test <- matrix(c(2,1,1,2,2,2),3,2,byrow=T)
>>>>
>>>> What I need to be able to do is (i) find the maximum value for each row, 
>>>> (ii) find the column containing the max, but (iii) if the maximum value is 
>>>> a tie (in this case, all numbers of the row are the same value), then I 
>>>> want which.max (presumably, a tweaked version of what which.max does) to 
>>>> reurn a T for the row where all values are the same.
>>>>
>>>> Parts (i) and (ii) seem easy enough:
>>>>
>>>> apply(test,1,max)  --- gives me the maximum values
>>>> apply(test,1,which.max) --- gives me the column
>>>>
>>>> But, standard which.max doesn't handles ties/duplicates in a way that 
>>>> serves my need. It defaults to returning the first column containing the 
>>>> maximum value.
>>>>
>>>> What I'd like to end up with is, ultimately, something where 
>>>> apply(test,1,which.max) yields 1,2,T  (rather than 1,2,1).
>>>>
>>>> So, a function which does what which.max currently does if the elements of 
>>>> the row differ, but which returns a T (or some such) if in fact the row 
>>>> values are all the same.
>>>>
>>>> I've tried a bunch of things, to know avail. Closest I got was to use a 
>>>> function to test for whether or not a vector
>>>>
>>>> isUnique <- function(vector){
>>>>   return(!any(duplicated(vector)))
>>>>  }
>>>>
>>>> which returns TRUE if values of vector all unique. So
>>>>
>>>> apply(test,1,isUnique)
>>>>
>>>> returns
>>>>
>>>> [1]  TRUE  TRUE FALSE
>>>>
>>>> but I'm stuck beyond this.
>>> The following gets me pretty close,
>>>
>>> test_new <- test
>>> test_new[which(apply(test,1,isUnique)==FALSE),] <- 'T'
>>>
>>> but is clunky.
>>>
>>>
>>>
>>>
>>>
>>>
>> __
>> 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.
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
>
> Ecological Forecasting: https://eco.bigelow.org/
>
>
>
>
>
>


[[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] looking for 'tied rows' in dataframe

2019-03-18 Thread Evan Cooch

Solved --

hold=apply(test,1,which.max)
    hold[apply(test,1,isUnique)==FALSE] <- 'T'

Now, all I need to do is figure out how to get <- 'T' from turning 
everything in the matrix to a string.



On 3/17/2019 8:00 PM, Evan Cooch wrote:

Got relatively close - below:

On 3/17/2019 7:39 PM, Evan Cooch wrote:

Suppose I have the following sort of structure:

test <- matrix(c(2,1,1,2,2,2),3,2,byrow=T)

What I need to be able to do is (i) find the maximum value for each 
row, (ii) find the column containing the max, but (iii) if the 
maximum value is a tie (in this case, all numbers of the row are the 
same value), then I want which.max (presumably, a tweaked version of 
what which.max does) to reurn a T for the row where all values are 
the same.


Parts (i) and (ii) seem easy enough:

apply(test,1,max)  --- gives me the maximum values
apply(test,1,which.max) --- gives me the column

But, standard which.max doesn't handles ties/duplicates in a way that 
serves my need. It defaults to returning the first column containing 
the maximum value.


What I'd like to end up with is, ultimately, something where 
apply(test,1,which.max) yields 1,2,T  (rather than 1,2,1).


So, a function which does what which.max currently does if the 
elements of the row differ, but which returns a T (or some such) if 
in fact the row values are all the same.


I've tried a bunch of things, to know avail. Closest I got was to use 
a function to test for whether or not a vector


isUnique <- function(vector){
 return(!any(duplicated(vector)))
    }

which returns TRUE if values of vector all unique. So

apply(test,1,isUnique)

returns

[1]  TRUE  TRUE FALSE

but I'm stuck beyond this. 


The following gets me pretty close,

test_new <- test
test_new[which(apply(test,1,isUnique)==FALSE),] <- 'T'

but is clunky.








__
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] looking for 'tied rows' in dataframe

2019-03-18 Thread Evan Cooch

Got relatively close - below:

On 3/17/2019 7:39 PM, Evan Cooch wrote:

Suppose I have the following sort of structure:

test <- matrix(c(2,1,1,2,2,2),3,2,byrow=T)

What I need to be able to do is (i) find the maximum value for each 
row, (ii) find the column containing the max, but (iii) if the maximum 
value is a tie (in this case, all numbers of the row are the same 
value), then I want which.max (presumably, a tweaked version of what 
which.max does) to reurn a T for the row where all values are the same.


Parts (i) and (ii) seem easy enough:

apply(test,1,max)  --- gives me the maximum values
apply(test,1,which.max) --- gives me the column

But, standard which.max doesn't handles ties/duplicates in a way that 
serves my need. It defaults to returning the first column containing 
the maximum value.


What I'd like to end up with is, ultimately, something where 
apply(test,1,which.max) yields 1,2,T  (rather than 1,2,1).


So, a function which does what which.max currently does if the 
elements of the row differ, but which returns a T (or some such) if in 
fact the row values are all the same.


I've tried a bunch of things, to know avail. Closest I got was to use 
a function to test for whether or not a vector


isUnique <- function(vector){
 return(!any(duplicated(vector)))
    }

which returns TRUE if values of vector all unique. So

apply(test,1,isUnique)

returns

[1]  TRUE  TRUE FALSE

but I'm stuck beyond this. 


The following gets me pretty close,

test_new <- test
test_new[which(apply(test,1,isUnique)==FALSE),] <- 'T'

but is clunky.

__
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] looking for 'tied rows' in dataframe

2019-03-18 Thread Evan Cooch

Suppose I have the following sort of structure:

test <- matrix(c(2,1,1,2,2,2),3,2,byrow=T)

What I need to be able to do is (i) find the maximum value for each row, 
(ii) find the column containing the max, but (iii) if the maximum value 
is a tie (in this case, all numbers of the row are the same value), then 
I want which.max (presumably, a tweaked version of what which.max does) 
to reurn a T for the row where all values are the same.


Parts (i) and (ii) seem easy enough:

apply(test,1,max)  --- gives me the maximum values
apply(test,1,which.max) --- gives me the column

But, standard which.max doesn't handles ties/duplicates in a way that 
serves my need. It defaults to returning the first column containing the 
maximum value.


What I'd like to end up with is, ultimately, something where 
apply(test,1,which.max) yields 1,2,T  (rather than 1,2,1).


So, a function which does what which.max currently does if the elements 
of the row differ, but which returns a T (or some such) if in fact the 
row values are all the same.


I've tried a bunch of things, to know avail. Closest I got was to use a 
function to test for whether or not a vector


isUnique <- function(vector){
 return(!any(duplicated(vector)))
    }

which returns TRUE if values of vector all unique. So

apply(test,1,isUnique)

returns

[1]  TRUE  TRUE FALSE

but I'm stuck beyond this.  Suggestions/pointers to the obvious welcome.

Thanks in advance.

__
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] options other than regex

2018-05-25 Thread Evan Cooch
Numbers -- thanks. Another clever trick.

On 5/25/2018 11:54 AM, Greg Minshall wrote:
> Evan,
>
> are you really looking at numbers, or just at character strings (that,
> in your case, happen to be numbers)?  if just characters, this rather
> odd combination of strsplit() and Reduce() might do the trick:
> 
>> x <- '10110111'
>> print(x)
> [1] "10110111"
>> y <- Reduce(function (x,y) { paste(x, y, sep=".") }, unlist(strsplit(x, 
>> "")), init="", right=TRUE)
>> print(y)
> [1] "1.0.1.1.0.1.1.1."
> 
>
> 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.


Re: [R] options other than regex

2018-05-25 Thread Evan Cooch
Thanks, another good idea.

On 5/25/2018 11:30 AM, PIKAL Petr wrote:
> Hi
> I am not sure if it is more readable
>
>> paste(paste(unlist(strsplit(x,"")),".", sep=""), collapse="")
> [1] "1.0.1.1.0.1.1.1."
>
> If you did not want last dot, it is a bit shorter.
>> paste(unlist(strsplit(x,"")),collapse=".")
> [1] "1.0.1.1.0.1.1.1"
> Cheers
> Petr
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají 
> tomuto právně závaznému prohlášení o vyloučení odpovědnosti: 
> https://www.precheza.cz/01-dovetek/ | This email and any documents attached 
> to it may be confidential and are subject to the legally binding disclaimer: 
> https://www.precheza.cz/en/01-disclaimer/
>
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Evan Cooch
>> Sent: Friday, May 25, 2018 3:43 PM
>> To: R-help <r-help@r-project.org>
>> Subject: [R] options other than regex
>>
>> Hi --
>>
>> I'm looking for alternatives to regex for a fairly simply 'reformatting'
>> problem. Alternatives only because a lot of folks have trouble
>> parsing/interpreting regex expressions, and I'm looking for suggestions for
>> something more 'transparent'.
>>
>> Here is an example of what I'm trying to do. Take the following string, 
>> which I
>> call x, and for each character in the string, replace that character with the
>> character, followed by a decimal. The following big of regex works...and
>> illustrates the reformatting I'm after:
>>
>> x <- '10110111'
>> print(x)
>>
>> y <- sub("\\s+$", "", gsub('(.{1})', '\\1.', x))
>> print(y)
>>
>> I had a look at formatC or prettyNum as another way to get there from here,
>> but couldn't get it to work:
>>
>> x <- '10110111'
>> hold <- prettyNum(as.numeric(x), big.mark = ".", big.interval = 1,
>>   format = "d", flag = "0", width = nchar(x))
>> print(hold)
>>
>>
>> I tried making big.mark a decimal, but that fails, since it confuses 
>> 'prettyNum'.
>> OK, so I try a 2-step approach
>>
>> x <- '10110111'
>> hold <- prettyNum(as.numeric(x), big.mark = "x", big.interval = 1,
>>   format = "d", flag = "00", width = nchar(x))
>> hold2 <- (gsub("x",".",hold))
>> print(hold2)
>>
>> Seems to work, but...doesn't work (at least, based on what I tried) if the 
>> first
>> character(s) in the string are 0's. [Whereas the regex approach handles this 
>> just
>> fine...]
>>
>>
>> x <- '0010110111'
>> hold <- prettyNum(as.numeric(x), big.mark = "x", big.interval = 1,
>>   format = "d", flag = "00", width = nchar(x))
>> hold2 <- (gsub("x",".",hold))
>> print(hold2)
>>
>>
>> Basically, it strips off the leading 0's. I'm sure I'm missing something with
>> prettyNum/formatC, but I'm also guessing there are alternatives.
>> Suggestions?
>>
>> Thanks in advance.
>>
>> __
>> 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.
> 
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou 
> určeny pouze jeho adresátům.
> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
> jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
> svého systému.
> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
> jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
> zpožděním přenosu e-mailu.
>
> V případě, že je tento e-mail součástí obchodního jednání:
> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, 
> a to z jakéhokoliv důvodu i bez uvedení důvodu.
> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
> Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany 
> příjemce s dodatkem či odchylkou.
> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
> dosažením shody na všech jejích náležitostech.
> - odesílatel tohoto emailu inform

[R] options other than regex

2018-05-25 Thread Evan Cooch

Hi --

I'm looking for alternatives to regex for a fairly simply 'reformatting' 
problem. Alternatives only because a lot of folks have trouble 
parsing/interpreting regex expressions, and I'm looking for suggestions 
for something more 'transparent'.


Here is an example of what I'm trying to do. Take the following string, 
which I call x, and for each character in the string, replace that 
character with the character, followed by a decimal. The following big 
of regex works...and illustrates the reformatting I'm after:


x <- '10110111'
print(x)

y <- sub("\\s+$", "", gsub('(.{1})', '\\1.', x))
print(y)

I had a look at formatC or prettyNum as another way to get there from 
here, but couldn't get it to work:


x <- '10110111'
hold <- prettyNum(as.numeric(x), big.mark = ".", big.interval = 1,
    format = "d", flag = "0", width = nchar(x))
print(hold)


I tried making big.mark a decimal, but that fails, since it confuses 
'prettyNum'. OK, so I try a 2-step approach


x <- '10110111'
hold <- prettyNum(as.numeric(x), big.mark = "x", big.interval = 1,
    format = "d", flag = "00", width = nchar(x))
hold2 <- (gsub("x",".",hold))
print(hold2)

Seems to work, but...doesn't work (at least, based on what I tried) if 
the first character(s) in the string are 0's. [Whereas the regex 
approach handles this just fine...]



x <- '0010110111'
hold <- prettyNum(as.numeric(x), big.mark = "x", big.interval = 1,
    format = "d", flag = "00", width = nchar(x))
hold2 <- (gsub("x",".",hold))
print(hold2)


Basically, it strips off the leading 0's. I'm sure I'm missing something 
with prettyNum/formatC, but I'm also guessing there are alternatives. 
Suggestions?


Thanks in advance.

__
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] building random matrices from vectors of random parameters

2017-09-28 Thread Evan Cooch
Makes sense, although (re-)learning what aperm does wasn't a wasted 
exercise.

Thanks!

On 9/28/2017 1:22 PM, Jeff Newmiller wrote:
> The use of aperm is unnecessary if you call array() properly.
>
> ms <- array(c(rep(0, 5),so,sa*m,sa), c(5, 2, 2))


[[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] building random matrices from vectors of random parameters

2017-09-28 Thread Evan Cooch
Sure -- thanks -- only took me 3-4 attempts to get aperm to work (as 
opposed to really thinking hard about how it works ;-)

On 9/28/2017 11:55 AM, Duncan Murdoch wrote:
> On 28/09/2017 9:10 AM, Evan Cooch wrote:
>> Thanks for both the mapply and array approaches! However, although 
>> intended to generate the same result, they don't:
>>
>> # mapply approach
>>
>> n = 3
>> sa <- rnorm(n,0.8,0.1)
>> so <- rnorm(n,0.5,0.1)
>> m <- rnorm(n,1.2,0.1)
>> mats = mapply(function(sa1, so1, m1) 
>> matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T), sa, so, m, SIMPLIFY = FALSE)
>>
>> print(mats)
>>
>> [[1]]
>>    [,1]  [,2]
>> [1,] 0.000 0.8643679
>> [2,] 0.4731249 0.7750431
>>
>> [[2]]
>>    [,1]  [,2]
>> [1,] 0.000 0.8838286
>> [2,] 0.5895258 0.7880983
>>
>> [[3]]
>>    [,1]  [,2]
>> [1,] 0.000 1.1491560
>> [2,] 0.4947322 0.9744166
>>
>>
>> Now, the array approach:
>>
>> # array approach
>>
>> ms <- array(c(rep(0, 3),sa*m,so,sa), c(3, 2, 2))
>>
>> for (i in 1:n) { print(ms[i,,])
>>
>>    [,1]  [,2]
>> [1,] 0.000 0.4731249
>> [2,] 0.8643679 0.7750431
>>
>>    [,1]  [,2]
>> [1,] 0.000 0.5895258
>> [2,] 0.8838286 0.7880983
>>
>>   [,1]  [,2]
>> [1,] 0.00 0.4947322
>> [2,] 1.149156 0.9744166
>>
>>
>> These matrices are the transpose of those returned by the mapply 
>> approach. To see if one approach or the other is 'confused', I simply 
>> rerun setting sd=0 for the parameters -- thus, every matrix will be 
>> the same. The correct matrix would be:
>>
>>   [,1] [,2]
>> [1,]  0.0 0.96
>> [2,]  0.5 0.80
>>
>>
>> In fact, this is what is returned by the mapply approach, while the 
>> array approach returns the transpose. I gather the 'missing step' is 
>> to use aperm, but haven't figured out how to get that to work...yet.
>>
>>
>> On 9/28/2017 5:11 AM, Duncan Murdoch wrote:
>>> ms <- array(c(rep(0, 5),sa*m,so,sa), c(5, 2, 2)) 
>>
>
>
> Sorry about that -- I didn't notice the "byrow = T" in your original.
>
> Duncan Murdoch
>


[[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] building random matrices from vectors of random parameters

2017-09-28 Thread Evan Cooch

>
> In fact, this is what is returned by the mapply approach, while the 
> array approach returns the transpose. I gather the 'missing step' is 
> to use aperm, but haven't figured out how to get that to work...yet.

ms <- array(c(rep(0, 3),sa*m,so,sa), c(3, 2, 2))

ms_new <- aperm(ms,c(1,3,2));

for (i in 1:n) { print(ms_new[i,,]) }

  [,1] [,2]
[1,]  0.0 0.96
[2,]  0.5 0.80

  [,1] [,2]
[1,]  0.0 0.96
[2,]  0.5 0.80

  [,1] [,2]
[1,]  0.0 0.96
[2,]  0.5 0.80


>
>
> On 9/28/2017 5:11 AM, Duncan Murdoch wrote:
>> ms <- array(c(rep(0, 5),sa*m,so,sa), c(5, 2, 2)) 
>

[[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] building random matrices from vectors of random parameters

2017-09-28 Thread Evan Cooch
Thanks for both the mapply and array approaches! However, although 
intended to generate the same result, they don't:

# mapply approach

n = 3
sa <- rnorm(n,0.8,0.1)
so <- rnorm(n,0.5,0.1)
m <- rnorm(n,1.2,0.1)
mats = mapply(function(sa1, so1, m1) 
matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T), sa, so, m, SIMPLIFY = FALSE)

print(mats)

[[1]]
   [,1]  [,2]
[1,] 0.000 0.8643679
[2,] 0.4731249 0.7750431

[[2]]
   [,1]  [,2]
[1,] 0.000 0.8838286
[2,] 0.5895258 0.7880983

[[3]]
   [,1]  [,2]
[1,] 0.000 1.1491560
[2,] 0.4947322 0.9744166


Now, the array approach:

# array approach

ms <- array(c(rep(0, 3),sa*m,so,sa), c(3, 2, 2))

for (i in 1:n) { print(ms[i,,])

   [,1]  [,2]
[1,] 0.000 0.4731249
[2,] 0.8643679 0.7750431

   [,1]  [,2]
[1,] 0.000 0.5895258
[2,] 0.8838286 0.7880983

  [,1]  [,2]
[1,] 0.00 0.4947322
[2,] 1.149156 0.9744166


These matrices are the transpose of those returned by the mapply 
approach. To see if one approach or the other is 'confused', I simply 
rerun setting sd=0 for the parameters -- thus, every matrix will be the 
same. The correct matrix would be:

  [,1] [,2]
[1,]  0.0 0.96
[2,]  0.5 0.80


In fact, this is what is returned by the mapply approach, while the 
array approach returns the transpose. I gather the 'missing step' is to 
use aperm, but haven't figured out how to get that to work...yet.


On 9/28/2017 5:11 AM, Duncan Murdoch wrote:
> ms <- array(c(rep(0, 5),sa*m,so,sa), c(5, 2, 2)) 


[[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] building random matrices from vectors of random parameters

2017-09-27 Thread Evan Cooch
Suppose I have interest in a matrix with the following symbolic 
structure (specified by 3 parameters: sa, so, m):


matrix(c(0,sa*m,so,sa),2,2,byrow=T)

What I can't figure out is how to construct a series of matrices, where 
the elements/parameters are rnorm values. I'd like to construct separate 
matrices, with each matrix in the series using the 'next random 
parameter value'. While the following works (for generating, say, 5 such 
random matrices)


replicate(5,matrix(c(0,rnorm(1,0.8,0.1)*rnorm(1,1.2,0.1),rnorm(1,0.5,0.1),rnorm(1,0.8,0.1)),2,2,byrow=T))

its inelegant, and a real pain if the matrix gets large (say, 20 x 20).

I'm wondering if there is an easier way. I tried

> sa <- rnorm(5,0.8,0.1)
> so <- rnorm(5,0.5,0.1)
> m <- rnorm(5,1.2,0.1)

matrix(c(0,sa*m,so,sa),2,2,byrow=T)

but that only returns a single matrix, not 5 matrices as I'd like. I 
also tried several variants of the 'replicate' approach (above), but 
didn't stumble across anything that seemed to work.


So, is there a better way than something like:

replicate(5,matrix(c(0,rnorm(1,0.8,0.1)*rnorm(1,1.2,0.1),rnorm(1,0.5,0.1),rnorm(1,0.8,0.1)),2,2,byrow=T))

Many thanks in advance...

__
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] update numeric values of list with new values...

2017-09-22 Thread Evan Cooch
Thanks!

On 9/22/2017 12:34 PM, Bert Gunter wrote:
> Well,  that's a bit like driving from Boston to New York by way of 
> Chicago.
>
> See ?structure
>
> test <- list(a=1,b=2,c=3)
> new <- c(4,5,6)
> test.new <- structure(as.list(new), names=names(test))
> test.new
> $a
> [1] 4
>
> $b
> [1] 5
>
> $c
> [1] 6
>
> Cheers,
> Bert
>
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along 
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Fri, Sep 22, 2017 at 7:51 AM, Evan Cooch <evan.co...@gmail.com 
> <mailto:evan.co...@gmail.com>> wrote:
>
> Solved it:
>
> test <- list(a=1,b=2,c=3)
> new <- c(4,5,6)
>
> hold <- as.list(new)
> updated_test <- replace(test,c(1:3),hold)
>
> $a
> [1] 4
>
> $b
> [1] 5
>
> $c
> [1] 6
>
>
>
> mean.parms <- as.list(mean.parms)
>
> mm.parms <- replace(far.parms,c(1:length(far.parms)),mean.parms)
>
>
> On 9/22/2017 10:34 AM, Evan Cooch wrote:
>
> Suppose I have the following:
>
> test <- list(a=1,b=2,c=3)
>
> I also have a vector (or list, or something else...) with new
> numbers
>
> new <- c(4,5,6)
>
> What I'm trying to figure out is how to take the list, and
> update the numbers from {1,2,3} to {4,5,6}
>
> So, in the end,I want the 'update' test list to look like
>
> (a=4,a=5,a=6)
>
> I tried a bunch of obvious things I know about 'replacing'
> things (without success), but the problem in this instance
> seems to be the fact that the list contains elements that are
> expressions (a=1, a=2,...), while the new vector is simply a
> set of numbers.
>
> So, I want to change the numbers in the list, but retain the
> character parts of the expressions in the list (I need to have
> the list of expressions as is for other purposes).
>
> Doable?
>
> Thanks in advance...
>
>
>
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list --
> To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> <https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
>


[[alternative HTML version deleted]]

__
R-help@r-project.org 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] update numeric values of list with new values...

2017-09-22 Thread Evan Cooch

Solved it:

test <- list(a=1,b=2,c=3)
new <- c(4,5,6)

hold <- as.list(new)
updated_test <- replace(test,c(1:3),hold)

$a
[1] 4

$b
[1] 5

$c
[1] 6



mean.parms <- as.list(mean.parms)

mm.parms <- replace(far.parms,c(1:length(far.parms)),mean.parms)

On 9/22/2017 10:34 AM, Evan Cooch wrote:

Suppose I have the following:

test <- list(a=1,b=2,c=3)

I also have a vector (or list, or something else...) with new numbers

new <- c(4,5,6)

What I'm trying to figure out is how to take the list, and update the 
numbers from {1,2,3} to {4,5,6}


So, in the end,I want the 'update' test list to look like

(a=4,a=5,a=6)

I tried a bunch of obvious things I know about 'replacing' things 
(without success), but the problem in this instance seems to be the 
fact that the list contains elements that are expressions (a=1, 
a=2,...), while the new vector is simply a set of numbers.


So, I want to change the numbers in the list, but retain the character 
parts of the expressions in the list (I need to have the list of 
expressions as is for other purposes).


Doable?

Thanks in advance...




__
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] update numeric values of list with new values...

2017-09-22 Thread Evan Cooch

Suppose I have the following:

test <- list(a=1,b=2,c=3)

I also have a vector (or list, or something else...) with new numbers

new <- c(4,5,6)

What I'm trying to figure out is how to take the list, and update the 
numbers from {1,2,3} to {4,5,6}


So, in the end,I want the 'update' test list to look like

(a=4,a=5,a=6)

I tried a bunch of obvious things I know about 'replacing' things 
(without success), but the problem in this instance seems to be the fact 
that the list contains elements that are expressions (a=1, a=2,...), 
while the new vector is simply a set of numbers.


So, I want to change the numbers in the list, but retain the character 
parts of the expressions in the list (I need to have the list of 
expressions as is for other purposes).


Doable?

Thanks in advance...

__
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] selecting dataframe columns based on substring of col name(s)

2017-06-22 Thread Evan Cooch
Thanks to all the good suggestions/solutions to the original problem.

On 6/21/2017 3:28 PM, David Winsemius wrote:
>> On Jun 21, 2017, at 9:11 AM, Evan Cooch <evan.co...@gmail.com> wrote:
>>
>> Suppose I have the following sort of dataframe, where each column name has a 
>> common structure: prefix, followed by a number (for this example, col1, 
>> col2, col3 and col4):
>>
>> d = data.frame( col1=runif(10), col2=runif(10), 
>> col3=runif(10),col4=runif(10))
>>
>> What I haven't been able to suss out is how to efficiently 
>> 'extract/manipulate/play with' columns from the data frame, making use of 
>> this common structure.
>>
>> Suppose, for example, I want to 'work with' col2, col3, and col4. Now, I 
>> could subset the dataframe d in any number of ways -- for example
>>
>> piece <- d[,c("col2","col3","col4")]
>>
>> Works as expected, but for *big* problems (where I might have dozens -> 
>> hundreds of columns -- often the case with big design matrices output by 
>> some linear models program or another), having to write them all out using 
>> c("col2","col3","colX") takes a lot of time. What I'm wondering 
>> about is if there is a way to simply select over the "changing part" of the 
>> column name (you can do this relatively easily in a data step in SAS, for 
>> example). Heuristically, something like:
>>
>> piece <- df[,col2:col4]
>>
>> where the heuristic col2:col4 is interpreted as col2 -> col4 (parse the 
>> prefix 'col', and then simply select over the changing suffic -- i.e., 
>> column number).
>>
>> Now, if I use the "to" function in the lessR package, I can get there from 
>> here fairly easily:
>>
>> piece <- d[,to("col",4,from=2,same.size=FALSE)]
>>
>> But, is there a better way? Beyond 'efficiency' (ease of implementation), 
>> part of what constitutes 'better' might be something in base R, rather than 
>> relying on a package?
> After staring at the code for the base function subset with a thought to 
> hacking it to do this I realized that should be already part of the 
> evaluation result from its current form:
>
>   names(airquality)
> #[1] "Ozone"   "Solar.R" "Wind""Temp""Month"   "Day"
>
> subset(airquality,
>Temp > 90, # this is the row selection
>select = Ozone:Solar.R) # and this selects columns
> #
>  Ozone Solar.R
> 42 NA 259
> 43 NA 250
> 69 97 267
> 70 97 272
> 75 NA 291
> 102NA 222
> 12076 203
> 121   118 225
> 12284 237
> 12385 188
> 12496 167
> 12578 197
> 12673 183
> 12791 189
>
> Bert's advice to work with the numbers is good, but conversion to numeric 
> designations of columns inside the `select`-expression is actually what is 
> occurring inside `subset`.
>


[[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] selecting dataframe columns based on substring of col name(s)

2017-06-21 Thread Evan Cooch
Suppose I have the following sort of dataframe, where each column name 
has a common structure: prefix, followed by a number (for this example, 
col1, col2, col3 and col4):


 d = data.frame( col1=runif(10), col2=runif(10), 
col3=runif(10),col4=runif(10))


What I haven't been able to suss out is how to efficiently 
'extract/manipulate/play with' columns from the data frame, making use 
of this common structure.


Suppose, for example, I want to 'work with' col2, col3, and col4. Now, I 
could subset the dataframe d in any number of ways -- for example


piece <- d[,c("col2","col3","col4")]

Works as expected, but for *big* problems (where I might have dozens -> 
hundreds of columns -- often the case with big design matrices output by 
some linear models program or another), having to write them all out 
using c("col2","col3","colX") takes a lot of time. What I'm 
wondering about is if there is a way to simply select over the "changing 
part" of the column name (you can do this relatively easily in a data 
step in SAS, for example). Heuristically, something like:


piece <- df[,col2:col4]

where the heuristic col2:col4 is interpreted as col2 -> col4 (parse the 
prefix 'col', and then simply select over the changing suffic -- i.e., 
column number).


Now, if I use the "to" function in the lessR package, I can get there 
from here fairly easily:


piece <- d[,to("col",4,from=2,same.size=FALSE)]

But, is there a better way? Beyond 'efficiency' (ease of 
implementation), part of what constitutes 'better' might be something in 
base R, rather than relying on a package?


Thanks in advance...

__
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] pull stat out of summary

2017-03-31 Thread Evan Cooch
Continuing my learning curve after 25_ years with using SAS. Want to 
pull the "Mean" forom the summary of something...


test <- rnorm(1000,1.5,1.25)

hold <- summary(test)

names(hold)
[1] "Min.""1st Qu." "Median"  "Mean""3rd Qu." "Max."

OK, so "Mean" is in there.
So, is there a short form answer for why hold$Mean throws an error, and 
hold["Mean"} returns the mean (as desired)?


Silly question I know,  but gotta start somewhere...

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.


Re: [R] lagging over consecutive pairs of rows in dataframe

2017-03-18 Thread Evan Cooch
Thanks very much. I suspect 50% of my time in R is spent translating 
from what I know how to do in SAS (25+ years of heavy use), to what is 
equivalent in SAS. So far, I haven't found anything I can do in SAS that 
I can't do in R, with some help. ;-)


Cheers...

On 3/17/2017 1:51 PM, Bert Gunter wrote:

Evan:

Yes, I stand partially corrected. You have the concept correct, but R
implements it differently than SAS.

I think what you want for your approach is diff():

evens <-  (seq_len(nrow(mydata)) %% 2) == 0
newdat <-data.frame(exp=mydata[evens,1 ],reslt= diff(mydata[,2])[evens[-1]])

... which seems neater to me than what I offered previously.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Mar 17, 2017 at 10:25 AM, Evan Cooch <evan.co...@gmail.com> wrote:


On 3/17/2017 1:19 PM, Bert Gunter wrote:

Evan:

You misunderstand the concept of a lagged variable.


Well, lag in R, perhaps (and by my own admission). In SAS, thats exactly how
it works.:

data test;
input exp rslt;
cards;

 *;


 data test2; set test; by exp;
 diff=rslt-lag(rslt);
   if last.exp;


Ulrik:

Well, yes, that is certainly a general solution that works. However,
given the *specific* structure described by the OP, an even more
direct (maybe more efficient?) way to do it just uses (logical)
subscripting:

odds <-  (seq_len(nrow(mydata)) %% 2) == 1
newdat <-data.frame(mydata[odds,1 ],mydata[!odds,2] - mydata[odds,2])
names(newdat) <- names(mydata)


Interesting - thanks!



Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Mar 17, 2017 at 9:58 AM, Ulrik Stervbo <ulrik.ster...@gmail.com>
wrote:

Hi Evan

you can easily do this by applying diff() to each exp group.

Either using dplyr:
library(dplyr)
mydata %>%
group_by(exp) %>%
summarise(difference = diff(rslt))

Or with base R
aggregate(mydata, by = list(group = mydata$exp), FUN = diff)

HTH
Ulrik


On Fri, 17 Mar 2017 at 17:34 Evan Cooch <evan.co...@gmail.com> wrote:


Suppose I have a dataframe that looks like the following:

n=2
mydata <- data.frame(exp = rep(1:5,each=n), rslt =
c(12,15,7,8,24,28,33,15,22,11))
mydata
  exp rslt
11   12
21   15
327
428
53   24
63   28
74   33
84   15
95   22
10   5   11

The variable 'exp' (for experiment') occurs in pairs over consecutive
rows -- 1,1, then 2,2, then 3,3, and so on. The first row in a pair is
the 'control', and the second is a 'treatment'. The rslt column is the
result.

What I'm trying to do is create a subset of this dataframe that consists
of the exp number, and the lagged difference between the 'control' and
'treatment' result.  So, for exp=1, the difference is (15-12)=3. For
exp=2,  the difference is (8-7)=1, and so on. What I'm hoping to do is
take mydata (above), and turn it into

exp  diff
1   1  3
2   2  1
3   3  4
4   4  -18
5   5  -11

The basic 'trick' I can't figure out is how to create a lagged variable
between the second row (record) for a given level of exp, and the first
row for that exp.  This is easy to do in SAS (which I'm more familiar
with), but I'm struggling with the equivalent in R. The brute force
approach  I thought of is to simply split the dataframe into to (one
even rows, one odd rows), merge by exp, and then calculate a difference.
But this seems to require renaming the rslt column in the two new
dataframes so they are different in the merge (say, rslt_cont n the odd
dataframe, and rslt_trt in the even dataframe), allowing me to calculate
a difference between the two.

While I suppose this would work, I'm wondering if I'm missing a more
elegant 'in place' approach that doesn't require me to split the data
frame and do every via a merge.

Suggestions/pointers to the obvious welcome. I've tried playing with
lag, and some approaches using lag in the zoo package,  but haven't
found the magic trick. The problem (meaning, what I can't figure out)
seems to be conditioning the lag on the level of exp.

Many thanks...


mydata <-*data.frame*(x = c(20,35,45,55,70), n = rep(50,5), y =
c(6,17,26,37,44))



  [[alternative HTML version deleted]]

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


  [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mail

Re: [R] lagging over consecutive pairs of rows in dataframe

2017-03-18 Thread Evan Cooch



On 3/17/2017 1:19 PM, Bert Gunter wrote:

Evan:

You misunderstand the concept of a lagged variable.


Well, lag in R, perhaps (and by my own admission). In SAS, thats exactly 
how it works.:


data test;
input exp rslt;
cards;

*;


data test2; set test; by exp;
diff=rslt-lag(rslt);
  if last.exp;



Ulrik:

Well, yes, that is certainly a general solution that works. However,
given the *specific* structure described by the OP, an even more
direct (maybe more efficient?) way to do it just uses (logical)
subscripting:

odds <-  (seq_len(nrow(mydata)) %% 2) == 1
newdat <-data.frame(mydata[odds,1 ],mydata[!odds,2] - mydata[odds,2])
names(newdat) <- names(mydata)



Interesting - thanks!



Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Mar 17, 2017 at 9:58 AM, Ulrik Stervbo <ulrik.ster...@gmail.com> wrote:

Hi Evan

you can easily do this by applying diff() to each exp group.

Either using dplyr:
library(dplyr)
mydata %>%
   group_by(exp) %>%
   summarise(difference = diff(rslt))

Or with base R
aggregate(mydata, by = list(group = mydata$exp), FUN = diff)

HTH
Ulrik


On Fri, 17 Mar 2017 at 17:34 Evan Cooch <evan.co...@gmail.com> wrote:


Suppose I have a dataframe that looks like the following:

n=2
mydata <- data.frame(exp = rep(1:5,each=n), rslt =
c(12,15,7,8,24,28,33,15,22,11))
mydata
 exp rslt
11   12
21   15
327
428
53   24
63   28
74   33
84   15
95   22
10   5   11

The variable 'exp' (for experiment') occurs in pairs over consecutive
rows -- 1,1, then 2,2, then 3,3, and so on. The first row in a pair is
the 'control', and the second is a 'treatment'. The rslt column is the
result.

What I'm trying to do is create a subset of this dataframe that consists
of the exp number, and the lagged difference between the 'control' and
'treatment' result.  So, for exp=1, the difference is (15-12)=3. For
exp=2,  the difference is (8-7)=1, and so on. What I'm hoping to do is
take mydata (above), and turn it into

   exp  diff
1   1  3
2   2  1
3   3  4
4   4  -18
5   5  -11

The basic 'trick' I can't figure out is how to create a lagged variable
between the second row (record) for a given level of exp, and the first
row for that exp.  This is easy to do in SAS (which I'm more familiar
with), but I'm struggling with the equivalent in R. The brute force
approach  I thought of is to simply split the dataframe into to (one
even rows, one odd rows), merge by exp, and then calculate a difference.
But this seems to require renaming the rslt column in the two new
dataframes so they are different in the merge (say, rslt_cont n the odd
dataframe, and rslt_trt in the even dataframe), allowing me to calculate
a difference between the two.

While I suppose this would work, I'm wondering if I'm missing a more
elegant 'in place' approach that doesn't require me to split the data
frame and do every via a merge.

Suggestions/pointers to the obvious welcome. I've tried playing with
lag, and some approaches using lag in the zoo package,  but haven't
found the magic trick. The problem (meaning, what I can't figure out)
seems to be conditioning the lag on the level of exp.

Many thanks...


mydata <-*data.frame*(x = c(20,35,45,55,70), n = rep(50,5), y =
c(6,17,26,37,44))



 [[alternative HTML version deleted]]

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


 [[alternative HTML version deleted]]

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


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


Re: [R] lagging over consecutive pairs of rows in dataframe

2017-03-18 Thread Evan Cooch


On 3/17/2017 12:58 PM, Ulrik Stervbo wrote:
> Hi Evan
>
> you can easily do this by applying diff() to each exp group.
>
> Either using dplyr:
> library(dplyr)
> mydata %>%
>   group_by(exp) %>%
>   summarise(difference = diff(rslt))
>
> Or with base R
> aggregate(mydata, by = list(group = mydata$exp), FUN = diff)
>
>


Indeed -- thanks very much!

[[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] lagging over consecutive pairs of rows in dataframe

2017-03-17 Thread Evan Cooch
Suppose I have a dataframe that looks like the following:

n=2
mydata <- data.frame(exp = rep(1:5,each=n), rslt = 
c(12,15,7,8,24,28,33,15,22,11))
mydata
exp rslt
11   12
21   15
327
428
53   24
63   28
74   33
84   15
95   22
10   5   11

The variable 'exp' (for experiment') occurs in pairs over consecutive 
rows -- 1,1, then 2,2, then 3,3, and so on. The first row in a pair is 
the 'control', and the second is a 'treatment'. The rslt column is the 
result.

What I'm trying to do is create a subset of this dataframe that consists 
of the exp number, and the lagged difference between the 'control' and 
'treatment' result.  So, for exp=1, the difference is (15-12)=3. For 
exp=2,  the difference is (8-7)=1, and so on. What I'm hoping to do is 
take mydata (above), and turn it into

  exp  diff
1   1  3
2   2  1
3   3  4
4   4  -18
5   5  -11

The basic 'trick' I can't figure out is how to create a lagged variable 
between the second row (record) for a given level of exp, and the first 
row for that exp.  This is easy to do in SAS (which I'm more familiar 
with), but I'm struggling with the equivalent in R. The brute force 
approach  I thought of is to simply split the dataframe into to (one 
even rows, one odd rows), merge by exp, and then calculate a difference. 
But this seems to require renaming the rslt column in the two new 
dataframes so they are different in the merge (say, rslt_cont n the odd 
dataframe, and rslt_trt in the even dataframe), allowing me to calculate 
a difference between the two.

While I suppose this would work, I'm wondering if I'm missing a more 
elegant 'in place' approach that doesn't require me to split the data 
frame and do every via a merge.

Suggestions/pointers to the obvious welcome. I've tried playing with 
lag, and some approaches using lag in the zoo package,  but haven't 
found the magic trick. The problem (meaning, what I can't figure out) 
seems to be conditioning the lag on the level of exp.

Many thanks...


mydata <-*data.frame*(x = c(20,35,45,55,70), n = rep(50,5), y = 
c(6,17,26,37,44))



[[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] matrix merge, or something else?

2017-03-10 Thread Evan Cooch

Slick -- thanks.

On 3/10/2017 1:26 AM, Jeff Newmiller wrote:

test2[ , colnames( test1 ) ] <- test1


__
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] concatenating range of columns in dataframe

2017-03-10 Thread Evan Cooch



On 3/10/2017 2:24 AM, Ulrik Stervbo wrote:

Hi Evan,

the unite function of the tidyr package achieves the same as Jim 
suggested, but in perhaps a slightly more readable manner.


Ulrik



I use perl for scripting, so readability isn't a big factor. ;-)

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.


Re: [R] concatenating range of columns in dataframe

2017-03-10 Thread Evan Cooch



On 3/10/2017 1:48 AM, Jim Lemon wrote:

Hi Evan,
How about this:

df2<-data.frame(Trt=df[,1],Conc=apply(df[,2:5],1,paste,sep="",collapse=""))

Jim





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.


Re: [R] concatenating range of columns in dataframe

2017-03-10 Thread Evan Cooch



On 3/10/2017 2:23 AM, Bert Gunter wrote:

I think you need to spend some time with an R tutorial or two,
especially with regard to indexing.

Unless I have misunderstood (apologies if I have),

df$Conc <- apply(df[,-1],1,paste,collapse="")

does it.

-- Bert



\

Thanks -- sage advice.

__
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] concatenating range of columns in dataframe

2017-03-09 Thread Evan Cooch

Suppose I have the following data frame (call it df):

Trt   y1  y2  y3  y4
A1A   1001
A1B  1100
A1 C   0   10   1
A1D   111   1

What I want to do is concatenate columns y1  -> y4 into a contiguous 
string (which I'll call df$conc), so that the final df looks like


Trt  Conc
A1A   1001
A1B   1100
A1C  0101
A1D   


Now, if my initial dataframe was simply

 1   0  0  1
 1   1  0  0
  0  1  0  1
  1  1  1  1

then apply(df,1,paste,collapse="") does the trick, more or less.

But once I have a Trt column, this approach yields

A1A1001
A1B1100
A1C0101
A1D

I need to maintain the space between Trt, and the other columns. So, I'm 
trying to concatenate a subset of columns in the data frame, but I don't 
want to have to do something like create a cahracter vector of the 
column names to do it (e.g., c("y1","y2","y3","y4"). Doing a few by hand 
that way is easy, but not if you  have dozens to hundreds of columns to 
work with.


 Ideally, I'd like to be able to say

"concatenate df[,2:4], get rid of the spaces, pipe the concatenated 
columns to a new named column, and drop the original columns from the 
final df.


Heuristically,

df$conc <- concatenate df[,2:4] # making a new, 5th column in df
df[,2:4] <- NULL   # to drop original columns 2 -> 4

Suggestions/pointers to the obvious appreciated.

Thanks in advance!

__
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] matrix merge, or something else?

2017-03-09 Thread Evan Cooch
Suppose I have the following two matrices, both with same number of rows 
(3), but different number of columns (3 in test1, 4 in test2).


test1 <- matrix(c(1,1,0,1,0,-1,-1,-1,0),3,3,byrow=T);
test2 <- matrix( rep( 0, len=12), nrow = 3)

I label the rows and columns of the two matrices as follows:

rownames(test1) <- c("row1","row2","row3")
rownames(test2) <- c("row1","row2","row3")

colnames(test1) <- c("a","b","d")
colnames(test2) <- c("a","b","c","d")

So, if we look at the matrices, we see

test1

 a  b  d
row1   1  1  0
row2   1  0 -1
row3  -1 -1  0


test2

a b c d
row1  0 0 0 0
row2  0 0 0 0
row3  0 0 0 0

So, we see that while both matrices have the same rows, the matrix test1 
has a subset of the columns of test2. In test1, there is no column for 
'c' -- have columns for 'a', 'b', 'd'.


Now, what I want to do is this -- take the information from each column 
in test1, and substitute it into the same row/column in test2. The end 
result should be a matrix that looks like:


a  b  c  d
row1  1  1  0  0
row2  1  0  0 -1
row3 -1 -1 0   0

My initial though  was some sort of merge by row and column, with some 
funky sort of intersection, but I couldn't figure out how to get that to 
work.


Any suggestions/pointers to the obvious most appreciated.

__
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] evaluating function over seq of values

2017-02-13 Thread Evan Cooch



Note that in your likelihood function, N can be a vector of values, so
you can compute the likelihood for all values of N and just access the
value you want via subscripting rather than repeatedly computing it
for different N's.


OK -- that is the part I'm stuck at - pointers to how to do precisely 
that appreciated (I don't use R a lot -- and it shows ;-)






__
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] evaluating function over seq of values

2017-02-13 Thread Evan Cooch

The MWE (below) shows what I'm hoping to get some help with:

step 1\ specify the likelihood expression I want to evaluate using a 
brute-force grid search (not that I would do this in practice, but it is 
a convenient approach to explain the idea in a class...).


step 2\ want to evaluate the likelihood at each of a sequence of values 
of N (for this example, seq(80,200,1)).


step 3\ take all of the values of the likelihood at each value for N, 
and (say) plot them


I'm sure there is a clever way to vectorize all this, but my token 
attempts at wrestling sapply into submission have failed me here. In my 
MWE, I use a simple loop, which has the advantages of working, and being 
completely transparent as to what it is doing. For teaching purposes, 
this is perhaps fine, but I'm curious as to how I could accomplish the 
same thing avoiding the loop.


Thanks in advance...

--


# ML estimation by simple grid search

rm(list=ls())
library("optimx")

# set up likelihood function

f_like <- function(par) {
p1 <- par[1];
p2 <- par[2];
p3 <- par[3];
p4 <- par[4];
   lfactorial(N)-lfactorial(N-79) +
(30*log(p1)+(N-30)*log(1-p1)) +
(15*log(p2)+(N-15)*log(1-p2)) +
(22*log(p3)+(N-22)*log(1-p3)) +
(45*log(p4)+(N-45)*log(1-p4)) }


# do the otimization using optimx nested in a loop (works, but guessing 
there is an

# easier way using lapply or some such...)

count <- 1;

dat <- matrix(c(0,0,0),length(seq(80,200,1)),3)

for (N in seq(80,200,1)) {

results_optx <- optim(c(0.2,0.2,0.2,0.2), f_like,
 method = "L-BFGS-B", lower=c(0.005,0.005,0.005,0.005), 
upper=c(0.990,0.995,0.995,0.995),

  hessian = TRUE,control=list(fnscale=-1))

like_mod <- results_optx$value;
 dat[count,1] <- count;
 dat[count,2] <- N;
 dat[count,3] <- like_mod;
count=count+1;
}

plot(dat[,2],dat[,3],type="l",bty="n",  xlim=c(79,205), yaxs = 
"i",main="likelihood profile",xlab="N", ylab="Likelihood")


__
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 lists of random matrices

2016-11-09 Thread Evan Cooch

>>
>> Hi,
>>
>> See ?replicate
>>
>> Example:
>>
>> ## Create a list of 5 2x2 matrices
>
>
> Sorry, correction on my reply.
>
> I copied the wrong output, It should be:
>
> > replicate(5, matrix(rnorm(4), 2, 2), simplify = FALSE)
>


Perfect does the trick. Thanks also for the lapply solutions from 
others. The replicate approach is more 'transparent' at least to me.

[[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] creating lists of random matrices

2016-11-09 Thread Evan Cooch

So, its easy enough to create a random matrix, using something like (say)

matrix(rnorm(4),2,2)

which generates a (2x2) matrix with random N(0,1) in each cell.

But, what I need to be able to do is create a 'list' of such random 
matrices, where the length of the list (i.e., the number of said random 
matrices I store in the list) is some variable I can pass to the 
function (or loop).


I tried the obvious like

hold <- list()
for (i in 1:5) {
hold[[i]] <- matrix(rnorm(4),2,2)
}


While this works, it seems inelegant, and I'm wondering if there is a 
better (more efficient) way to accomplish the same thing -- perhaps 
avoiding the loop.


Thanks in advance...

__
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] problems compiling packages | 3.3.0 | Linux

2016-06-03 Thread Evan Cooch
OK -- thanks. I used to compile from source routinely, but could never 
get thee 'hand rolled' version of R to play nice with some external 
applications (specifically, jags, and openbugs).



On 6/2/2016 5:41 PM, Marc Schwartz wrote:

On Jun 2, 2016, at 10:35 AM, Evan Cooch <evan.co...@gmail.com> wrote:

Updated my R install on my GNU/Linux boxes (running RHEL 6.xx), using latest 
from CRAN (i.e., not compiling from source), and while said upgrade seemed to 
go fine, am having all sorts of problems with getting some packages to compile 
(either during an initial install attempt, or upgrade to existing packages).


Just for clarification, if you were NOT installing from source, you were NOT 
installing from CRAN. Precompiled RH RPM binaries of R have not been available 
from CRAN for quite some time.

Presumably you used 'yum' and were installing via the EPEL using their 
precompiled binary RPMs? Those would be configured for your specific RHEL 
distribution to have dependencies that are compatible.

The RPMS there would include both "base" R and the additional "recommended" 
packages, which are part of the default R distribution and includes nlme.

More below.


For example, if I try to update nlme, I get the following errors, which are 
pretty well fatal:

gcc: error: /builddir/build/BUILD/R-3.3.0/zlib-1.2.8/target/usr/lib64/libz.a: 
No such file or directory
gcc: error: 
/builddir/build/BUILD/R-3.3.0/bzip2-1.0.6/target/usr/lib64/libbz2.a: No such 
file or directory
gcc: error: /builddir/build/BUILD/R-3.3.0/xz-5.2.2/target/usr/lib64/liblzma.a: 
No such file or directory
gcc: error: /builddir/build/BUILD/R-3.3.0/pcre-8.38/target/usr/lib64/libpcre.a: 
No such file or directory
gcc: error: 
/builddir/build/BUILD/R-3.3.0/curl-7.48.0/target/usr/lib64/libcurl.a: No such 
file or directory


I think the clue is the version of the libs the installer seems to be looking 
for. For example, zlib-1.2.8. RHEL only supports zlib-1.2.3-29 (RHEL, like most 
'enterprise distros', is typically 1 step back from 'bleeding edge').

Any way I can force R CMD (or some such) to use system libs, instead of looking 
for specific, newer versions? Or, any other suggestions?

Serious pain in the butt. R 3.2.5 was working perfectly -- upgrade pretty much 
gummed things up, as far as compiling some packages.

Thanks in advance.

p.s. wasn't sure if this should go to r-help, or r-packages.


Neither one.

You should be posting to R-SIG-Fedora:

   https://stat.ethz.ch/mailman/listinfo/r-sig-fedora

Please re-post there as both RH/Fedora users and the RH RPM maintainers read 
that list, should there be issues with the EPEL RPMs relative to dependencies.

Regards,

Marc Schwartz




__
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] problems compiling packages | 3.3.0 | Linux

2016-06-02 Thread Evan Cooch
Updated my R install on my GNU/Linux boxes (running RHEL 6.xx), using 
latest from CRAN (i.e., not compiling from source), and while said 
upgrade seemed to go fine, am having all sorts of problems with getting 
some packages to compile (either during an initial install attempt, or 
upgrade to existing packages).


For example, if I try to update nlme, I get the following errors, which 
are pretty well fatal:


gcc: error: 
/builddir/build/BUILD/R-3.3.0/zlib-1.2.8/target/usr/lib64/libz.a: No 
such file or directory
gcc: error: 
/builddir/build/BUILD/R-3.3.0/bzip2-1.0.6/target/usr/lib64/libbz2.a: No 
such file or directory
gcc: error: 
/builddir/build/BUILD/R-3.3.0/xz-5.2.2/target/usr/lib64/liblzma.a: No 
such file or directory
gcc: error: 
/builddir/build/BUILD/R-3.3.0/pcre-8.38/target/usr/lib64/libpcre.a: No 
such file or directory
gcc: error: 
/builddir/build/BUILD/R-3.3.0/curl-7.48.0/target/usr/lib64/libcurl.a: No 
such file or directory



I think the clue is the version of the libs the installer seems to be 
looking for. For example, zlib-1.2.8. RHEL only supports zlib-1.2.3-29 
(RHEL, like most 'enterprise distros', is typically 1 step back from 
'bleeding edge').


Any way I can force R CMD (or some such) to use system libs, instead of 
looking for specific, newer versions? Or, any other suggestions?


Serious pain in the butt. R 3.2.5 was working perfectly -- upgrade 
pretty much gummed things up, as far as compiling some packages.


Thanks in advance.

p.s. wasn't sure if this should go to r-help, or r-packages.

__
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] embedding expression into title in R plot

2016-01-11 Thread Evan Cooch



On 1/11/2016 2:08 PM, William Dunlap wrote:

I tend to use bquote, as in

   x_label <- bquote(bold(species) ~ (italic(N1)))
   plot(1:10,main=bquote("This is the expression for" ~ .(x_label) * "!"))





Thanks -- I thought I'd tried something very close to this in my various 
attempts, but it would seem, not close enough.


I'll give your suggestion a try. It isn't a critical feature/need on my 
end (since I can live without elements of the title being bold, or 
italic), but I'm always happier knowing what to do if I *need* do - in 
future.


__
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] embedding expression into title in R plot

2016-01-11 Thread Evan Cooch

David --

On 1/11/2016 1:01 PM, David Winsemius wrote:



On Jan 11, 2016, at 7:59 AM, Evan Cooch <evan.co...@gmail.com> wrote:

Suppose I've specified that the xlab for a plot is

expression(bold(species~(italic(N1

In other words, I want the axis label to be bold, italic 'species (N1)'

Now, I want the title for the plot to be have this label embedded in the
title.

Say, 'This is the plot for Species (N1)'.

For a variety of reasons, I've set this up so that the xlab is a global
parameter (basically, because the labels are set in a function which
when called, generates various plots):

x_label <<- expression(bold(species~(italic(N1




So, in the title, I've tried

  title(main=paste("This is the plot for ",x_label,"nullcline", sep=" "));

but what this does is generate something like

'This is the plot for bold(species~(italic(N1)))'

In other words, it pastes the text of the expression into the title, but
not what the expression 'evaluates' to.

Is there any way around this?


You instead need the `bquote` function. The `paste` function will only confuse things. In this 
particular instance it is embedding the literal as.character result of 'x_label'-value in a 
character object rather than in an expression-object. Since you have not offered a full example it 
remains unclear whether you want the words: "species" or "N1" rather than the 
values of those names.



Thanks. I had wondered if bquote was the solution, but wasn't sure. Have 
followed your suggestion, but for the moment, am having problems getting 
it to work. I haven't figured out how to get bquote to actually evaulate 
the expression.






Thanks in advance...


[[alternative HTML version deleted]]


This is a plain text mailing list.




Indeed -- forgot to flip the switch on my email client, which defaults 
to sending both plain text and HTML email.



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


David Winsemius
Alameda, CA, USA




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


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

2016-01-11 Thread Evan Cooch



On 1/11/2016 1:54 PM, William Dunlap wrote:

The following shows how to get different colors for most features of a
scatterplot:

plot(1:11,log(1:11),ann=FALSE,axes=FALSE,col="pink",pch=16)
box(col="gray")
title(xlab="X Axis Label", col.lab="light blue")
title(ylab="Y Axis Label", col.lab="light green")
axis(side=1, at=c(2,3,5,7,11), lab=as.expression(lapply(1:5,
function(i)bquote(pi[.(i)]))), col.axis="red", col="orange")
axis(side=2, at=log(c(2,3,5,7,11)), lab=as.expression(lapply(1:5,
function(i)bquote(lambda[.(i)]))), col.axis="blue", col="green")
title(main="Main Title", col.main="magenta", sub="(subtitle)",
col.sub="yellow")

See help(par) for details.  The 'cex' and 'font' parameters have same
subtypes as 'col'.






Thanks -- very helpful.

__
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] embedding expression into title in R plot

2016-01-11 Thread Evan Cooch
Suppose I've specified that the xlab for a plot is

expression(bold(species~(italic(N1

In other words, I want the axis label to be bold, italic 'species (N1)'

Now, I want the title for the plot to be have this label embedded in the 
title.

Say, 'This is the plot for Species (N1)'.

For a variety of reasons, I've set this up so that the xlab is a global 
parameter (basically, because the labels are set in a function which 
when called, generates various plots):

x_label <<- expression(bold(species~(italic(N1

So, in the title, I've tried

  title(main=paste("This is the plot for ",x_label,"nullcline", sep=" "));

but what this does is generate something like

'This is the plot for bold(species~(italic(N1)))'

In other words, it pastes the text of the expression into the title, but 
not what the expression 'evaluates' to.

Is there any way around this?

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


[R] different coloured axis title labels for different axes

2016-01-11 Thread Evan Cooch
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.


[R] column means dropping column minimum

2015-12-08 Thread Evan Cooch

Suppose I have something like the following dataframe:

samp1 <- c(60,50,20,90)
samp2 <- c(60,60,90,58)
samp3 <- c(25,65,65,90)

test <- data.frame(samp1,samp2,samp3)

I want to calculate column means. Easy enough, if I want to use all the 
data within each column:



print(colMeans(test),na.rm = TRUE)


However, I'm danged if I can figure out how to do the same thing after 
dropping the minimum value for each column. For example, column 1 in the 
dataframe test consists of 60, 50,20,90. I want to calculate the mean 
over (60,50,90), dropping the minimum value (20). Figuring out what the 
minimum value is in a single column is easy, but I can't figure out how 
to arm-twist colMeans into 'applying itself' to the elements of a column 
greater than the minimum, for each column in turn. I've tried 
permutations of select, subset etc., to no avail. Only thing I can think 
of is to (i) find the minimum in a column, (ii) change it to NA, and 
then (iii) tell colMeans to na.rm = TRUE):


test2 <- test

for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]==NA}

print(test2)

print(colMeans(test2),na.rm = TRUE)


While this works, seems awfully 'clunky' -- is there a better way?

Thanks in advance...

__
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] JAGS 4.x, rjags 4.x problems | Linux

2015-11-05 Thread Evan Cooch



On 11/5/2015 9:45 AM, Rainer Hurling wrote:

Am 04.11.2015 um 21:36 schrieb Evan Cooch:



On 11/4/2015 2:08 PM, Evan Cooch wrote:

Greetings --

This has also been posted on the jags forum, but since I suspect the
problem is more 'R-related' than jags, will aos post here.

Decided to 'upgrade' from jags 3.x.x to 4.x.x today, on my GNU/Linux
boxes (which run latest RHEL). Here are the basic details:

1\ used R 3.2.2 compiled from source. 64-bit -- nothing fancy, other
than the fact that I used OpenBLAS instead of 'generic'. Works fine.

2\ downloaded and compiled JAGS 4.0.1 from source (nothing fancy,
./configure & make & make install) -- no errors. Runs fine as a
standalone app from CLI.


3\ Downloaded rjags_4-3.tar.gz, and installed from R CLI (within R --
usual R CMD INSTALL approach). Again, no errors reported.


However, when I fire up R, and try something simple like

library(R2jags)

I get a whole slew of error messages - following is reproducible on
all my machines:

Loading required package: rjags
Loading required package: coda
Error : .onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object
'/usr/lib64/R/library/rjags/libs/rjags.so':
libjags.so.3: cannot open shared object file: No such file or directory
Error: package ‘rjags’ could not be loaded




Further puzzlement -- I uninstalled R2jags and rjags, with the idea that
re-installing them (ostensibly with the 'latest and greatest') would do
the trick. While the process went fine for R2jags, when I tried to
re-install rjags, got the following error messages:

checking for gcc -m64 -std=gnu99 option to accept ISO C89... none needed
checking for jags_version in -ljags... yes
checking version of JAGS library... wrong version
configure: error: rjags requires JAGS version 4.x.y
ERROR: configuration failed for package ‘rjags’
* removing ‘/usr/lib64/R/library/rjags’
* restoring previous ‘/usr/lib64/R/library/rjags’


Hmm, is it possible, that your JAGS 4.x.y installation is fine, but an 
old libjags.so library is lying around from a not fully completed 
deinstallation? Could you have a look for older libjags.so versions, 
please?


Just a thought.




I suppose thats possible -- I'll go through the sequence again at some 
point, and report back.


__
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] JAGS 4.x, rjags 4.x problems | Linux -- solved

2015-11-05 Thread Evan Cooch
Well, sort of. I got sufficiently frustrated that I completely 
uninstalled R, jags, and everything related. Did a re-install using only 
versions of R nd JAGS found in the epel repo. No muss, no muss -- all 
works.


Out of curiosity, uninstalled again, and tried my usual sequence of 
manually compile R from source, same with JAGS. R works, JAGS works, but 
can't get any R package linking the two (say, rjags, R2jags), to 
recognize that JAGS is installed.


Ah well, at least the 'install from repos' approach works. I'll have to 
make do with that.


__
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] JAGS 4.x, rjags 4.x problems | Linux

2015-11-04 Thread Evan Cooch



On 11/4/2015 2:08 PM, Evan Cooch wrote:

Greetings --

This has also been posted on the jags forum, but since I suspect the 
problem is more 'R-related' than jags, will aos post here.


Decided to 'upgrade' from jags 3.x.x to 4.x.x today, on my GNU/Linux 
boxes (which run latest RHEL). Here are the basic details:


1\ used R 3.2.2 compiled from source. 64-bit -- nothing fancy, other 
than the fact that I used OpenBLAS instead of 'generic'. Works fine.


2\ downloaded and compiled JAGS 4.0.1 from source (nothing fancy, 
./configure & make & make install) -- no errors. Runs fine as a 
standalone app from CLI.



3\ Downloaded rjags_4-3.tar.gz, and installed from R CLI (within R -- 
usual R CMD INSTALL approach). Again, no errors reported.



However, when I fire up R, and try something simple like

library(R2jags)

I get a whole slew of error messages - following is reproducible on 
all my machines:


Loading required package: rjags
Loading required package: coda
Error : .onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object 
'/usr/lib64/R/library/rjags/libs/rjags.so':

libjags.so.3: cannot open shared object file: No such file or directory
Error: package ‘rjags’ could not be loaded




Further puzzlement -- I uninstalled R2jags and rjags, with the idea that 
re-installing them (ostensibly with the 'latest and greatest') would do 
the trick. While the process went fine for R2jags, when I tried to 
re-install rjags, got the following error messages:


checking for gcc -m64 -std=gnu99 option to accept ISO C89... none needed
checking for jags_version in -ljags... yes
checking version of JAGS library... wrong version
configure: error: rjags requires JAGS version 4.x.y
ERROR: configuration failed for package ‘rjags’
* removing ‘/usr/lib64/R/library/rjags’
* restoring previous ‘/usr/lib64/R/library/rjags’


I'm confused as to how it is not finding JAGS 4.x.y, which is not only 
most definitely on the system, but in the path:


[root@euler egc]# jags
Welcome to JAGS 4.0.1 on Wed Nov  4 15:35:12 2015
JAGS is free software and comes with ABSOLUTELY NO WARRANTY
Loading module: basemod: ok
Loading module: bugs: ok

__
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] JAGS 4.x, rjags 4.x problems | Linux

2015-11-04 Thread Evan Cooch



On 11/4/2015 3:31 PM, Yvan Richard wrote:

Hi Evan

The last version of rjags on CRAN is 4.4. Have you tried it?
http://cran.stat.auckland.ac.nz/web/packages/rjags/index.html
I did have the same problem before updating it, but it now works on my
Ubuntu with the new JAGS version.

Cheers,
-Yvan



yes, but when I do, I get the following during the install (which fails).

checking version of JAGS library... wrong version
configure: error: rjags requires JAGS version 4.x.y
ERROR: configuration failed for package ‘rjags’
* removing ‘/usr/lib64/R/library/rjags’
* restoring previous ‘/usr/lib64/R/library/rjags’


which makes no sense, because I have JAGS 4.0.01 on the system, and in 
the path


Welcome to JAGS 4.0.1 on Wed Nov  4 15:41:46 2015
JAGS is free software and comes with ABSOLUTELY NO WARRANTY
Loading module: basemod: ok
Loading module: bugs: ok
.

__
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] JAGS 4.x, rjags 4.x problems | Linux

2015-11-04 Thread Evan Cooch
I wonder if this is the problem -- on my system(s), R is installed to 
/usr/lib64/R, whereas JAGS and associated files is in 
/usr/local/lib/JAGS. I have a hunch that the problem relates to where  
rjags expects to find things during install/compile, given how R was 
compiled, and where it is installed.


Seem reasonable? Not sure what to do about it, but...

On 11/4/2015 3:42 PM, Evan Cooch wrote:



On 11/4/2015 3:31 PM, Yvan Richard wrote:

Hi Evan

The last version of rjags on CRAN is 4.4. Have you tried it?
http://cran.stat.auckland.ac.nz/web/packages/rjags/index.html
I did have the same problem before updating it, but it now works on my
Ubuntu with the new JAGS version.

Cheers,
-Yvan



yes, but when I do, I get the following during the install (which fails).

checking version of JAGS library... wrong version
configure: error: rjags requires JAGS version 4.x.y
ERROR: configuration failed for package ‘rjags’
* removing ‘/usr/lib64/R/library/rjags’
* restoring previous ‘/usr/lib64/R/library/rjags’


which makes no sense, because I have JAGS 4.0.01 on the system, and in 
the path


Welcome to JAGS 4.0.1 on Wed Nov  4 15:41:46 2015
JAGS is free software and comes with ABSOLUTELY NO WARRANTY
Loading module: basemod: ok
Loading module: bugs: ok
.




__
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] JAGS 4.x, rjags 4.x problems | Linux

2015-11-04 Thread Evan Cooch

Greetings --

This has also been posted on the jags forum, but since I suspect the 
problem is more 'R-related' than jags, will aos post here.


Decided to 'upgrade' from jags 3.x.x to 4.x.x today, on my GNU/Linux 
boxes (which run latest RHEL). Here are the basic details:


1\ used R 3.2.2 compiled from source. 64-bit -- nothing fancy, other 
than the fact that I used OpenBLAS instead of 'generic'. Works fine.


2\ downloaded and compiled JAGS 4.0.1 from source (nothing fancy, 
./configure & make & make install) -- no errors. Runs fine as a 
standalone app from CLI.



3\ Downloaded rjags_4-3.tar.gz, and installed from R CLI (within R -- 
usual R CMD INSTALL approach). Again, no errors reported.



However, when I fire up R, and try something simple like

library(R2jags)

I get a whole slew of error messages - following is reproducible on all 
my machines:


Loading required package: rjags
Loading required package: coda
Error : .onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object 
'/usr/lib64/R/library/rjags/libs/rjags.so':

libjags.so.3: cannot open shared object file: No such file or directory
Error: package ‘rjags’ could not be loaded


Meaning, what? I checked, and rjags.so is where its supposed to be.If I run

 R CMD ldd /usr/lib64/R/library/rjags/libs/rjags.so

no failures at any point.

Suggestions? Pointers to the obvious?

Thanks very much in advance.

__
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] 'strange' R graphics problem | Linux...

2015-10-15 Thread Evan Cooch
Tried compiling all previous version of R 3.x.x. Compilations went fine. 
Code works, but every version throws the 'graphics problem' (basically, 
spawns the X1 window, which more or less becomes a static screen capture 
of the desktop under the spawned window.

What I think is related (cause?) is the code I had which generated lots 
of graphics worked fine in early summer, no longer works properly. While 
R has been updated since then, I don't think that's the problem (based 
on replicating the problem back through several iterations). What I 
suspect is driving things are the numerous package updates to CentOS 
which occurred in the later summer,many of which touched things related 
to X11. Short of re-installing a earlier version of the distro (which I 
could do in a VM, but that takes more time than I have), I will 
tentatively suggest the problem arises because of the CentOS changes.

One bit of information I want to flesh out is that I only get the 
'graphics error' if I am working at the console of the CentOS box. If I 
create an SSH tunnel, and do a remote desktop (with, say TightVNC), 
graphics work *perfectly*. VNC and related approaches often use very 
different graphical subsystems (mostly designed to minimize bandwidth 
overhead), but in so doing, R graphics  'work'.



On 10/14/2015 9:39 PM, Thomas Adams wrote:
> Evan,
>
> I have R 3.2.2 installed on my Ubuntu 15.04 machine -- no problems 
> with the graphics display. I have R 3.1.1 installed on my Ubuntu 14.04 
> machine, that, as expected I have not had any problems with... I tried 
> to install 3.2.2 and 3.2.1 from source and got a very strange compile 
> error, which I need to sort out -- recompiling 3.1.1 failed as well...
>
> Best,
> Tom
>
> On Wed, Oct 14, 2015 at 6:35 PM, Evan Cooch <evan.co...@cornell.edu 
> <mailto:evan.co...@cornell.edu>> wrote:
>
> A clue --
>
> Working from home, I created an ssh tunnel into my CentOS box, and
> brought up the desktop remotely using VNC. Fire up R in a
> terminal, and *voila*, graphics work fine.
>
> So, if I'm sitting at the CentOS machine, R graphics choke and
> die. If I use a remote desktop approach, graphics fine.
>
> Very strange...
>
> Forgot to add before, here are the 'capabilities' from my R
> install -- X11 and cairo both 'there', so not sure what the
> problem is.
>
>jpeg pngtiff tcltk X11aqua
>TRUETRUETRUETRUE TRUE   FALSE
>http/ftp sockets  libxmlfifo cledit   iconv
>TRUETRUETRUETRUE TRUETRUE
> NLS profmem   cairo ICU long.double
>     libcurl
>TRUE   FALSETRUETRUE TRUE   FALSE
>
> On 10/14/2015 4:00 PM, Evan Cooch wrote:
>>
>>
>> On 10/14/2015 3:51 PM, Thomas Adams wrote:
>>> Evan,
>>>
>>> I have Ubuntu 14.04 and 15.10 at home and have not had problems,
>>> but I don't think I've been using R 3.2.2 — I'll try this evening.
>>
>> Indeed - it could be an R-version issue, and not so much the
>> distro. I might, for chuckles, roll back to 3.2.1, and see what
>> happens.
>>
>>>
>>> Tom
>>>
>>> On Wed, Oct 14, 2015 at 2:47 PM, Evan Cooch
>>> <evan.co...@gmail.com <mailto:evan.co...@gmail.com>> wrote:
>>>
>>> Tom --
>>>
>>> On 10/14/2015 3:35 PM, Thomas Adams wrote:
>>>> Evan,
>>>>
>>>> Not that this helps you, but I am using a very similar
>>>> platform and I am having the identical problem. My test
>>>> simply comes from the first help(plot) example. I tried
>>>> doing some things to 'correct' the problem and ended up
>>>> mucking-up my Gnome environment. In the process, I was able
>>>> to get the example to display correctly, but as I said, I
>>>> now have an unusable system. I'm not sure this is an R
>>>> specific problem, but some incompatibility with the Centos
>>>> Gnome environment.
>>>>
>>>
>>> Thanks very much. I have a couple of Linux Mint 17.x systems
>>> as well -- I'll see if they throw the same problem at me/us.
>>>
>>>> Tom
>>>>
>>>> On Wed, Oct 14, 2015 at 8:36 AM, Evan Cooch
>>>> <evan.co...@gmail.com <mailto:evan.co...@gmail.com>> wrote:
>>>>
>>>> So, am

[R] 'strange' R graphics problem | Linux...

2015-10-14 Thread Evan Cooch
So, am running 3.2.2 on a Centos 6.xx box. Code executes fine, but I'm 
having a heck of a time with graphics. I don't think this is related to 
R in the broad sense, but how it is interacting with graphics on the 
system. here is a description of the problem.


1\ something simple:  test <- rnorm(100)

2\ try to generate a simple histogram  using hist(test)

3\ what happens is that a terminal window pops up (as I would expect for 
the graphic), but rather than showing the histogram, its essentially a 
screen-capture of the original terminal window in which I ran the 
script. Said second terminal window is not responsive, at all -- can't 
even close it short of opening another shell, and killing the process 
from the CLI.


4\ I get the exact same problem even if I try  a simple plot.new() -- 
generate a new terminal window, but with the same problem 'attributes' 
as described above.


For what it works, when I fire up gnuplot, terminal type set to X11 -- 
and basic gnuplot graphics (e.g., plot sin(x)) work perfectly. Other 
graphics seem to work fine too. Just nothing I try to plot using R.


Anyone have any ideas as to what to look for/try? Here is the output of 
sessionInfo() -- nothing obvious that I can see.


R version 3.2.2 (2015-08-14)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.7 (Final)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods base

__
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] 'strange' R graphics problem | Linux...

2015-10-14 Thread Evan Cooch


On 10/14/2015 3:51 PM, Thomas Adams wrote:
> Evan,
>
> I have Ubuntu 14.04 and 15.10 at home and have not had problems, but I 
> don't think I've been using R 3.2.2 — I'll try this evening.

Indeed - it could be an R-version issue, and not so much the distro. I 
might, for chuckles, roll back to 3.2.1, and see what happens.

>
> Tom
>
> On Wed, Oct 14, 2015 at 2:47 PM, Evan Cooch <evan.co...@gmail.com 
> <mailto:evan.co...@gmail.com>> wrote:
>
> Tom --
>
> On 10/14/2015 3:35 PM, Thomas Adams wrote:
>> Evan,
>>
>> Not that this helps you, but I am using a very similar platform
>> and I am having the identical problem. My test simply comes from
>> the first help(plot) example. I tried doing some things to
>> 'correct' the problem and ended up mucking-up my Gnome
>> environment. In the process, I was able to get the example to
>> display correctly, but as I said, I now have an unusable system.
>> I'm not sure this is an R specific problem, but some
>> incompatibility with the Centos Gnome environment.
>>
>
> Thanks very much. I have a couple of Linux Mint 17.x systems as
>     well -- I'll see if they throw the same problem at me/us.
>
>> Tom
>>
>> On Wed, Oct 14, 2015 at 8:36 AM, Evan Cooch <evan.co...@gmail.com
>> <mailto:evan.co...@gmail.com>> wrote:
>>
>> So, am running 3.2.2 on a Centos 6.xx box. Code executes
>> fine, but I'm having a heck of a time with graphics. I don't
>> think this is related to R in the broad sense, but how it is
>> interacting with graphics on the system. here is a
>> description of the problem.
>>
>> 1\ something simple:  test <- rnorm(100)
>>
>> 2\ try to generate a simple histogram using hist(test)
>>
>> 3\ what happens is that a terminal window pops up (as I would
>> expect for the graphic), but rather than showing the
>> histogram, its essentially a screen-capture of the original
>> terminal window in which I ran the script. Said second
>> terminal window is not responsive, at all -- can't even close
>> it short of opening another shell, and killing the process
>> from the CLI.
>>
>> 4\ I get the exact same problem even if I try  a simple
>> plot.new() -- generate a new terminal window, but with the
>> same problem 'attributes' as described above.
>>
>> For what it works, when I fire up gnuplot, terminal type set
>> to X11 -- and basic gnuplot graphics (e.g., plot sin(x)) work
>> perfectly. Other graphics seem to work fine too. Just nothing
>> I try to plot using R.
>>
>> Anyone have any ideas as to what to look for/try? Here is the
>> output of sessionInfo() -- nothing obvious that I can see.
>>
>> R version 3.2.2 (2015-08-14)
>> Platform: x86_64-redhat-linux-gnu (64-bit)
>> Running under: CentOS release 6.7 (Final)
>>
>> locale:
>>  [1] LC_CTYPE=en_US.UTF-8  LC_NUMERIC=C
>>  [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
>>  [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
>>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>>  [9] LC_ADDRESS=C  LC_TELEPHONE=C
>> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils  datasets  methods base
>>
>> __
>> R-help@r-project.org <mailto:R-help@r-project.org> mailing
>> list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible
>> code.
>>
>>
>>
>>
>>
>>
>
>
>
>
>


[[alternative HTML version deleted]]

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

Re: [R] 'strange' R graphics problem | Linux...

2015-10-14 Thread Evan Cooch
Tom --

On 10/14/2015 3:35 PM, Thomas Adams wrote:
> Evan,
>
> Not that this helps you, but I am using a very similar platform and I 
> am having the identical problem. My test simply comes from the first 
> help(plot) example. I tried doing some things to 'correct' the problem 
> and ended up mucking-up my Gnome environment. In the process, I was 
> able to get the example to display correctly, but as I said, I now 
> have an unusable system. I'm not sure this is an R specific problem, 
> but some incompatibility with the Centos Gnome environment.
>

Thanks very much. I have a couple of Linux Mint 17.x systems as well -- 
I'll see if they throw the same problem at me/us.

> Tom
>
> On Wed, Oct 14, 2015 at 8:36 AM, Evan Cooch <evan.co...@gmail.com 
> <mailto:evan.co...@gmail.com>> wrote:
>
> So, am running 3.2.2 on a Centos 6.xx box. Code executes fine, but
> I'm having a heck of a time with graphics. I don't think this is
> related to R in the broad sense, but how it is interacting with
> graphics on the system. here is a description of the problem.
>
> 1\ something simple:  test <- rnorm(100)
>
> 2\ try to generate a simple histogram  using hist(test)
>
> 3\ what happens is that a terminal window pops up (as I would
> expect for the graphic), but rather than showing the histogram,
> its essentially a screen-capture of the original terminal window
> in which I ran the script. Said second terminal window is not
> responsive, at all -- can't even close it short of opening another
> shell, and killing the process from the CLI.
>
> 4\ I get the exact same problem even if I try  a simple plot.new()
> -- generate a new terminal window, but with the same problem
> 'attributes' as described above.
>
> For what it works, when I fire up gnuplot, terminal type set to
> X11 -- and basic gnuplot graphics (e.g., plot sin(x)) work
> perfectly. Other graphics seem to work fine too. Just nothing I
> try to plot using R.
>
> Anyone have any ideas as to what to look for/try? Here is the
> output of sessionInfo() -- nothing obvious that I can see.
>
> R version 3.2.2 (2015-08-14)
> Platform: x86_64-redhat-linux-gnu (64-bit)
> Running under: CentOS release 6.7 (Final)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets methods base
>
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list --
> To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>
>


[[alternative HTML version deleted]]

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


Re: [R] 'strange' R graphics problem | Linux...

2015-10-14 Thread Evan Cooch


On 10/14/2015 4:00 PM, Evan Cooch wrote:
>
>
> On 10/14/2015 3:51 PM, Thomas Adams wrote:
>> Evan,
>>
>> I have Ubuntu 14.04 and 15.10 at home and have not had problems, but 
>> I don't think I've been using R 3.2.2 — I'll try this evening.
>
> Indeed - it could be an R-version issue, and not so much the distro. I 
> might, for chuckles, roll back to 3.2.1, and see what happens.
>
>>
>> Tom
>>


Tested on a Linux Mint 17.2 system, Cinnamon desktop -- R 3.2.2. 
Graphics work *perfectly*.

Will try rolling back to earlier version of R tomorrow on the CentOS 
6.xx box, to see if something has changed with R that is no longer 
playing nice with X11 as implemented on CentOS -- this wouldn't surprise 
me entirely, since CentOS goes for 'stability', whereas Mint is closer 
to 'bleeding edge'. If R is expecting a more 'current' implementation of 
X11 and associated libs than CentOS has, that would explain the problem.

[[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] 'strange' R graphics problem | Linux...

2015-10-14 Thread Evan Cooch
A clue --

Working from home, I created an ssh tunnel into my CentOS box, and 
brought up the desktop remotely using VNC. Fire up R in a terminal, and 
*voila*, graphics work fine.

So, if I'm sitting at the CentOS machine, R graphics choke and die. If I 
use a remote desktop approach, graphics fine.

Very strange...

Forgot to add before, here are the 'capabilities' from my R install -- 
X11 and cairo both 'there', so not sure what the problem is.

jpeg pngtiff   tcltk X11 aqua
TRUETRUETRUETRUETRUE FALSE
http/ftp sockets  libxmlfifo  cledit iconv
TRUETRUETRUETRUETRUE TRUE
 NLS profmem   cairo ICU long.double libcurl
TRUE   FALSETRUETRUETRUE FALSE

On 10/14/2015 4:00 PM, Evan Cooch wrote:
>
>
> On 10/14/2015 3:51 PM, Thomas Adams wrote:
>> Evan,
>>
>> I have Ubuntu 14.04 and 15.10 at home and have not had problems, but 
>> I don't think I've been using R 3.2.2 — I'll try this evening.
>
> Indeed - it could be an R-version issue, and not so much the distro. I 
> might, for chuckles, roll back to 3.2.1, and see what happens.
>
>>
>> Tom
>>
>> On Wed, Oct 14, 2015 at 2:47 PM, Evan Cooch <evan.co...@gmail.com 
>> <mailto:evan.co...@gmail.com>> wrote:
>>
>> Tom --
>>
>> On 10/14/2015 3:35 PM, Thomas Adams wrote:
>>> Evan,
>>>
>>> Not that this helps you, but I am using a very similar platform
>>> and I am having the identical problem. My test simply comes from
>>> the first help(plot) example. I tried doing some things to
>>> 'correct' the problem and ended up mucking-up my Gnome
>>> environment. In the process, I was able to get the example to
>>> display correctly, but as I said, I now have an unusable system.
>>> I'm not sure this is an R specific problem, but some
>>> incompatibility with the Centos Gnome environment.
>>>
>>
>> Thanks very much. I have a couple of Linux Mint 17.x systems as
>> well -- I'll see if they throw the same problem at me/us.
>>
>>> Tom
>>>
>>> On Wed, Oct 14, 2015 at 8:36 AM, Evan Cooch
>>> <evan.co...@gmail.com> wrote:
>>>
>>> So, am running 3.2.2 on a Centos 6.xx box. Code executes
>>> fine, but I'm having a heck of a time with graphics. I don't
>>> think this is related to R in the broad sense, but how it is
>>> interacting with graphics on the system. here is a
>>> description of the problem.
>>>
>>> 1\ something simple:  test <- rnorm(100)
>>>
>>> 2\ try to generate a simple histogram using hist(test)
>>>
>>> 3\ what happens is that a terminal window pops up (as I
>>> would expect for the graphic), but rather than showing the
>>> histogram, its essentially a screen-capture of the original
>>> terminal window in which I ran the script. Said second
>>> terminal window is not responsive, at all -- can't even
>>> close it short of opening another shell, and killing the
>>> process from the CLI.
>>>
>>> 4\ I get the exact same problem even if I try  a simple
>>> plot.new() -- generate a new terminal window, but with the
>>> same problem 'attributes' as described above.
>>>
>>> For what it works, when I fire up gnuplot, terminal type set
>>> to X11 -- and basic gnuplot graphics (e.g., plot sin(x))
>>> work perfectly. Other graphics seem to work fine too. Just
>>> nothing I try to plot using R.
>>>
>>> Anyone have any ideas as to what to look for/try? Here is
>>> the output of sessionInfo() -- nothing obvious that I can see.
>>>
>>> R version 3.2.2 (2015-08-14)
>>> Platform: x86_64-redhat-linux-gnu (64-bit)
>>> Running under: CentOS release 6.7 (Final)
>>>
>>> locale:
>>>  [1] LC_CTYPE=en_US.UTF-8  LC_NUMERIC=C
>>>  [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
>>>  [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
>>>  [7] LC_PAPER=en_US.UTF-8  LC_NAME=C
>>>  [9] LC_ADDRESS=C  LC_TELEPHONE=C
>>> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>>>
>>> attached base packages:
>>>

[R] extracting every nth character from a string...

2015-09-06 Thread Evan Cooch
Suppose I had the following string, which has length of integer multiple 
of some value n. So, say n=2, and the example string has a length of  
(2x4) = 8 characters.


str <- "ABCDEFGH"

What I'm trying to figure out is a simple, base-R coded way (which I 
heuristically call StrSubset in the following) to extract every nth 
character from the string, to generate a new string.


So

str <- "ABCDEFGH"

new_str <- StrSubset(str);

print(new_str)

which would yield

"ACEG"


Best I could come up with is something like the following, where I 
extract every odd character from the string:


StrSubset <- function(string)
  { 
paste(unlist(strsplit(string,""))[seq(1,nchar(string),2)],collapse="") }



Anything more elegant come to mind? Trying to avoid regex if possible 
(harder to explain to end-users), but if that meets the 'more elegant' 
sniff test, happy to consider...


Thanks in advance...

__
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] specifying dimensions of a graphic (not the window...)

2015-02-08 Thread Evan Cooch
Greetings --

Graphics newbie (I generally don't use R for graphics, so if the 
question is 'obvious', point that out gently ;-)

I'm trying to use levelplot in the lattice package, to generate what 
I'll call a 'decision table', where optimal decisions (discrete, on the 
interval [0.0,0.5] by increments of 0.1) from a dynamic programming 
problem are plotted as a function of time since the time horizon. The 
'matrix' I'm trying to plot is 100 rows x 10 columns. While using the 
following works, more or less...

rgb.palette - colorRampPalette(c(red, green), space = rgb)
levelplot(t(results$policy), main=optimal harvest, xlab=time from 
end, ylab=state (N), col.regions=rgb.palette(6), cuts=6, 
at=seq(0,0.5,0.1))


the rendered figure is way too narrow. I want to make the 
proportions of the 'levelplot' (what I usually call a 'heat map') square 
(or something else that I specify). I'm used to dedicated graphics 
applications wherew I simply grab the figure and resize it to whatever 
aspect ratio I want. Obviously, with R, I need to invoke some sort of 
command line argument.

In my searches, I've found a fair number of queries/answers about how to 
change the size of the graphics windows, but I could care lerss what the 
graphics window sizing is (presumably, it should adjust to whatever the 
size of the underlying graphic is). I want to 'hard code' the dimensions 
of the graphic itself, not the window it's rendered in.

I'm sure the answer is out there, but I've been unsuccessful at finding 
the magic keywords in my searches.

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


Re: [R] specifying dimensions of a graphic (not the window...)

2015-02-08 Thread Evan Cooch

On 2/8/2015 7:41 PM, Evan Cooch wrote:
 Greetings --

 Graphics newbie (I generally don't use R for graphics, so if the 
 question is 'obvious', point that out gently ;-)

 I'm trying to use levelplot in the lattice package, to generate what 
 I'll call a 'decision table', where optimal decisions (discrete, on 
 the interval [0.0,0.5] by increments of 0.1) from a dynamic 
 programming problem are plotted as a function of time since the time 
 horizon. The 'matrix' I'm trying to plot is 100 rows x 10 columns. 
 While using the following works, more or less...

 rgb.palette - colorRampPalette(c(red, green), space = rgb)
 levelplot(t(results$policy), main=optimal harvest, xlab=time from 
 end, ylab=state (N), col.regions=rgb.palette(6), cuts=6, 
 at=seq(0,0.5,0.1))



Sufficient solution to the problem for now -- adding the option 
aspect=fill fills the window, and if I specify the size of the window, 
then this amounts to the same thing, more or less.

Seems kind of a backward way to do it. I'd have thought setting size of 
the graphic, and then having the window size change dynamically around 
said graphic, would have been more intuitive.




[[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] naming rows/columns in 'array of matrices' | solved

2015-01-30 Thread Evan Cooch

The (obvious, after the fact) solution at the bottom. D'oh...

On 1/30/2015 2:07 PM, Evan Cooch wrote:

Suppose I have the following situation:

I have an array of 2 matrices, where each matrix is (2x2):

P - array(0, c(2,2,2))

P[,,1] - matrix(c(1,2,3,4),2,2,byrow=T);
P[,,2] - matrix(c(5,6,7,8),2,2,byrow=T);

I want to label rows and columns of each matrix in the array, such 
that P would look like



live dead
live  12
dead  34

, , 2

live  dead
 live 56
 dead 78

I've tried 'direct, brute force approaches like

rownames(P[,,1]) - c(live,dead)
colnames(P[,,1]) - c(live,dead)

(repeated for the second matrix), but this doesn't work.

Since all of the matrices are of the same dimension(s), and since I 
want the same rownames and colnames for each matrix, I'm hoping there 
is some simply magical permutation of lapply (I'm guessing) which will 
do the trick.


Forgot I was dealing with a multi-dimensional array, not a list. So, 
following works fine. I'm sure there are better approaches (where 
'better' is either 'cooler', or 'more flexible'), but for the moment...)


P - array(0, 
c(2,2,2),dimnames=list(c(live,dead),c(old,young),NULL))


P[,,1] - matrix(c(1,2,3,4),2,2,byrow=T);
P[,,2] - matrix(c(5,6,7,8),2,2,byrow=T);

print(P);

__
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] naming rows/columns in 'array of matrices'

2015-01-30 Thread Evan Cooch

Suppose I have the following situation:

I have an array of 2 matrices, where each matrix is (2x2):

P - array(0, c(2,2,2))

P[,,1] - matrix(c(1,2,3,4),2,2,byrow=T);
P[,,2] - matrix(c(5,6,7,8),2,2,byrow=T);

I want to label rows and columns of each matrix in the array, such that 
P would look like



live dead
live  12
dead  34

, , 2

live  dead
 live 56
 dead 78

I've tried 'direct, brute force approaches like

rownames(P[,,1]) - c(live,dead)
colnames(P[,,1]) - c(live,dead)

(repeated for the second matrix), but this doesn't work.

Since all of the matrices are of the same dimension(s), and since I want 
the same rownames and colnames for each matrix, I'm hoping there is some 
simply magical permutation of lapply (I'm guessing) which will do the trick.


 I'd also be interested in why the 'direct, brute force' approach 
(above) doesn't work, and what does, since I might need to manipulate 
row/col names for individual matrices in the array (if, say, dimensions 
of the matrices were not the same over the array).


Thanks in advance!

__
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] cbind in a loop...better way? | summary

2014-10-09 Thread Evan Cooch
Two solutions proposed -- not entirely orthogonal, but both do the 
trick. Instead of nesting cbin in a loop (as I did originally -- OP, 
below),


1\   do.call(cbind, lapply(mat_list, as.vector))

or

2\   sapply(mat_list,function(x) as.vector(x))


Both work fine. Thanks to Jeff Laake (2) + David Carlson (1) for their 
suggestions.



On 10/8/2014 3:12 PM, Evan Cooch wrote:
...or some such. I'm trying to work up a function wherein the user 
passes a list of matrices to the function, which then (1) takes each 
matrix, (2) performs an operation to 'vectorize' the matrix (i.e., 
given an (m x n) matrix x, this produces the vector Y of length  m*n 
that contains the columns of the matrix x, stacked below each other), 
and then (3) cbinds them together.


Here is an example using the case where I know how many matrices I 
need to cbind together. For this example, 2 square (3x3) matrices:


 a - matrix(c,0,20,50,0.05,0,0,0,0.1,0),3,3,byrow=T)
 b - matrix(c(0,15,45,0.15,0,0,0,0.2,0),3,3,byrow=T)

I want to vec them, and then cbind them together. So,

result  - cbind(matrix(a,nr=9), matrix(b,nr=9))

which yields the following:

  [,1]  [,2]
 [1,]  0.00  0.00
 [2,]  0.05  0.15
 [3,]  0.00  0.00
 [4,] 20.00 15.00
 [5,]  0.00  0.00
 [6,]  0.10  0.20
 [7,] 50.00 45.00
 [8,]  0.00  0.00
 [9,]  0.00  0.00

Easy enough. But, I want to put it in a function, where the number and 
dimensions  of the matrices is not specified. Something like


Using matrices (a) and (b) from above, let

  env - list(a,b).

Now, a function (or attempt at same) to perform the desired operations:

  vec=function(matlist) {

  n_mat=length(matlist);
  size_mat=dim(matlist[[1]])[1];

  result=cbind()

   for (i in 1:n_mat) {
 result=cbind(result,matrix(matlist[[i]],nr=size_mat^2))
  }

 return(result)

   }


When I run vec(env), I get the *right answer*, but I am wondering if 
there is a *better* way to get there from here than the approach I use 
(above). I'm not so much interested in 'computational efficiency' as I 
am in stability, and flexibility.


Thanks...

.



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


Re: [R] cbind in a loop...better way? | summary

2014-10-09 Thread Evan Cooch

Thanks!

On 10/9/2014 1:52 PM, David L Carlson wrote:

Actually Jeff Laake's can be made even shorter with

sapply(mat_list, as.vector)

David C

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Evan Cooch
Sent: Thursday, October 9, 2014 7:37 AM
To: Evan Cooch; r-help@r-project.org
Subject: Re: [R] cbind in a loop...better way? | summary

Two solutions proposed -- not entirely orthogonal, but both do the
trick. Instead of nesting cbin in a loop (as I did originally -- OP,
below),

1\   do.call(cbind, lapply(mat_list, as.vector))

or

2\   sapply(mat_list,function(x) as.vector(x))


Both work fine. Thanks to Jeff Laake (2) + David Carlson (1) for their
suggestions.


On 10/8/2014 3:12 PM, Evan Cooch wrote:

...or some such. I'm trying to work up a function wherein the user
passes a list of matrices to the function, which then (1) takes each
matrix, (2) performs an operation to 'vectorize' the matrix (i.e.,
given an (m x n) matrix x, this produces the vector Y of length  m*n
that contains the columns of the matrix x, stacked below each other),
and then (3) cbinds them together.

Here is an example using the case where I know how many matrices I
need to cbind together. For this example, 2 square (3x3) matrices:

  a - matrix(c,0,20,50,0.05,0,0,0,0.1,0),3,3,byrow=T)
  b - matrix(c(0,15,45,0.15,0,0,0,0.2,0),3,3,byrow=T)

I want to vec them, and then cbind them together. So,

result  - cbind(matrix(a,nr=9), matrix(b,nr=9))

which yields the following:

   [,1]  [,2]
  [1,]  0.00  0.00
  [2,]  0.05  0.15
  [3,]  0.00  0.00
  [4,] 20.00 15.00
  [5,]  0.00  0.00
  [6,]  0.10  0.20
  [7,] 50.00 45.00
  [8,]  0.00  0.00
  [9,]  0.00  0.00

Easy enough. But, I want to put it in a function, where the number and
dimensions  of the matrices is not specified. Something like

Using matrices (a) and (b) from above, let

   env - list(a,b).

Now, a function (or attempt at same) to perform the desired operations:

   vec=function(matlist) {

   n_mat=length(matlist);
   size_mat=dim(matlist[[1]])[1];

   result=cbind()

for (i in 1:n_mat) {
  result=cbind(result,matrix(matlist[[i]],nr=size_mat^2))
   }

  return(result)

}


When I run vec(env), I get the *right answer*, but I am wondering if
there is a *better* way to get there from here than the approach I use
(above). I'm not so much interested in 'computational efficiency' as I
am in stability, and flexibility.

Thanks...

.


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



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


[R] cbind in a loop...better way?

2014-10-08 Thread Evan Cooch
...or some such. I'm trying to work up a function wherein the user 
passes a list of matrices to the function, which then (1) takes each 
matrix, (2) performs an operation to 'vectorize' the matrix (i.e., given 
an (m x n) matrix x, this produces the vector Y of length  m*n that 
contains the columns of the matrix x, stacked below each other), and 
then (3) cbinds them together.


Here is an example using the case where I know how many matrices I need 
to cbind together. For this example, 2 square (3x3) matrices:


 a - matrix(c,0,20,50,0.05,0,0,0,0.1,0),3,3,byrow=T)
 b - matrix(c(0,15,45,0.15,0,0,0,0.2,0),3,3,byrow=T)

I want to vec them, and then cbind them together. So,

result  - cbind(matrix(a,nr=9), matrix(b,nr=9))

which yields the following:

  [,1]  [,2]
 [1,]  0.00  0.00
 [2,]  0.05  0.15
 [3,]  0.00  0.00
 [4,] 20.00 15.00
 [5,]  0.00  0.00
 [6,]  0.10  0.20
 [7,] 50.00 45.00
 [8,]  0.00  0.00
 [9,]  0.00  0.00

Easy enough. But, I want to put it in a function, where the number and 
dimensions  of the matrices is not specified. Something like


Using matrices (a) and (b) from above, let

  env - list(a,b).

Now, a function (or attempt at same) to perform the desired operations:

  vec=function(matlist) {

  n_mat=length(matlist);
  size_mat=dim(matlist[[1]])[1];

  result=cbind()

   for (i in 1:n_mat) {
 result=cbind(result,matrix(matlist[[i]],nr=size_mat^2))
  }

 return(result)

   }


When I run vec(env), I get the *right answer*, but I am wondering if 
there is a *better* way to get there from here than the approach I use 
(above). I'm not so much interested in 'computational efficiency' as I 
am in stability, and flexibility.


Thanks...

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


Re: [R] cbind in a loop...better way?

2014-10-08 Thread Evan Cooch
That works as well. I'll collate your response and a couple of others, 
and post tomorrow.

On 10/8/2014 4:17 PM, David L Carlson wrote:
 How about

 do.call(cbind, lapply(env, as.vector))
 [,1]  [,2]
   [1,]  0.00  0.00
   [2,]  0.05  0.15
   [3,]  0.00  0.00
   [4,] 20.00 15.00
   [5,]  0.00  0.00
   [6,]  0.10  0.20
   [7,] 50.00 45.00
   [8,]  0.00  0.00
   [9,]  0.00  0.00

 -
 David L Carlson
 Department of Anthropology
 Texas AM University
 College Station, TX 77840-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Evan Cooch
 Sent: Wednesday, October 8, 2014 2:13 PM
 To: r-help@r-project.org
 Subject: [R] cbind in a loop...better way?

 ...or some such. I'm trying to work up a function wherein the user
 passes a list of matrices to the function, which then (1) takes each
 matrix, (2) performs an operation to 'vectorize' the matrix (i.e., given
 an (m x n) matrix x, this produces the vector Y of length  m*n that
 contains the columns of the matrix x, stacked below each other), and
 then (3) cbinds them together.

 Here is an example using the case where I know how many matrices I need
 to cbind together. For this example, 2 square (3x3) matrices:

a - matrix(c,0,20,50,0.05,0,0,0,0.1,0),3,3,byrow=T)
b - matrix(c(0,15,45,0.15,0,0,0,0.2,0),3,3,byrow=T)

 I want to vec them, and then cbind them together. So,

 result  - cbind(matrix(a,nr=9), matrix(b,nr=9))

 which yields the following:

 [,1]  [,2]
[1,]  0.00  0.00
[2,]  0.05  0.15
[3,]  0.00  0.00
[4,] 20.00 15.00
[5,]  0.00  0.00
[6,]  0.10  0.20
[7,] 50.00 45.00
[8,]  0.00  0.00
[9,]  0.00  0.00

 Easy enough. But, I want to put it in a function, where the number and
 dimensions  of the matrices is not specified. Something like

 Using matrices (a) and (b) from above, let

 env - list(a,b).

 Now, a function (or attempt at same) to perform the desired operations:

 vec=function(matlist) {

 n_mat=length(matlist);
 size_mat=dim(matlist[[1]])[1];

 result=cbind()

  for (i in 1:n_mat) {
result=cbind(result,matrix(matlist[[i]],nr=size_mat^2))
 }

return(result)

  }


 When I run vec(env), I get the *right answer*, but I am wondering if
 there is a *better* way to get there from here than the approach I use
 (above). I'm not so much interested in 'computational efficiency' as I
 am in stability, and flexibility.

 Thanks...

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



[[alternative HTML version deleted]]

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


[R] optim, L-BFGS-B | constrained bounds on parms?

2014-09-19 Thread Evan Cooch
Or, something to that effect. Following is an example of what I'm 
working with basic ABO blood type ML estimation from observed type 
(phenotypic) frequencies. First, I generate a log-likelihood function. 
mu[1] - mu[2] are allele freqs for A and B alleles, respectively. Since 
freq of O allele is redundant, I use 1-mu[1]-mu[2] for that. The terms 
in the function are the probability expressions for the expected values 
of each phenotype.

But, that is somewhat besides the point:

f_abo - function(mu) { 
25*log(mu[1]^2+2*mu[1]*(1-mu[1]-mu[2]))+25*log(mu[2]^2+2*mu[2]*(1-mu[1]-mu[2]))+50*log(2*mu[1]*mu[2])+15*log((1-mu[1]-mu[2])^2)
 
}


So, I want to come up with MLE for mu[1] and mu[2] (for alleleic freqs 
for A and B alleles, respectively. Now, given the data, I know (from 
having maximized this likelihood outside of R) that the MLE for mu[1] is 
0.37176, and for mu[2], the same -- mu[2]=0.371763. I confirm this in 
MATLAB, and Maple, and Mathematica, using various non-linear 
solvers/optimization routines. They all yielded recisely the right answers.

But, stuck trying to come up with a general approach to getting the 
'right estimates' in R, that doesn't rely on strong prior knowledge of 
the parameters. I tried the following - I used L-BFGDS-B' because this 
is a 'boxed' optimzation: mu[1] and mu[2] are both parameters on the 
interval [0,1].

  results - optim(c(0.3,0.3), f_abo,
  method = L-BFGS-B, lower=c(0.1,0.1), upper=c(0.9,0.9),
   hessian = TRUE,control=list(fnscale=-1))

but that through the following error at me:

L-BFGS-B needs finite values of 'fn'

OK, fine. Taking that literally, and thinking a bit, clear that the 
problem is that the upper bound on the parms creates the problem. So, I 
try the crude approach of making the upper bound for each 0.5:


  results - optim(c(0.3,0.3), f_abo,
  method = L-BFGS-B, lower=c(0.1,0.1), upper=c(0.5,0.5),
   hessian = TRUE,control=list(fnscale=-1))


No errors this time, but no estimates either. At all.

OK -- so I 'cheat', and since I know that mu[1]=mu[2]=0.37176, I make 
another change to the upper limit, using 0.4 for both parms:



  results - optim(c(0.3,0.3), f_abo,
  method = L-BFGS-B, lower=c(0.1,0.1), upper=c(0.4,0.4),
   hessian = TRUE,control=list(fnscale=-1))


Works perfectly, and...right estimates too. ;-)

But, I could get there from here because I had prior knowledge of the 
parameter values. In other words, I cheated (not a thinly veiled 
suggestion that prior information is cheating, of course ;-)

What I'm trying to figure out is how to do a constrained optimization 
with R, where mu[1] and mu[2] are estimated subject to the constraint that

0 = mu[1]+mu[2] = 1

There seems to be no obvious way to impose that -- which creates a 
problem for optim since if I set 'vague' bounds on the parms (as per 
original attempt), optim tries combinations (like mu[1]=0.9, mu[2]=0.9), 
which aren't plausible, given the constraint that 0 = mu[1]+mu[2] = 1. 
Further, in this example, mu[1]=mu[2]. That might not be the case, and I 
might need to set upper bound on a parameter to be 0.5. But, without 
knowing which parameter, I'd need to set both from (say) 0.1 - 0.9.

Is this possible with optim, or do I need to use a different package? If 
I can get there from here using optim, what do I need to do, either to 
my call to the optim routine, or the function that I pass to it?

This sort of thing is quite easy in (say) Maple. I simply execute

NLPSolve(f_abo,initialpoint={mu[1]=0.2,mu[2]=0.2},{mu[1]+mu[2]=1},mu[1]=0.1..0.9,mu[2]=0.1..0.9,maximize);

where I'm telling the NLPSolve function that there is a constraint for 
mu[1] and mu[2] (as above), which lets me set bounds on the parameter 
over larger interval. Can I do the same in R?

Again, I'm trying to avoid having to use a 'good guess'. I know I can 
gene count to come up with a quick and dirty starting point (the basis 
for the EM algorithm commonly used for this), but again, I'm trying to 
avoid that.

Thanks very much in advance.

[[alternative HTML version deleted]]

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


Re: [R] optim, L-BFGS-B | constrained bounds on parms?

2014-09-19 Thread Evan Cooch



On 9/19/2014 11:32 AM, Prof J C Nash (U30A) wrote:

One choice is to add a penalty to the objective to enforce the
constraint(s) along with bounds to keep the parameters from going wild.

This generally works reasonably well. Sometimes it helps to run just a
few iterations with a big penalty scale to force the parameters into a
feasible region, though a lot depends on the particular problem in my
experience, with some being straightforward and others needing a lot of
fiddle.

I suspect a math programming approach is overkill, though R does have
some packages for that. Your mileage may vary.

Note that L-BFGS-B used by R is a version for which Nocedal et al.
reported a bug in 2011 and provided a new Fortran code. I've recently
put up an implementation of the new code on r-forge under the optimizer
project. Still testing, but I think it's OK. You could also use Rvmmin
that has bounds, or nmkb from dfoptim (though you cannot start on bounds).

Best, JN



Thanks very much. I've found that for most of my current problems, 
optimx is working well, but there are trade-offs. Good to have multiple 
options in the toolkit.


Cheers...

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


Re: [R] optim, L-BFGS-B | constrained bounds on parms?

2014-09-19 Thread Evan Cooch

 You could also use Rvmmin

that has bounds, or nmkb from dfoptim (though you cannot start on bounds).



One 'negative' for dfoptim is that is doesn't automatically generate the 
Hessian (as far as I can tell). Rather nice to be able to do so for 
other calculations that usual follow after the optimization. optimx has 
a control option for that.


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


Re: [R] help using extrafont package | R graphics

2014-05-01 Thread Evan Cooch
Thanks very much. I'll give it a try.

On 4/30/2014 9:33 PM, Yixuan Qiu wrote:
 Hi Evan,
 If you just need one font, you may try the showtext package. Here is a 
 piece of code that you can test:

 library(showtext)
 # If you have this font installed
 font.add(gara, gara.ttf)
 # Or you can install a similar one from Google Font
 # font.add.google(EB Garamond, gara)

 # Try some plots
 pdf(test.pdf)
 showtext.begin()
 par(family = gara)
 plot(1, main = Garamond, type = n)
 text(1, 1, Some Text, cex = 5)
 showtext.end()
 dev.off()


 A more detailed introduction of the showtext package is available at 
 http://statr.me/2014/01/using-system-fonts-in-r-graphs/. Hope this 
 would be helpful for you.


 Best,
 Yixuan






 2014-04-26 16:54 GMT-04:00 Evan Cooch evan.co...@gmail.com 
 mailto:evan.co...@gmail.com:
  Greetings --
 
  Submitted this a little while ago -- for some reason, still being held
  up by the moderator. Trying again...
 
 
  For a host of reasons, I need to use/embed Garamond font with various R
  graphics for a particular publication. I've figured out how to more or
  less get there from here, using the following sequence:
 
 
  library(extrafont)
 
  Then, I need to import the system fonts (Windoze box, R 3.1.0).
 
  So, I use
 
  font_import()
 
  But, this takes a *huge* amount of time, and often throws errors as it
  chokes on various fonts (I have probably 250+ fonts installed). I only
  want *one* font (Garamond). But, for the life of me, I can't figure out
  how to get font_import to select only the single font I want. In theory
 
  font_import(paths = NULL, recursive = TRUE, prompt = TRUE, pattern = 
 NULL)
 
  as defaults, where pattern is a regex that font filenames must match.
 
  The file name for Garamong is gara.ttf, so I tried
 
  font_import(pattern=gara)
 
  R responds with 'Importing fonts make take a few minutes, depending on
  the...etc, etc'.
  Continue? [y/n]
 
  Hit 'y', and am presented with
 
  Scanning ttf files in C:\Windows\Fonts ...
  Extracting .afm files from .ttf files...
  Error in data.frame(fontfile = ttfiles, FontName = , stringsAsFactors
  = FALSE) :
 arguments imply differing number of rows: 0, 1
 
  I have no idea what to do with this.
 
  Suggestions/pointers to the obvious welcome. And I thought futzing with
  fonts in LaTeX was fun! ;-)
 
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailto:R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



 -- 
 Yixuan Qiu yixuan@cos.name mailto:yixuan@cos.name
 Department of Statistics,
 Purdue University


[[alternative HTML version deleted]]

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


[R] help using extrafont package | R graphics

2014-04-26 Thread Evan Cooch
Greetings --

Submitted this a little while ago -- for some reason, still being held 
up by the moderator. Trying again...


For a host of reasons, I need to use/embed Garamond font with various R 
graphics for a particular publication. I've figured out how to more or 
less get there from here, using the following sequence:


library(extrafont)

Then, I need to import the system fonts (Windoze box, R 3.1.0).

So, I use

font_import()

But, this takes a *huge* amount of time, and often throws errors as it 
chokes on various fonts (I have probably 250+ fonts installed). I only 
want *one* font (Garamond). But, for the life of me, I can't figure out 
how to get font_import to select only the single font I want. In theory

font_import(paths = NULL, recursive = TRUE, prompt = TRUE, pattern = NULL)

as defaults, where pattern is a regex that font filenames must match.

The file name for Garamong is gara.ttf, so I tried

font_import(pattern=gara)

R responds with 'Importing fonts make take a few minutes, depending on 
the...etc, etc'.
Continue? [y/n]

Hit 'y', and am presented with

Scanning ttf files in C:\Windows\Fonts ...
Extracting .afm files from .ttf files...
Error in data.frame(fontfile = ttfiles, FontName = , stringsAsFactors 
= FALSE) :
   arguments imply differing number of rows: 0, 1

I have no idea what to do with this.

Suggestions/pointers to the obvious welcome. And I thought futzing with 
fonts in LaTeX was fun! ;-)


[[alternative HTML version deleted]]

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


[R] extrafont query | importing only 1 TTF

2014-04-25 Thread Evan Cooch
Greetings --

For a host of reasons, I need to use/embed Garamond font with various 
graphics for a particular publication. I've figured out how to more or 
less get there from here, using the following sequence:


library(extrafont)

Then, I need to import the system fonts (Windoze box).

So, I use

font_import()

But, this takes a *huge* amount of time, and often throws errors as it 
chokes n various fonts (I have probably 250+ fonts installed). I only 
want *one* font (Garamond). But, for the life of me, I can't figure out 
how to get font_import to select only the single font I want. In theory

font_import(paths = NULL, recursive = TRUE, prompt = TRUE, pattern = NULL)

as defaults, where pattern is a regex that font filenames must match.

The file name for Garamong is gara.ttf, so I tried

font_import(pattern=gara)

R responds with 'Importing fonts make take a few minutes, depending on 
the...etc, etc'.
Continue? [y/n]

Hit 'y', and am presented with

Scanning ttf files in C:\Windows\Fonts ...
Extracting .afm files from .ttf files...
Error in data.frame(fontfile = ttfiles, FontName = , stringsAsFactors 
= FALSE) :
   arguments imply differing number of rows: 0, 1

I have no idea what to do with this.

Suggestions/pointers to the obvious welcome. And I thought futzing with 
fonts in LaTeX was fun! ;-)



[[alternative HTML version deleted]]

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


Re: [R] R2winBUGS WinBUGS gui

2007-11-25 Thread Evan Cooch


 No. The idea is to use BRugs, i.e. OpenBUGS in such cases. If OpenBUGS 
 lacks some features, you are certainly welcome to implement them and 
 send patches to Andrew Thomas.



Thanks very much. I thought as much, but given that I have had a 0% 
success rate in getting OpenBUGS to run on any GNU/Linux platform, I was 
resigning myself into using winBUGS under wine. I have recently 
installed a different distro on one of my machines - perhaps time to try 
openBUGS again.

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


Re: [R] R2winBUGS WinBUGS gui

2007-11-25 Thread Evan Cooch


 No. The idea is to use BRugs, i.e. OpenBUGS in such cases. If OpenBUGS 
 lacks some features, you are certainly welcome to implement them and 
 send patches to Andrew Thomas.


Just finished trying the install of openBUGS under linux yet again. Same 
problems (more or less), which I'll list here for the benefit (possibly) 
of others who might go this route.

1. connect to

http://www.mathstat.helsinki.fi/openbugs/

Download latest zip of openBUGS

2. unzip it (preserving directory structure) onto Linux machine (in this 
case, running Fedora Core 8 latest flavours of everything, including R).

3. look at the 'docs' for installing under linux. I say 'docs' 
advisedly, since there really isn't much to read - here it is in its 
entirety.

OpenBUGS for both Windows and Linux can be downloaded as a .zip file 
from here http://www.mathstat.helsinki.fi/openbugs/OpenBUGS.zip. The 
source code comes with the installation: check the readme notes to see 
how to compile the code. you will need to install Black Box 
http://www.oberon.ch/blackbox.html as well.


  Old Installation Instructions for LinBUGS (which may or may not
  still work):

   1. Un-zip the .zip file into the folder of your choice.
   2. Change the permissions for the LINBUGS and CBugs files (e.g. with
  chmod 755 LinBUGS CBugs)
   3. Change the temp directory in LINBUGS to the current directory (at
  the moment it is /home/ant/temp). Use the full path name (can
  anyone suggest a less ugly way of doing this? We don't want to put
  the temp directory in OpenBUGS/).
   4. Start LinBUGS with the command LINBUGS.


(the admonition that it may or may not work is not inspiring). Confirmed 
at step (2), where you're supposed to change permissions on 2 files 
which, in fact, are *not* distributed in the openBUGS.zip file. This 
makes it rather tough to install. ;-)


I dug around, and found some folks have hacked together a LINGUS script 
- one version I found fairly commonly looks like:

#!/bin/bash

export LD_ASSUME_KERNEL=2.4.1 

DIR=$(dirname $0)
cd $DIR
if [ \! -e $DIR/temp ] ; then
mkdir $DIR/temp
fi

if [ -e bugs.so ] ; then
./cbugs $DIR $DIR/temp /bugs.so 
else
./cbugs $DIR $DIR/temp /brugs.so 


Fine, except for line two, which doesn't work with newer distros.

And, apparently (based on a bunch of websites I just looked at), BRugs 
doesn't work under Linux, not unless you want to install the Blackbox 
compiler (is there one for Linux?), and recompile. Not me (not today, 
anyway...).

So, unless I (and a lot of folks who seem to be running into the same 
issues), my preliminary conclusion is that neither openBUGS nor BRugs 
are ready for prime time on a Linux platform. Which seems a shame, given 
how many people using MCMC etc. use Linux as their primary platform.

Guess I'll have another look at JAGS.

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


Re: [R] R2winBUGS WinBUGS gui

2007-11-25 Thread Evan Cooch


 Yes, sure, and indeed, it is a shame that nobody of those people who 
 want it to work under Linux is trying to submit patches to make it work.



I agree, but I *think* the primary reason for this is that it requires 
installing Blackbox as a PASCAL compiler. For much of the Linux 
community, if it doesn't make use of a standard GNU compiler (there *is* 
a GNU Pascal compiler, but since I (and most others) don't know PASCAL, 
I've never installed it), there will be little interest. Of course, what 
seems attractive about JAGS is that it is less dependent on a non-GNU 
compiler (although the dependencies to Blackbox may not be large - 
relative to GNU Pascal - don't know), and is written in a more familiar 
language.

What everyone wants is a tarball with a simple configure, make, make 
install sequence, that plays nice with R, under linux, which is the OS 
of choice (based on the statistics I have) for folks with high-end 
hardware (read - multi-processor 64-bit chips with a 64-bit OS). Of 
course, this doesn't happen by itself (your point is well-taken).

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


[R] R2winBUGS | option to turn off GUI?

2007-11-24 Thread Evan Cooch
Greetings -

I run a multi-pro server box (GNU/Linux), on which I've installed 
winBUGS under wine. Works fine, and plays nice with r2WinBUGS, provided 
everything is done through a graphical front-end (either by working from 
console, or using a virtual desktop via VNC or equivalent).

However, I'm wondering if there is a way to use R2winBUGS and winBUGS 
such that winBUGS does not spawn any windows - in other words, have R 
and R2winBUGS access the winBUGS 'engine', dump everything to coda 
files, but not generate any windows? I ask because a number of my more 
'remote' users have trouble running a graphical interface to the 
machine. Rather, they'd like to ssh into a shell, run a R script calling 
R2WinBUGS, then sign off. At present, this doesn't work 'cleanly' 
because winBUGS keeps trying to open up a window or two. Which, needless 
to say, doesn't work if you're running things in an ASCII shell from the 
command line.

We've looked at the R2winBUGS docs, and found nothing there (or on 
various drills through what we could find on the web) for how to do this 
- if it is at all possible.

Possible? If so, we'd be delighted to be enlightened on how! ;-)

Thanks very much in advance...

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


[R] R2winBUGS WinBUGS gui

2007-11-23 Thread Evan Cooch
I am trying to figure out if it is possible to run winBUGS from within 
R, using R2winBUGS, without having winBUGS spawn any windows (basically 
- 'true' batch - no GUI actions at all). The reason being I have a 
machine which I (and several others) ssh/telnet into, and would like to 
run winBUGS without having to mount a virtual desktop of any kind.

I've looked through the r2winBUGS docs, and there doesn't seem to be any 
command(s) which I can invoke to simply use the winBUGS 'engine', and 
not the winBUGS windows.

Yes, I know I could look at classic BUGS, or openBUGS, but neither work 
particularly well for my purposes (since the code I'm using makes use of 
a numb4er of winBUGS 'extensions' which aren't supported in other 
flavours of BUGS).

Is this possible in any fashion?

Thanks in advance...

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


Re: [R] really dumb question | loop counters in

2007-09-21 Thread Evan Cooch
Thanks. And thanks for the C-style tip.

Greg Snow wrote:
 Try:

 for(x in seq(0,1,by=0.01)) {
 print(x)
 }

 The for loop in S/R is what some languages call a foreach loop, you need
 to provide a vector of the values to loop over.

 If you really want a C style for loop, then just realize that the for
 loop is a shorthand while loop:

 x - 0
 while( x  1 ) {
   print(x)
   x - x + 0.01
 }

 Hope this helps,




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