Re: [R] Extracting rows of a data.frame by "identical"

2016-05-02 Thread Ulrik Stervbo
Can you use subset?

subset(d, b == 4 & c == 10)

Best
Ulrik

On Tue, 3 May 2016 04:58 jpm miao,  wrote:

> Is it possible? I am expecting the result to be the second row of the data
> frame ...
>
>
> d<-data.frame(a=1:3, b=3:5,c=9:11)
> > d
>   a b  c
> 1 1 3  9
> 2 2 4 10
> 3 3 5 11
> > d[identical(d[c("b","c")],c(4,10)),]
> [1] a b c
> <0 rows> (or 0-length row.names)
>
> [[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] Use "append" in the function write.xlsx2 or write.xlsx (openxlsx package)

2016-05-02 Thread jpm miao
Hi,

   I am trying to print several dataset in several different sheets of the
same xlsx file.
I sometimes run the codes more than once, and I need to erase all things in
the target file, and I do not use "append" in the first function call.
However I want to write it in a loop. Is there a way to initiate a blank
xlsx file so that I can use "append = TRUE" whenever I call the function
write.xlsx2?

output_file2<-"data_xx.xlsx"
write.xlsx2(x= df_all2[["a"]], file = output_file2, sheetName = "a")
write.xlsx2(x= df_all2[["b"]], file = output_file2, sheetName = "b",
append=TRUE)
write.xlsx2(x= df_all2[["c"]], file = output_file2, sheetName = "c",
append= TRUE)

[[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] Extracting rows of a data.frame by "identical"

2016-05-02 Thread jpm miao
Is it possible? I am expecting the result to be the second row of the data
frame ...


d<-data.frame(a=1:3, b=3:5,c=9:11)
> d
  a b  c
1 1 3  9
2 2 4 10
3 3 5 11
> d[identical(d[c("b","c")],c(4,10)),]
[1] a b c
<0 rows> (or 0-length row.names)

[[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-es] Script sin resultados (SOLUCIONADO)

2016-05-02 Thread Manuel Máquez
Carlos:
Muchísimas gracias nuevamente, en mi anterior había dicho que te
comentaría, y, ahora lo hago.
Quería 'comerme el pastel con una mordida', era necesario tomar un vector y
'exprimirlo' quedando finalmente así:
library(ggplot2)
ogl <- read.csv('T06.csv')
re <- ogl[ogl[,3] <= 9,]# Gracias por tu post *Carlos*
qu <- ogl[ogl[,3] >= 10,]
sua <- loess(d ~ n, data = re, span = 0.65, degree = 2)
idx <- predict(sua)
sv <- loess(d ~ n, data = qu, span = 0.65, degree = 2)
ix <- predict(sv)
ogl$det <-ifelse(ogl$d >= 10, 'Myr', 'Nor')
gr <- ggplot(data = ogl, aes(x = n, y = d, col = det)) +
geom_point(aes(shape = det))+
geom_smooth(span = 0.65) +
scale_colour_manual(values = c('red', 'blue')) +
theme(legend.position = c(0.17, 0.85)) +
ggtitle('Norm, c/y>=10; Curvas Sep e Iterv d Conf [06]')
print (gr)
  # tail(idx,20)  ix también
  # sink( ? ?.txt) para sacar valores de idx e ix

Bueno pues, gracias y buenos días.
Atentamente;

*MANOLO MÁRQUEZ P.*

[[alternative HTML version deleted]]

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


Re: [R] Create a new variable and concatenation inside a "for" loop

2016-05-02 Thread Rolf Turner



You are quite wrong.  This is not "nonsense"; it is sound advice.  It is 
true that R is capable of distinguishing between a function and a 
non-function object with the same name.  However there are many 
circumstances in which using a function's name for the name of a data 
object will lead to errors in function calls and the resulting error 
messages will be difficult to interpret.  (Things like "object of type 
'builtin' is not subsettable".)


Indulging in using "c" (e.g.) for the name of a data object is bad 
practice and mental laziness.


I would suggest that you restrain your presumptuousness and arrogance, 
and refrain from telling experienced and wise R gurus, like Jeff 
Newmiller, that their ideas are "nonsense" until you have a little more 
experience with and knowledge of R.


I am sure that you will insist on arguing about this and that you will 
continue to claim that black is white, but the fact remains that you are 
wrong.  Others should pay no attention to your ranting.


cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

On 03/05/16 10:00, Raubertas, Richard wrote:

What nonsense. There is a group of finger-waggers on this list who
jump on every poster who uses the name of an R function as a variable
name. R is perfectly capable of distinguishing the two, so if 'c' (or
'data' or 'df', etc.) is the natural name for a variable then go ahead
and use it. Mr. Newmiller provides an excellent example of this: he
recommends 'C' instead of 'c', apparently without realizing that 'C' is
also a built-in R function--because there is "no such problem".

Richard Raubertas

-Original Message- From: R-help
[mailto:r-help-boun...@r-project.org] On Behalf Of JeffNewmiller
Sent: Wednesday, April 27, 2016 3:58 PM To: Gordon, Fabiana;
'r-help@R-project.org' Subject: Re: [R] Create a new variable and
concatenation inside a  "for" loop
"c" an extremely commonly-used function. Functions are first-class
objects that occupy the same namespaces that variables do, so they can
obscure each other. In short, don't use variables called "c" (R is case
sensitive, so "C" has no such problem).

Wherever possible, avoid incremental concatenation like the plague.
If  you feel you must use it, at least concatenate in lists and then use
functions like unlist, do.call, or pre-allocate vectors or matrix-like
objects with unuseful values like NA and then overwrite each element in
the vector or matrix-type object in a loop like your first one.


__
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] Create a new variable and concatenation inside a "for" loop

2016-05-02 Thread Tom Wright
As pointed out somewhere in the replies to this you can always use the
exists() function.
for(i in 1:5){
if(exists(output)){
output <- c(output, i )
}else{
   output <- i
   }
}

On Wed, Apr 27, 2016, 11:15 AM Gordon, Fabiana <
fabiana.gor...@imperial.ac.uk> wrote:

> Hello,
>
> Suppose the you need a loop to create a new variable , i.e., you are not
> reading data from outside the loop. This is a simple example in Matlab code,
>
> for i=1:5
> r1=randn
> r2=randn
> r=[r1 r2]
> c(i,:)=r;   % creation of each row of c , % the ":" symbol indicates all
> columns. In R this would be [i,]
> end
>
> The output of interest is c which I'm creating inside the "for" loop -also
> the index used in the loop is used to create c. In R I had to create c as
> an  empty vector (numeric() ) outside the loop, otherwise I get an error
> message saying that c doesn't exit.
>
> The other issue is the concatenation. In each iteration I'm creating the
> rows of c by placing the new row  (r) below the previous one so that c
> becomes a 5 x 2 matrix.
> In R, it seems that I have no choice but use the function "rbind". I
> managed to write this code in R . However, I'm not sure that if instead of
> creating a new variable  using  the index in the "for" loop , I wanted to
> use the index to read data, e.g.  suppose I have a 2 X 10 matrix X and
> suppose I want to calculate the sin () for each 2 x 2 sub-matrix of and
> stored in a matrix A. Then the code would be something like this,
>
> for i=1:5
> A(:, 2*i-1:2*i)= sin(X(:, 2*i-1:2*i))   % the ":" symbol indicates all rows
> end
>
> Many Thanks,
>
> Fabiana
>
>
> Dr Fabiana Gordon
>
> Senior Statistical Consultant
> Statistical Advisory Service, School Of Public Health,
> Imperial College London
> 1st Floor, Stadium House, 68 Wood Lane,
> London W12 7RH.
>
> Tel: 020 7594 1749
> Email: fabiana.gor...@imperial.ac.uk
> Web:
> www.imperial.ac.uk/research-and-innovation/support-for-staff/stats-advice-service/
> <
> http://www.imperial.ac.uk/research-and-innovation/support-for-staff/stats-advice-service/
> >
>
>
>
> [[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.


Re: [R] Create a new variable and concatenation inside a "for" loop

2016-05-02 Thread Raubertas, Richard
What nonsense.  There is a group of finger-waggers on this list who jump on 
every poster who uses the name of an R function as a variable name.  R is 
perfectly capable of distinguishing the two, so if 'c' (or 'data' or 'df', 
etc.) is the natural name for a variable then go ahead and use it.  Mr. 
Newmiller provides an excellent example of this:  he recommends 'C' instead of 
'c', apparently without realizing that 'C' is also a built-in R 
function--because there is "no such problem".

Richard Raubertas

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Newmiller
Sent: Wednesday, April 27, 2016 3:58 PM
To: Gordon, Fabiana; 'r-help@R-project.org'
Subject: Re: [R] Create a new variable and concatenation inside a "for" loop

"c" an extremely commonly-used function. Functions are first-class objects that 
occupy the same namespaces that variables do, so they can obscure each other. 
In short, don't use variables called "c" (R is case sensitive, so "C" has no 
such problem).

Wherever possible, avoid incremental concatenation like the plague. If you feel 
you must use it, at least concatenate in lists and then use functions like 
unlist, do.call, or pre-allocate vectors or matrix-like objects with unuseful 
values like NA and then overwrite each element in the vector or matrix-type 
object in a loop like your first one. 
-- 
Sent from my phone. Please excuse my brevity.

On April 27, 2016 3:25:14 PM GMT+01:00, "Gordon, Fabiana" 
 wrote:
>Hello,
>
>Suppose the you need a loop to create a new variable , i.e., you are
>not reading data from outside the loop. This is a simple example in
>Matlab code,
>
>for i=1:5
>r1=randn
>r2=randn
>r=[r1 r2]
>c(i,:)=r;   % creation of each row of c , % the ":" symbol indicates
>all columns. In R this would be [i,]
>end
>
>The output of interest is c which I'm creating inside the "for" loop
>-also the index used in the loop is used to create c. In R I had to
>create c as an  empty vector (numeric() ) outside the loop, otherwise I
>get an error message saying that c doesn't exit.
>
>The other issue is the concatenation. In each iteration I'm creating
>the rows of c by placing the new row  (r) below the previous one so
>that c becomes a 5 x 2 matrix.
>In R, it seems that I have no choice but use the function "rbind". I
>managed to write this code in R . However, I'm not sure that if instead
>of creating a new variable  using  the index in the "for" loop , I
>wanted to use the index to read data, e.g.  suppose I have a 2 X 10
>matrix X and suppose I want to calculate the sin () for each 2 x 2
>sub-matrix of and stored in a matrix A. Then the code would be
>something like this,
>
>for i=1:5
>A(:, 2*i-1:2*i)= sin(X(:, 2*i-1:2*i))   % the ":" symbol indicates all
>rows
>end
>
>Many Thanks,
>
>Fabiana
>
>
>Dr Fabiana Gordon
>
>Senior Statistical Consultant
>Statistical Advisory Service, School Of Public Health,
>Imperial College London
>1st Floor, Stadium House, 68 Wood Lane,
>London W12 7RH.
>
>Tel: 020 7594 1749
>Email:
>fabiana.gor...@imperial.ac.uk
>Web: 
>www.imperial.ac.uk/research-and-innovation/support-for-staff/stats-advice-service/
>
>
>
>   [[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.
Notice:  This e-mail message, together with any attachme...{{dropped:11}}

__
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] Accessing terminal datasets in Ctree()

2016-05-02 Thread Achim Zeileis

On Mon, 2 May 2016, Preetam Pal wrote:


Great, thank you so much Achim.But one issue, in case I do not know how many
terminal nodes would be there, what do I do? Note that I do not need the
datasets corresponding to the intermediate nodes only need the terminal
datasets.


With predict(ct, type = "node") you can set up a new variable, e.g.,

iris$node <- factor(predict(ct, type = "node"))

and then use this to obtain the subset corresponding to each of the 
terminal nodes.



Regards,
Preetam 

On Tue, May 3, 2016 at 3:08 AM, Achim Zeileis 
wrote:
  On Mon, 2 May 2016, Preetam Pal wrote:

Hi guys,

If I am applying ctree() on a data (specifying some
control parameters like
maxdepth), is there a way I can programmatically
access the (smaller)
datasets corresponding to the terminal nodes in the
tree? Say, if there are
7 terminal nodes, I need those 7 datasets (of
course, I can look at the
respective node-splitting attributes and write out a
filtering function -
but clearly too much to ask for if I have a large
number of terminal
nodes). Intention is to perform regression on each
of these terminal
datasets.


  If you use the "partykit" implementation you can do:

  library("partykit")
  ct <- ctree(Species ~ ., data = iris)
  data_party(ct, id = 6)

  to obtain the data associated with node 6 for example. You can
  also use ct[6] to obtain the subtree and ct[6]$data for its
  associated data.

  For setting up a factor with the terminal node IDs, you can also
  use predict(ct, type = "node") and then use that in lm() etc.

  Finally, note that there is also lmtree() and glmtree() for
  trees with (generalized) linear models in their nodes.

Regards,
Preetam

--
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year,                                   
         Room No. N-114
Statistics Division,                               
           C.V.Raman
Hall
Indian Statistical Institute,                       
         B.H.O.S.
Kolkata.

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




--
Preetam Pal                                                  
(+91)-9432212774
M-Stat 2nd Year,                                             Room No. N-114
Statistics Division,                                           C.V.Raman
HallIndian Statistical Institute,                                 B.H.O.S.
Kolkata.



__
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] Accessing terminal datasets in Ctree()

2016-05-02 Thread Preetam Pal
Again, really appreciate your help on this. Thanks, Achim.
-Preetam

On Tue, May 3, 2016 at 3:22 AM, Achim Zeileis 
wrote:

> On Mon, 2 May 2016, Preetam Pal wrote:
>
> Great, thank you so much Achim.But one issue, in case I do not know how
>> many
>> terminal nodes would be there, what do I do? Note that I do not need the
>> datasets corresponding to the intermediate nodes only need the terminal
>> datasets.
>>
>
> With predict(ct, type = "node") you can set up a new variable, e.g.,
>
> iris$node <- factor(predict(ct, type = "node"))
>
> and then use this to obtain the subset corresponding to each of the
> terminal nodes.
>
>
> Regards,
>> Preetam
>>
>> On Tue, May 3, 2016 at 3:08 AM, Achim Zeileis 
>> wrote:
>>   On Mon, 2 May 2016, Preetam Pal wrote:
>>
>> Hi guys,
>>
>> If I am applying ctree() on a data (specifying some
>> control parameters like
>> maxdepth), is there a way I can programmatically
>> access the (smaller)
>> datasets corresponding to the terminal nodes in the
>> tree? Say, if there are
>> 7 terminal nodes, I need those 7 datasets (of
>> course, I can look at the
>> respective node-splitting attributes and write out a
>> filtering function -
>> but clearly too much to ask for if I have a large
>> number of terminal
>> nodes). Intention is to perform regression on each
>> of these terminal
>> datasets.
>>
>>
>>   If you use the "partykit" implementation you can do:
>>
>>   library("partykit")
>>   ct <- ctree(Species ~ ., data = iris)
>>   data_party(ct, id = 6)
>>
>>   to obtain the data associated with node 6 for example. You can
>>   also use ct[6] to obtain the subtree and ct[6]$data for its
>>   associated data.
>>
>>   For setting up a factor with the terminal node IDs, you can also
>>   use predict(ct, type = "node") and then use that in lm() etc.
>>
>>   Finally, note that there is also lmtree() and glmtree() for
>>   trees with (generalized) linear models in their nodes.
>>
>> Regards,
>> Preetam
>>
>> --
>> Preetam Pal
>> (+91)-9432212774
>> M-Stat 2nd Year,
>>  Room No. N-114
>> Statistics Division,
>>C.V.Raman
>> Hall
>> Indian Statistical Institute,
>>  B.H.O.S.
>> Kolkata.
>>
>> [[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.
>>
>>
>>
>>
>> --
>> Preetam Pal
>> (+91)-9432212774
>> M-Stat 2nd Year, Room No.
>> N-114
>> Statistics Division,   C.V.Raman
>> HallIndian Statistical Institute, B.H.O.S.
>> Kolkata.
>>
>>


-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[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] Accessing terminal datasets in Ctree()

2016-05-02 Thread Preetam Pal
Great, thank you so much Achim.
But one issue, in case I do not know how many terminal nodes would be
there, what do I do? Note that I do not need the datasets corresponding to
the intermediate nodes only need the terminal datasets.
Regards,
Preetam

On Tue, May 3, 2016 at 3:08 AM, Achim Zeileis 
wrote:

> On Mon, 2 May 2016, Preetam Pal wrote:
>
> Hi guys,
>>
>> If I am applying ctree() on a data (specifying some control parameters
>> like
>> maxdepth), is there a way I can programmatically access the (smaller)
>> datasets corresponding to the terminal nodes in the tree? Say, if there
>> are
>> 7 terminal nodes, I need those 7 datasets (of course, I can look at the
>> respective node-splitting attributes and write out a filtering function -
>> but clearly too much to ask for if I have a large number of terminal
>> nodes). Intention is to perform regression on each of these terminal
>> datasets.
>>
>
> If you use the "partykit" implementation you can do:
>
> library("partykit")
> ct <- ctree(Species ~ ., data = iris)
> data_party(ct, id = 6)
>
> to obtain the data associated with node 6 for example. You can also use
> ct[6] to obtain the subtree and ct[6]$data for its associated data.
>
> For setting up a factor with the terminal node IDs, you can also use
> predict(ct, type = "node") and then use that in lm() etc.
>
> Finally, note that there is also lmtree() and glmtree() for trees with
> (generalized) linear models in their nodes.
>
> Regards,
>> Preetam
>>
>> --
>> Preetam Pal
>> (+91)-9432212774
>> M-Stat 2nd Year, Room No.
>> N-114
>> Statistics Division,   C.V.Raman
>> Hall
>> Indian Statistical Institute, B.H.O.S.
>> Kolkata.
>>
>> [[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.
>>
>>


-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[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] Accessing terminal datasets in Ctree()

2016-05-02 Thread Achim Zeileis

On Mon, 2 May 2016, Preetam Pal wrote:


Hi guys,

If I am applying ctree() on a data (specifying some control parameters like
maxdepth), is there a way I can programmatically access the (smaller)
datasets corresponding to the terminal nodes in the tree? Say, if there are
7 terminal nodes, I need those 7 datasets (of course, I can look at the
respective node-splitting attributes and write out a filtering function -
but clearly too much to ask for if I have a large number of terminal
nodes). Intention is to perform regression on each of these terminal
datasets.


If you use the "partykit" implementation you can do:

library("partykit")
ct <- ctree(Species ~ ., data = iris)
data_party(ct, id = 6)

to obtain the data associated with node 6 for example. You can also use 
ct[6] to obtain the subtree and ct[6]$data for its associated data.


For setting up a factor with the terminal node IDs, you can also use 
predict(ct, type = "node") and then use that in lm() etc.


Finally, note that there is also lmtree() and glmtree() for trees with 
(generalized) linear models in their nodes.



Regards,
Preetam

--
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[alternative HTML version deleted]]

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



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


[R] Accessing terminal datasets in Ctree()

2016-05-02 Thread Preetam Pal
Hi guys,

If I am applying ctree() on a data (specifying some control parameters like
maxdepth), is there a way I can programmatically access the (smaller)
datasets corresponding to the terminal nodes in the tree? Say, if there are
7 terminal nodes, I need those 7 datasets (of course, I can look at the
respective node-splitting attributes and write out a filtering function -
but clearly too much to ask for if I have a large number of terminal
nodes). Intention is to perform regression on each of these terminal
datasets.

Regards,
Preetam

-- 
Preetam Pal
(+91)-9432212774
M-Stat 2nd Year, Room No. N-114
Statistics Division,   C.V.Raman
Hall
Indian Statistical Institute, B.H.O.S.
Kolkata.

[[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] greek characters in Figures

2016-05-02 Thread David Winsemius

> On May 2, 2016, at 10:32 AM, Alaios via R-help  wrote:
> 
> Dear all,I am trying to write in my Figure labels short equations that 
> contain greek characters
> 
> For example:  C(h) = sigma^2 * rho(h).   
> 
> I am googling it and there are many packages available but unfortunately they 
> do not look available for my 3.2.4 latex version
> 
> install.packages("latex2expr")

My efforts found a 'latex2exp' but no 'latex2expr'. Are you sure you are not 
missplelling the package name?


> Installiere Paket nach ‘/home/apa/R/x86_64-pc-linux-gnu-library/3.2’(da ‘lib’ 
> nicht spezifiziert)Warnung: kann nicht auf den Index für das Repository 
> https://cran.cnr.Berkeley.edu/src/contrib zugreifen:  nicht unterstütztes URL 
> SchemaWarnmeldung:Paket ‘latex2expr’ ist nicht verfügbar (for R version 3.2.4 
> Revised) 
> 
> Any ideas what else I can try?I would like to thank you in advance for your 
> replyRegardsAlex
>   [[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.

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] how to use AND in grepl

2016-05-02 Thread Tom Wright
Please try to read my earlier comments.
In the absence of a proper example with expected output I think what you
are trying to achieve is:

# create a sample dataframe
df <- data.frame(Command=c("_localize_PD", "_localize_tre_t2",
"_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))

# identify which rows in the dataframe set match the patterns
# note, the vectors PD, T2 and PDT2 are booleans indicating if a match was
made
PD <- grepl("pd", df$Command)
T2 <- grepl('t2', df$Command)
PDT2 <- grepl("(.*t2.*pd.*)|(.*pd.*t2.*)", df$Command)

# create the new column to hold the new names
df$new_name <- NA

df[PD,'new_name'] <- 'pd'
df[T2,'new_name'] <- 't2'
df[PDT2,'new_name'] <- 'pdt2'


# note 1: the order of these command is important, if the last command is
run first all matches will be overwritten by the single matches for 't2'
and 'pd'.
# note 2: There is no match for row 1 as "PD" != "pd", as suggested by John
McKown the ignore.case parameter for grepl can be used to change this
behaviour.

On Mon, May 2, 2016 at 11:01 AM,  wrote:

> I just changed all the names in Command to lowercase, then this
> str_extract works fine for "pd" and "t2", but not for "PDT2". Do you have
> any idea how I can bring PDT2  also in str_extract?
>
>
> On Monday, May 2, 2016 9:16 AM, Tom Wright  wrote:
>
>
>
> The first thing I notice here is that your first two subset statements are
> searching in an object named Command, not the column df$Command. I'm not at
> all sure what you are trying to achieve with the str_extract process but it
> is looking for the exact string 'PDT2' the vectors / dataframe formed in
> your previous commands are not being used at all.
> Moving forward I think you need to pay attention to case "PD" != "pd".
> Also the set PDT2 is going to be a subset of both  sets PD and t2, I don't
> think this is what you are after.
>
> On Mon, May 2, 2016, 8:49 AM   wrote:
>
> Yes it works, but let me explain what I am going to do. I extract all the
> names I want and then create a new column out of them for my plot. This is
> he whole thing I do:
> >  PD=subset(df,grepl("pd",Command)) //extract names in Command with only
> "pd"
> >  t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
> >  PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract
> names which contain both "pd" and "t2"
> >  v1=c('PD','t2','PDT2')// I create a vector with these conditions
> >  str_extract(df$Command,paste(v1,collaps='|')) //returning patterns,
> using stringr library
> >
> >here I see no pattern named PDT2 but there are only PD and t2 patterns.
> >On Monday, May 2, 2016 8:18 AM, Tom Wright  wrote:
> >
> >
> >
> >Sorry for the missed braces earlier. I was typing on a phone, not the
> best place to conjugate regular expressions.
> >Using the example you provided:
> >
> >> df=data.frame(Command=c("_localize_PD", "_localize_tre_t2",
> "_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))
> >
> >> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
> >[1] FALSE FALSE FALSE FALSE  TRUE
> >
> >> subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
> >  Command
> >5 pd_local_abdomen_t2
> >
> >
> >
> >On Mon, May 2, 2016 at 7:42 AM,  wrote:
> >
> >Thanks Peter, you were right, the exact grepl is
> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change
> anything in Command, when I check the size of it by
> sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I
> am sure that the size is not 0. It seems that this AND does not work.
> >>
> >>
> >>
> >>On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
> >>
> >>On 02 May 2016, at 12:43 , ch.elahe via R-help 
> wrote:
> >>
> >>> Thanks for your reply tom. After using
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error:
> Argument "x" is missing, with no default. Actually I don't know how to fix
> this. Do you have any idea?
> >>
> >>Tom's code was missing a ")" but not where you put one. He probably also
> didn't intend to capitalize "subset".
> >>
> >>
> >>-pd
> >>
> >>> Thanks,
> >>> Elahe
> >>>
> >>>
> >>> On Saturday, April 30, 2016 7:35 PM, Tom Wright 
> wrote:
> >>>
> >>>
> >>>
> >>> Actually not sure my previous answer does what you wanted. Using your
> approach:
> >>> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> >>> Should work.
> >>> I think the regex pattern you are looking for is:
> >>> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> >>>
> >>> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> >>>
> >>> subset(df,grepl("t2|pd",x$Command))
> 
> 
> 
> 
>  On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help <
> r-help@r-project.org> wrote:
> 
>  Hi all,
> >
> > I have one factor variable in my df and I want 

Re: [R] Generating 3Dplot in lattice package

2016-05-02 Thread William Dunlap via R-help
For starters, use 'pmin' (parallel min) instead of 'min'.

substitute(MIN(psi/K14,EXP(((ABS(H14)/peak)^omega)*LN(psi/K14))),
 list(MIN=quote(pmin), K14=quote(VaR), ABS=quote(abs),
  EXP=quote(exp), LN=quote(log), H14=quote(Bmax),
  omega=quote(w2)))
# pmin(psi/VaR, exp(((abs(Bmax)/peak)^w2) * log(psi/VaR)))


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, May 2, 2016 at 11:31 AM, T.Riedle  wrote:

> Dear R users,
>
> I am trying to generate a 3D plot using the wireframe() function in the
> lattice package.
>
> The corresponding formula in Excel looks as follows and is applied to the
> wireframe() function:
>
> MIN(psi/K14,EXP(((ABS(H14)/peak)^omega)*LN(psi/K14)))
>
> I tried to "translate" this formula in R and the code looks as follows
>
>
> min(psi/VaR,exp(((abs(B)/Bmax)^w2)*log((psi/VaR),2.718182)))
>
>
>
> In this case I get only one value which is NAN but I should get a time
> series with 13000 values. Hence, I deleted the min() function and tried the
> wireframe() function:
>
>
>
> wireframe(inflator~exp((abs(B)/Bmax)^w2)*log((psi/VaR),base=2.718182),data=data_3Dplot)
>
> However, it doesn't work as the formula for the inflator is incorrect. It
> produces NANs although it shouldn't do that and actually doesn't do that in
> Excel. Furthermore, the results are totally different to those calculated
> by Excel.
>
> Can anyone help me with the formula and translate it correctly in terms of
> R? How do I get the time series? How do I get the values I get in Excel?
>
> I have attached the data as csv file to this email.
>
> Thank you very much for your help.
>
> __
> 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] Can't rename a data frame column

2016-05-02 Thread Thierry Onkelinx
Or you dplyr

library(dplyr)
d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9)
mm <- "beta"
rename_(d, "two" = mm, "three" = "gamma")


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-05-02 19:49 GMT+02:00 Boris Steipe :

> You need to learn about proper subsetting, and the names() function.
> Consider the following:
>
> R > d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9)
> R > d
>   alpha beta gamma
> 1 14 7
> 2 25 8
> 3 36 9
> R > names(d)
> [1] "alpha" "beta"  "gamma"
> R > names(d) == "beta"
> [1] FALSE  TRUE FALSE
> R > names(d)[names(d) == "beta"] <- "two"
> R > d
>   alpha two gamma
> 1 1   4 7
> 2 2   5 8
> 3 3   6 9
>
> R > names(d)[3] <- "three"
> R > d
>   alpha two three
> 1 1   4 7
> 2 2   5 8
> 3 3   6 9
>
>
>
> B.
> (I can't even ...)
>
>
>
>
> On May 2, 2016, at 1:27 PM, jpm miao  wrote:
>
> > Hi,
> >
> >   Could someone suggest a way to rename a data frame column? For example,
> > I want to rename the column beta, but I can't do it this way
> >
> >> d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9)
> >> mm<-"beta"
> >> rename(d, c(mm="two", "gamma"="three"))
> > The following `from` values were not present in `x`: mm
> >  alpha beta three
> > 1 14 7
> > 2 25 8
> > 3 36 9
> >
> > 
> > Of course this would work
> >
> >> rename(d, c("beta"="two", "gamma"="three"))
> >  alpha two three
> > 1 1   4 7
> > 2 2   5 8
> > 3 3   6 9
> >
> >   [[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.
>

[[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] Backtesting VaR using rugarch package

2016-05-02 Thread T.Riedle
Dear R users,
I am trying to backtest VaR using the rugarch package. My code looks as follows

VaRTest(alpha=0.025,Backtesting_BuVaR$Log.return,Backtesting_BuVaR$VaR,conf.level
 = 0.975)

R returns following output. I don't understand why I get NAs except for the 
critical values.
Does anyone have an idea what I am doing wrong and why R returns only NAs? The 
corresponding data are in the csv file.

Many thanks for your support.

$expected.exceed
[1] 117

$actual.exceed
[1] NA

$uc.H0
[1] "Correct Exceedances"

$uc.LRstat
[1] NA

$uc.critical
[1] 5.023886

$uc.LRp
[1] NA

$uc.Decision
[1] NA

$cc.H0
[1] "Correct Exceedances & Independent"

$cc.LRstat
[1] NA

$cc.critical
[1] 7.377759

$cc.LRp
[1] NA

$cc.Decision
[1] NA

Warning message:
In Ops.factor(actual, VaR) : '<' not meaningful for factors



__
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] Generating 3Dplot in lattice package

2016-05-02 Thread T.Riedle
Dear R users,

I am trying to generate a 3D plot using the wireframe() function in the lattice 
package.

The corresponding formula in Excel looks as follows and is applied to the 
wireframe() function:

MIN(psi/K14,EXP(((ABS(H14)/peak)^omega)*LN(psi/K14)))

I tried to "translate" this formula in R and the code looks as follows


min(psi/VaR,exp(((abs(B)/Bmax)^w2)*log((psi/VaR),2.718182)))



In this case I get only one value which is NAN but I should get a time series 
with 13000 values. Hence, I deleted the min() function and tried the 
wireframe() function:


wireframe(inflator~exp((abs(B)/Bmax)^w2)*log((psi/VaR),base=2.718182),data=data_3Dplot)

However, it doesn't work as the formula for the inflator is incorrect. It 
produces NANs although it shouldn't do that and actually doesn't do that in 
Excel. Furthermore, the results are totally different to those calculated by 
Excel.

Can anyone help me with the formula and translate it correctly in terms of R? 
How do I get the time series? How do I get the values I get in Excel?

I have attached the data as csv file to this email.

Thank you very much for your help.

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


Re: [R] how to use AND in grepl

2016-05-02 Thread John McKown
On Mon, May 2, 2016 at 1:01 PM, ch.elahe via R-help 
wrote:

> I just changed all the names in Command to lowercase, then this
> str_extract works fine for "pd" and "t2", but not for "PDT2". Do you have
> any idea how I can bring PDT2  also in str_extract?
>

Looking at ​?grepl, I see the option: ignore.case=TRUE​

 PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$
Command,ignore.case=TRUE)

Perhaps this will do the trick.

-- 
The unfacts, did we have them, are too imprecisely few to warrant our
certitude.

Maranatha! <><
John McKown

[[alternative HTML version deleted]]

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

Re: [R] how to use AND in grepl

2016-05-02 Thread ch.elahe via R-help
I just changed all the names in Command to lowercase, then this str_extract 
works fine for "pd" and "t2", but not for "PDT2". Do you have any idea how I 
can bring PDT2  also in str_extract?  


On Monday, May 2, 2016 9:16 AM, Tom Wright  wrote:



The first thing I notice here is that your first two subset statements are 
searching in an object named Command, not the column df$Command. I'm not at all 
sure what you are trying to achieve with the str_extract process but it is 
looking for the exact string 'PDT2' the vectors / dataframe formed in your 
previous commands are not being used at all. 
Moving forward I think you need to pay attention to case "PD" != "pd". Also the 
set PDT2 is going to be a subset of both  sets PD and t2, I don't think this is 
what you are after.

On Mon, May 2, 2016, 8:49 AM   wrote:

Yes it works, but let me explain what I am going to do. I extract all the names 
I want and then create a new column out of them for my plot. This is he whole 
thing I do:
>  PD=subset(df,grepl("pd",Command)) //extract names in Command with only "pd"
>  t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
>  PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract 
> names which contain both "pd" and "t2"
>  v1=c('PD','t2','PDT2')// I create a vector with these conditions
>  str_extract(df$Command,paste(v1,collaps='|')) //returning patterns, using 
> stringr library
>
>here I see no pattern named PDT2 but there are only PD and t2 patterns.
>On Monday, May 2, 2016 8:18 AM, Tom Wright  wrote:
>
>
>
>Sorry for the missed braces earlier. I was typing on a phone, not the best 
>place to conjugate regular expressions.
>Using the example you provided:
>
>> df=data.frame(Command=c("_localize_PD", "_localize_tre_t2", 
>> "_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))
>
>> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
>[1] FALSE FALSE FALSE FALSE  TRUE
>
>> subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
>  Command
>5 pd_local_abdomen_t2
>
>
>
>On Mon, May 2, 2016 at 7:42 AM,  wrote:
>
>Thanks Peter, you were right, the exact grepl is 
>grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change anything 
>in Command, when I check the size of it by 
>sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I am 
>sure that the size is not 0. It seems that this AND does not work.
>>
>>
>>
>>On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
>>
>>On 02 May 2016, at 12:43 , ch.elahe via R-help  wrote:
>>
>>> Thanks for your reply tom. After using  
>>> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
>>> Argument "x" is missing, with no default. Actually I don't know how to fix 
>>> this. Do you have any idea?
>>
>>Tom's code was missing a ")" but not where you put one. He probably also 
>>didn't intend to capitalize "subset".
>>
>>
>>-pd
>>
>>> Thanks,
>>> Elahe
>>>
>>>
>>> On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:
>>>
>>>
>>>
>>> Actually not sure my previous answer does what you wanted. Using your 
>>> approach:
>>> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
>>> Should work.
>>> I think the regex pattern you are looking for is:
>>> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
>>>
>>> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
>>>
>>> subset(df,grepl("t2|pd",x$Command))




 On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help 
  wrote:

 Hi all,
>
> I have one factor variable in my df and I want to extract the names from 
> it which contain both "t2" and "pd":
>
> 'data.frame': 36919 obs. of 162 variables
>  $TE:int 38,41,11,52,48,75,.
>  $TR:int 100,210,548,546,.
>  $Command  :factor W/2229 levels 
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>
> I have tried this but I did not get result:
>
> t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>
>
> does anyone know how to apply AND in grepl?
>
> Thanks
> Elahe
>
> __
> 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 

Re: [R] Can't rename a data frame column

2016-05-02 Thread Boris Steipe
You need to learn about proper subsetting, and the names() function. Consider 
the following:

R > d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9)
R > d
  alpha beta gamma
1 14 7
2 25 8
3 36 9
R > names(d)
[1] "alpha" "beta"  "gamma"
R > names(d) == "beta"
[1] FALSE  TRUE FALSE
R > names(d)[names(d) == "beta"] <- "two"
R > d
  alpha two gamma
1 1   4 7
2 2   5 8
3 3   6 9

R > names(d)[3] <- "three"
R > d
  alpha two three
1 1   4 7
2 2   5 8
3 3   6 9



B.
(I can't even ...)




On May 2, 2016, at 1:27 PM, jpm miao  wrote:

> Hi,
> 
>   Could someone suggest a way to rename a data frame column? For example,
> I want to rename the column beta, but I can't do it this way
> 
>> d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9)
>> mm<-"beta"
>> rename(d, c(mm="two", "gamma"="three"))
> The following `from` values were not present in `x`: mm
>  alpha beta three
> 1 14 7
> 2 25 8
> 3 36 9
> 
> 
> Of course this would work
> 
>> rename(d, c("beta"="two", "gamma"="three"))
>  alpha two three
> 1 1   4 7
> 2 2   5 8
> 3 3   6 9
> 
>   [[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] greek characters in Figures

2016-05-02 Thread Martin Maechler
> Alaios via R-help 
> on Mon, 2 May 2016 17:32:34 + writes:

> Dear all,I am trying to write in my Figure labels short equations that 
contain greek characters
> For example:  C(h) = sigma^2 * rho(h).   

> I am googling it and there are many packages available ..

Googling about R problems often does not lead to the best
solutions.

In this case do

   ?plotmath

and see that you do *NOT* need to install any extra packages.
You do have 29 R packages installed with your R installation,
you already have several 1000s R functions at your
disposition

Martin Maechler,
ETH Zurich


> Any ideas what else I can try?I would like to thank you in advance for 
your replyRegardsAlex

__
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] greek characters in Figures

2016-05-02 Thread Alaios via R-help
Dear all,I am trying to write in my Figure labels short equations that contain 
greek characters

For example:  C(h) = sigma^2 * rho(h).   

I am googling it and there are many packages available but unfortunately they 
do not look available for my 3.2.4 latex version

install.packages("latex2expr")Installiere Paket nach 
‘/home/apa/R/x86_64-pc-linux-gnu-library/3.2’(da ‘lib’ nicht 
spezifiziert)Warnung: kann nicht auf den Index für das Repository 
https://cran.cnr.Berkeley.edu/src/contrib zugreifen:  nicht unterstütztes URL 
SchemaWarnmeldung:Paket ‘latex2expr’ ist nicht verfügbar (for R version 3.2.4 
Revised) 

Any ideas what else I can try?I would like to thank you in advance for your 
replyRegardsAlex
[[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] Removing NAs from dataframe (for use in Vioplot)

2016-05-02 Thread Martin Maechler
> Bert Gunter 
> on Mon, 2 May 2016 06:20:52 -0700 writes:

> Martin et. al.:
> na.omit(frame) will remove all rows/cases in which an NA occurs.  I'm
> not sure that this is what the OP wanted, which seemed to be to
> separately remove NA's from each column and plot the resulting column.
> This is what the lapply (and the OP's provided code) does, anyway.

> Also, lapply() produces a single list (of vectors), not a "series of 
lists" .

> Corrections happily accepted if I'm in error.

No corrections needed.  You were right ... and indeed I was
wrong in assuming that "one would want"  a complete  na.omit()
here.

Martin



> 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 Mon, May 2, 2016 at 1:49 AM, Martin Maechler
>  wrote:
>>> Mike Smith 
>>> on Sun, 1 May 2016 08:15:44 +0100 writes:
>> 
>>  On Apr 30, 2016, at 12:58 PM, Mike Smith
>>   wrote: Hi
>> 
>>  First post and a relative R newbie
>> 
>>  I am using the vioplot library to produce some violin
>>  plots.
>> 
DW> It's a package,  not a library.
>> 
>> [yes!]
>> 
>> 
>>  1. Is there a more elegant way of automatically
>>  stripping the NAs, passing the columns to the function
>>  along with the header names??
>> 
>> >>> ds2 <- lapply( ds1, na.omit)
>> 
>> 
>> > Fantastic - that does the trick! Easy when you know how!!
>> 
>> > Follow-on: is there a way feed all the lists from ds2 to
>> > vioplot? It is now a series of lists (rather than a
>> > dataframe - is that right?).
>> 
>> Yes, that's right.  So after all the above was not really
>> perfect :
>> 
>> na.omit() has been designed as a generic function and has always
>> had a method for "data.frame"; so, really
>> 
>> ds.noNA <- na.omit(ds1)
>> or  ds0NA   <- na.omit(ds1)
>> 
>> (choosing "expressive names")
>> 
>> is what you want.
>> 
>> __
>> 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] Can't rename a data frame column

2016-05-02 Thread jpm miao
Hi,

   Could someone suggest a way to rename a data frame column? For example,
I want to rename the column beta, but I can't do it this way

> d <- data.frame(alpha=1:3, beta=4:6, gamma=7:9)
> mm<-"beta"
> rename(d, c(mm="two", "gamma"="three"))
The following `from` values were not present in `x`: mm
  alpha beta three
1 14 7
2 25 8
3 36 9


 Of course this would work

> rename(d, c("beta"="two", "gamma"="three"))
  alpha two three
1 1   4 7
2 2   5 8
3 3   6 9

[[alternative HTML version deleted]]

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


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

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

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

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

Or, showing the whole example:

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

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

Thanks again!

-Dan

On Sat, Apr 30, 2016 at 6:43 AM, Fox, John  wrote:

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



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

[[alternative HTML version deleted]]

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


Re: [R] how to use AND in grepl

2016-05-02 Thread Tom Wright
The first thing I notice here is that your first two subset statements are
searching in an object named Command, not the column df$Command. I'm not at
all sure what you are trying to achieve with the str_extract process but it
is looking for the exact string 'PDT2' the vectors / dataframe formed in
your previous commands are not being used at all.
Moving forward I think you need to pay attention to case "PD" != "pd". Also
the set PDT2 is going to be a subset of both  sets PD and t2, I don't think
this is what you are after.

On Mon, May 2, 2016, 8:49 AM  wrote:

> Yes it works, but let me explain what I am going to do. I extract all the
> names I want and then create a new column out of them for my plot. This is
> he whole thing I do:
>   PD=subset(df,grepl("pd",Command)) //extract names in Command with only
> "pd"
>   t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
>   PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract
> names which contain both "pd" and "t2"
>   v1=c('PD','t2','PDT2')// I create a vector with these conditions
>   str_extract(df$Command,paste(v1,collaps='|')) //returning patterns,
> using stringr library
>
> here I see no pattern named PDT2 but there are only PD and t2 patterns.
> On Monday, May 2, 2016 8:18 AM, Tom Wright  wrote:
>
>
>
> Sorry for the missed braces earlier. I was typing on a phone, not the best
> place to conjugate regular expressions.
> Using the example you provided:
>
> > df=data.frame(Command=c("_localize_PD", "_localize_tre_t2",
> "_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))
>
> > grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
> [1] FALSE FALSE FALSE FALSE  TRUE
>
> > subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
>   Command
> 5 pd_local_abdomen_t2
>
>
>
> On Mon, May 2, 2016 at 7:42 AM,  wrote:
>
> Thanks Peter, you were right, the exact grepl is
> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change
> anything in Command, when I check the size of it by
> sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I
> am sure that the size is not 0. It seems that this AND does not work.
> >
> >
> >
> >On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
> >
> >On 02 May 2016, at 12:43 , ch.elahe via R-help 
> wrote:
> >
> >> Thanks for your reply tom. After using
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error:
> Argument "x" is missing, with no default. Actually I don't know how to fix
> this. Do you have any idea?
> >
> >Tom's code was missing a ")" but not where you put one. He probably also
> didn't intend to capitalize "subset".
> >
> >
> >-pd
> >
> >> Thanks,
> >> Elahe
> >>
> >>
> >> On Saturday, April 30, 2016 7:35 PM, Tom Wright 
> wrote:
> >>
> >>
> >>
> >> Actually not sure my previous answer does what you wanted. Using your
> approach:
> >> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> >> Should work.
> >> I think the regex pattern you are looking for is:
> >> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> >>
> >> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> >>
> >> subset(df,grepl("t2|pd",x$Command))
> >>>
> >>>
> >>>
> >>>
> >>> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help <
> r-help@r-project.org> wrote:
> >>>
> >>> Hi all,
> 
>  I have one factor variable in my df and I want to extract the names
> from it which contain both "t2" and "pd":
> 
>  'data.frame': 36919 obs. of 162 variables
>   $TE:int 38,41,11,52,48,75,.
>   $TR:int 100,210,548,546,.
>   $Command  :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
> 
>  I have tried this but I did not get result:
> 
>  t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
> 
> 
>  does anyone know how to apply AND in grepl?
> 
>  Thanks
>  Elahe
> 
>  __
>  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.
> >
> >--
> >Peter Dalgaard, Professor,
> >Center for Statistics, Copenhagen Business School
> >Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> >Phone: (+45)38153501

Re: [R] how to use AND in grepl

2016-05-02 Thread ch.elahe via R-help
Yes it works, but let me explain what I am going to do. I extract all the names 
I want and then create a new column out of them for my plot. This is he whole 
thing I do:
  PD=subset(df,grepl("pd",Command)) //extract names in Command with only "pd"
  t2=subset(df,grepl("t2",Command)) //extract names with only "t2"
  PDT2=subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command) // extract names 
which contain both "pd" and "t2"
  v1=c('PD','t2','PDT2')// I create a vector with these conditions
  str_extract(df$Command,paste(v1,collaps='|')) //returning patterns, using 
stringr library

here I see no pattern named PDT2 but there are only PD and t2 patterns.
On Monday, May 2, 2016 8:18 AM, Tom Wright  wrote:



Sorry for the missed braces earlier. I was typing on a phone, not the best 
place to conjugate regular expressions.
Using the example you provided:

> df=data.frame(Command=c("_localize_PD", "_localize_tre_t2", 
> "_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))

> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
[1] FALSE FALSE FALSE FALSE  TRUE

> subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
  Command
5 pd_local_abdomen_t2



On Mon, May 2, 2016 at 7:42 AM,  wrote:

Thanks Peter, you were right, the exact grepl is 
grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change anything 
in Command, when I check the size of it by 
sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I am 
sure that the size is not 0. It seems that this AND does not work.
>
>
>
>On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
>
>On 02 May 2016, at 12:43 , ch.elahe via R-help  wrote:
>
>> Thanks for your reply tom. After using  
>> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
>> Argument "x" is missing, with no default. Actually I don't know how to fix 
>> this. Do you have any idea?
>
>Tom's code was missing a ")" but not where you put one. He probably also 
>didn't intend to capitalize "subset".
>
>
>-pd
>
>> Thanks,
>> Elahe
>>
>>
>> On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:
>>
>>
>>
>> Actually not sure my previous answer does what you wanted. Using your 
>> approach:
>> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
>> Should work.
>> I think the regex pattern you are looking for is:
>> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
>>
>> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
>>
>> subset(df,grepl("t2|pd",x$Command))
>>>
>>>
>>>
>>>
>>> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  
>>> wrote:
>>>
>>> Hi all,

 I have one factor variable in my df and I want to extract the names from 
 it which contain both "t2" and "pd":

 'data.frame': 36919 obs. of 162 variables
  $TE:int 38,41,11,52,48,75,.
  $TR:int 100,210,548,546,.
  $Command  :factor W/2229 levels 
 "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...

 I have tried this but I did not get result:

 t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))


 does anyone know how to apply AND in grepl?

 Thanks
 Elahe

 __
 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.
>
>--
>Peter Dalgaard, Professor,
>Center for Statistics, Copenhagen Business School
>Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>Phone: (+45)38153501
>Office: A 4.23
>Email: pd@cbs.dk  Priv: pda...@gmail.com
>

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


Re: [R] Help regarding Community Detection Algorithm in R (like Propagation, Walktrap)

2016-05-02 Thread Giorgio Garziano
You may look at:

http://rseek.org/?q=community%20detection


--

Best,

GG

[[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] Issue installing packages - Linux

2016-05-02 Thread Shouro Dasgupta
Hello Lara,

I recently installed a number of packages through compiling. After
downloading the package using 'wget', running R CMD INSTALL package.tar.gz
should work.

Sincerely,

Shouro

On Mon, May 2, 2016 at 5:17 PM, Lars Bishop  wrote:

> Thanks Jim. I don't think that is the issue...if anyone else can shed some
> light here, that would be much appreciated.
>
> Regards
> Lars.
>
> On Saturday, 30 April 2016, Jim Lemon  wrote:
>
> > Hi Lars,
> > A mystery, but for the bodgy characters in your error message. Perhaps
> > there is a problem with R trying to read a different character set
> > from that used in the package.
> >
> > Jim
> >
> > On Sat, Apr 30, 2016 at 8:22 PM, Lars Bishop  > > wrote:
> > > Hello,
> > >
> > > I can’t seem to be able to install packages on a redhat-linux-gnu. For
> > > instance, this is what happens when I try to install “bitops”. Any hint
> > on
> > > what might be the issue would be much appreciated.
> > >
> > >> sessionInfo()
> > > R version 3.2.3 (2015-12-10)
> > > Platform: x86_64-redhat-linux-gnu (64-bit)
> > > Running under: Red Hat Enterprise Linux
> > >
> > >> Sys.setenv(https_proxy="https://labproxy.com:8080;)
> > >> install.packages("bitops", lib="mypath ")
> > >
> > > Here I choose: 22: (HTTP mirrors) and then a mirror 16:Canada(ON)
> > >
> > > * installing *source* package âbitopsâ ...
> > > ** package âbitopsâ successfully unpacked and MD5 sums checked
> > > Error in readRDS(pfile) : error reading from connection
> > > ERROR: lazy loading failed for package âbitopsâ
> > >
> > > I’ve also tried from the shell (after downloading the package source)
> > >
> > > $  R CMD INSTALL bitops_1.0-6.tar.gz
> > > ERROR: cannot extract package from bitops_1.0-6.tar.gz
> > >
> > > Thank you,
> > > Lars.
> > >
> > > [[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.




-- 

Shouro Dasgupta, PhD
Junior Researcher
Fondazione Eni Enrico Mattei (FEEM) |
Centro Euro-Mediterraneo per i Cambiamenti Climatici (CMCC)
Isola di San Giorgio Maggiore, 8
30124 Venezia
Phone: +39 041 2700 436

[[alternative HTML version deleted]]

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

Re: [R] how to use AND in grepl

2016-05-02 Thread Tom Wright
Sorry for the missed braces earlier. I was typing on a phone, not the best
place to conjugate regular expressions.
Using the example you provided:

> df=data.frame(Command=c("_localize_PD", "_localize_tre_t2",
"_abdomen_t1_seq", "knee_pd_t1_localize", "pd_local_abdomen_t2"))

> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command)
[1] FALSE FALSE FALSE FALSE  TRUE

> subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))
  Command
5 pd_local_abdomen_t2


On Mon, May 2, 2016 at 7:42 AM,  wrote:

> Thanks Peter, you were right, the exact grepl is
> grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change
> anything in Command, when I check the size of it by
> sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I
> am sure that the size is not 0. It seems that this AND does not work.
>
>
> On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:
>
> On 02 May 2016, at 12:43 , ch.elahe via R-help 
> wrote:
>
> > Thanks for your reply tom. After using
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error:
> Argument "x" is missing, with no default. Actually I don't know how to fix
> this. Do you have any idea?
>
> Tom's code was missing a ")" but not where you put one. He probably also
> didn't intend to capitalize "subset".
>
>
> -pd
>
> > Thanks,
> > Elahe
> >
> >
> > On Saturday, April 30, 2016 7:35 PM, Tom Wright 
> wrote:
> >
> >
> >
> > Actually not sure my previous answer does what you wanted. Using your
> approach:
> > t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> > Should work.
> > I think the regex pattern you are looking for is:
> > Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> >
> > On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> >
> > subset(df,grepl("t2|pd",x$Command))
> >>
> >>
> >>
> >>
> >> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help <
> r-help@r-project.org> wrote:
> >>
> >> Hi all,
> >>>
> >>> I have one factor variable in my df and I want to extract the names
> from it which contain both "t2" and "pd":
> >>>
> >>> 'data.frame': 36919 obs. of 162 variables
> >>>  $TE:int 38,41,11,52,48,75,.
> >>>  $TR:int 100,210,548,546,.
> >>>  $Command  :factor W/2229 levels
> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
> >>>
> >>> I have tried this but I did not get result:
> >>>
> >>> t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
> >>>
> >>>
> >>> does anyone know how to apply AND in grepl?
> >>>
> >>> Thanks
> >>> Elahe
> >>>
> >>> __
> >>> 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.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>

[[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] Issue installing packages - Linux

2016-05-02 Thread Lars Bishop
Thanks Jim. I don't think that is the issue...if anyone else can shed some
light here, that would be much appreciated.

Regards
Lars.

On Saturday, 30 April 2016, Jim Lemon  wrote:

> Hi Lars,
> A mystery, but for the bodgy characters in your error message. Perhaps
> there is a problem with R trying to read a different character set
> from that used in the package.
>
> Jim
>
> On Sat, Apr 30, 2016 at 8:22 PM, Lars Bishop  > wrote:
> > Hello,
> >
> > I can’t seem to be able to install packages on a redhat-linux-gnu. For
> > instance, this is what happens when I try to install “bitops”. Any hint
> on
> > what might be the issue would be much appreciated.
> >
> >> sessionInfo()
> > R version 3.2.3 (2015-12-10)
> > Platform: x86_64-redhat-linux-gnu (64-bit)
> > Running under: Red Hat Enterprise Linux
> >
> >> Sys.setenv(https_proxy="https://labproxy.com:8080;)
> >> install.packages("bitops", lib="mypath ")
> >
> > Here I choose: 22: (HTTP mirrors) and then a mirror 16:Canada(ON)
> >
> > * installing *source* package âbitopsâ ...
> > ** package âbitopsâ successfully unpacked and MD5 sums checked
> > Error in readRDS(pfile) : error reading from connection
> > ERROR: lazy loading failed for package âbitopsâ
> >
> > I’ve also tried from the shell (after downloading the package source)
> >
> > $  R CMD INSTALL bitops_1.0-6.tar.gz
> > ERROR: cannot extract package from bitops_1.0-6.tar.gz
> >
> > Thank you,
> > Lars.
> >
> > [[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.

Re: [R] Network Layouting in R

2016-05-02 Thread Sarah Goslee
Hi,

On Mon, May 2, 2016 at 8:36 AM, Kushank Chhabra
 wrote:
> Hi,
>
>
>
> I am trying to plot a network diagram of around 1500 component (as nodes)
> and many connections (as edges) within them.

> I tried igraph package, however unable to create a layout where there is no
> overlap of nodes or edges.

How do you know it's physically possible to create a 2D layout with no overlap?
1500 nodes is a lot.

What did you try? What did you get? Did you produce a diagram, just
with more overlap than you were expecting? That may be the best you
can do.

> More or less tried all the things mentioned in this link -
>
> http://kateto.net/network-visualization

Again, what did you try? What did you get that doesn't meet your
needs? Just the overlap? Again, that may be unavoidable. Note the
comment from that link:
"One thing to emphasize though is that in many cases, visualizing
larger networks as giant hairballs is less helpful than providing
charts that show key characteristics of the graph."

> Can you please suggest how to do it in R ?

For working with largish graph layouts, I've had more success with
gephi than R, although I believe you can duplicate most of the gephi
functionality in R.

Sarah


>
>
> Output expected – A good layout of the network diagram (of around 1500
> nodes) with no overlaps of nodes or even edges and possibly it can be
> screened as a picture, or on a browser or on a pdf.
>
>
>
> With Best Regards,
>
> Kushank

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

Re: [R] how to use AND in grepl

2016-05-02 Thread ch.elahe via R-help
Thanks Peter, you were right, the exact grepl is 
grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command), but it does not change anything 
in Command, when I check the size of it by 
sum(grepl("(.*t2.*pd.*)|(.*pd.*t2.*)",df$Command))  the result is 0, but I am 
sure that the size is not 0. It seems that this AND does not work.
 

On Monday, May 2, 2016 5:05 AM, peter dalgaard  wrote:

On 02 May 2016, at 12:43 , ch.elahe via R-help  wrote:

> Thanks for your reply tom. After using  
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
> Argument "x" is missing, with no default. Actually I don't know how to fix 
> this. Do you have any idea?

Tom's code was missing a ")" but not where you put one. He probably also didn't 
intend to capitalize "subset".


-pd

> Thanks,
> Elahe 
> 
> 
> On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:
> 
> 
> 
> Actually not sure my previous answer does what you wanted. Using your 
> approach:
> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> Should work.
> I think the regex pattern you are looking for is:
> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> 
> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> 
> subset(df,grepl("t2|pd",x$Command))
>> 
>> 
>> 
>> 
>> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  
>> wrote:
>> 
>> Hi all,
>>> 
>>> I have one factor variable in my df and I want to extract the names from it 
>>> which contain both "t2" and "pd":
>>> 
>>> 'data.frame': 36919 obs. of 162 variables
>>>  $TE:int 38,41,11,52,48,75,.
>>>  $TR:int 100,210,548,546,.
>>>  $Command  :factor W/2229 levels 
>>> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>>> 
>>> I have tried this but I did not get result:
>>> 
>>> t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>>> 
>>> 
>>> does anyone know how to apply AND in grepl?
>>> 
>>> Thanks
>>> Elahe
>>> 
>>> __
>>> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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] Network Layouting in R

2016-05-02 Thread Kushank Chhabra
Hi,



I am trying to plot a network diagram of around 1500 component (as nodes)
and many connections (as edges) within them.



I tried igraph package, however unable to create a layout where there is no
overlap of nodes or edges.



More or less tried all the things mentioned in this link -

http://kateto.net/network-visualization



Can you please suggest how to do it in R ?



Output expected – A good layout of the network diagram (of around 1500
nodes) with no overlaps of nodes or even edges and possibly it can be
screened as a picture, or on a browser or on a pdf.



With Best Regards,

Kushank

[[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] Rserve() error in the first instance of running a Java application

2016-05-02 Thread Purva Kulkarni
Hi, 

I am writing a Java GUI application which uses Rserve(). I have a java script 
which sends a command to the shell to start Rserve(). When I run the Java main 
method for the very first time, it calls this script to invoke Rserve() and 
starts Rserve(). But, in this first run the Java GUI application is not 
launched. But, when I run the main method for the second time, I get the 
following message and the GUI application is launched. 

##> SOCK_ERROR: bind error #48(address already in use)

I do not understand this behaviour. From what I can understand, in the first 
run, the script just establishes the Rserve() connection and then in the second 
run it works. Can someone help me fix this, so that program connects to 
Rserve() in the first instance and also launches the GUI?

Here my Java class containing the method to invoke Rserve():

public class InvokeRserve {
public static int invoke() {
String s;

try {

// run the Unix "ps -ef" command
// using the Runtime exec method:
Process p = Runtime.getRuntime().exec("R CMD RServe --vanilla");

BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));

BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));

// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}

// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if 
any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}

//  System.exit(0);

}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
return 1;
}


Here is the main method which calls the invoke() method:

public class Application {
/**
 * Main method for the Swing application
 *
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {

// Start Rserve()
int value = InvokeRserve.invoke();

if(value == 1) {
// Run the GUI construction in the Event-Dispatching thread for 
thread-safety
SwingUtilities.invokeLater(new Runnable() {

/**
 * run method which create a new GUIMain object
 */
@Override
public void run() {
new GUIMain(“Data Analysis Application“); // Let the 
constructor do the job
}
});
}
}
}

__
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 regarding Community Detection Algorithm in R (like Propagation, Walktrap)

2016-05-02 Thread Swagatam Basu
Hi

I am very new to R studio and R language. I have installed the R studio in
my machine.

I need to do a community detection of a set of message. I have a Matrix for
that.

Is there any sample code /Package/ website is present which will help me to
understand/do this community Detection (like Propagation, Walk trap
Algorithm) in R-language by using R-studio.

Please help.

Please revert back in case of any discrepencies.

Thanks
S Basu

[[alternative HTML version deleted]]

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


Re: [R] How to print the frequency table (produced by the command "table" to Excel

2016-05-02 Thread Bert Gunter
Don't know if this would help, but you could always set an attribute
of alphatab to be the dimnames. See ?attrib . Of course you would then
have to write a custom print() function, possibly along the lines you
indicated.

You could also do this via S3 (or whatever) classes, of course. But
again, none of this may be the sort of thing the OP could handle.
Maybe my point is by improving her(?) R programming skills, she would
gain the ability to do all sorts of such "customizations".

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 Mon, May 2, 2016 at 2:58 AM, Jim Lemon  wrote:
> Hi jpm miao,
> After a fair stretch of fooling around with it, I can't see any way to
> add the variable names ("varnames") to the output of delim.table
> without breaking it for things other than table objects. You can
> probably do this as a one-off hack by setting the names of the
> dimnames of the "counts" element in alphatab like this:
>
> names(dimnames(alphatab$counts))<-alphatab$varnames
>
> You can then shoehorn these into the output by adding a line to
> display the second varname above the table and add the first varname
> to the row of value labels. That's the best I can do at the moment.
>
> Jim
>
>
> On Sun, May 1, 2016 at 11:19 AM, jpm miao  wrote:
>> Thanks.
>> Could we print the row/column names, "alpha1" and "alpha2" to the csv file?
>>
>> 2016-04-30 17:06 GMT-07:00 Jim Lemon :
>>>
>>> Hi jpm miao,
>>> I think you can get what you want like this:
>>>
>>> alpha1<-sample(LETTERS[1:3],50,TRUE)
>>> alpha2<-sample(LETTERS[1:2],50,TRUE)
>>> alphas<-data.frame(alpha1,alpha2)
>>> library(prettyR)
>>> alphatab<-xtab(alpha1~alpha2,alphas)
>>> sink("temp_table3.csv",append=TRUE)
>>> delim.xtab(alphatab,pct=NA,delim=",")
>>> sink()
>>>
>>> Jim
>>>
>>> On Sun, May 1, 2016 at 4:47 AM, jpm miao  wrote:
>>> > Jim,
>>> >
>>> >Thanks for creating such a fantastic package "prettyR".
>>> >I want to print the pretty frequency table (with row total and column
>>> > total) to an excel (or csv ) file. Is it possible?
>>> >>alphatab
>>> >
>>> > A B Total
>>> > A 8 10 18
>>> > B 7 5 12
>>> > C 9 11 20
>>> > Total 24 26 50
>>> >
>>> >Two issues I encountered (See the attached csv file).
>>> > 1. When I tried to print the above table to csv file, all elements on
>>> > the
>>> > same row are printed in one cell.
>>> > 2. If I write "delim.table(alpha tab)", the table is distorted (see
>>> > attached). Of course, I can adjust it manually but sometimes the number
>>> > of
>>> > files is big.
>>> >
>>> > Thanks!
>>> >
>>> > Miao
>>> >
>>> >> alpha1<-sample(LETTERS[1:3],50,TRUE)
>>> >> alpha2<-sample(LETTERS[1:2],50,TRUE)
>>> >>
>>> >> alphas<-data.frame(alpha1,alpha2)
>>> >> alphatab<-xtab(alpha1~alpha2,alphas)
>>> > Crosstabulation of alpha1 by alpha2
>>> > alpha2
>>> > alpha1  A  B
>>> > A  8 10 18
>>> >44.44  55.56  -
>>> >33.33  38.46  36.00
>>> >
>>> > B  7  5 12
>>> >58.33  41.67  -
>>> >29.17  19.23  24.00
>>> >
>>> > C  9 11 20
>>> >   45 55  -
>>> >37.50  42.31  40.00
>>> >
>>> >   24 26 50
>>> >   48 52100
>>> >> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
>>> > alphatab
>>> >
>>> > A B Total
>>> > A 8 10 18
>>> > B 7 5 12
>>> > C 9 11 20
>>> > Total 24 26 50
>>> >
>>> >> sink("temp_table3.csv")
>>> >> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
>>> >> sink()
>>> >> sink("temp_table3.csv", append=TRUE)
>>> >> delim.table(alphatab)
>>> >> sink()
>>> >> sink("temp_table3.csv", append=TRUE)
>>> >> delim.table(alphatab)
>>> >> sink()
>>> >> ?delim.xtab
>>> >
>>> >
>>> > 2016-04-26 16:14 GMT-07:00 Jim Lemon :
>>> >>
>>> >> Hi jpm miao,
>>> >> You can get CSV files that can be imported into Excel like this:
>>> >>
>>> >> library(prettyR)
>>> >> sink("excel_table1.csv")
>>> >> delim.table(table(df[,c("y","z")]))
>>> >> sink()
>>> >> sink("excel_table2.csv")
>>> >> delim.table(as.data.frame(table(df[,c("y","z")])),label="")
>>> >> sink()
>>> >> sink("excel_table3.csv")
>>> >> delim.table(as.matrix(table(df[,c("y","z")])),label="")
>>> >> sink()
>>> >>
>>> >> Jim
>>> >>
>>> >> On Wed, Apr 27, 2016 at 8:35 AM, jpm miao  wrote:
>>> >> > Hi,
>>> >> >
>>> >> >How could we print the frequency table (produced by "table") to an
>>> >> > Excel
>>> >> > file?
>>> >> >Is there an easy way to do so? Thanks,
>>> >> >
>>> >> > Miao
>>> >> >
>>> >> >> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3])
>>> >> >
>>> >> >> table(df[,c("y","z")])
>>> >> >z
>>> >> > y   a b c
>>> >> >   1 0 0 1
>>> >> >   2 0 1 0
>>> >> >   3 1 0 0
>>> >> >> test<-table(df[,c("y","z")])
>>> >> >> as.data.frame(test)
>>> >> >   y z Freq
>>> >> > 1 1 a0
>>> >> > 2 2 a 

Re: [R] Removing NAs from dataframe (for use in Vioplot)

2016-05-02 Thread Bert Gunter
Martin et. al.:

na.omit(frame) will remove all rows/cases in which an NA occurs.  I'm
not sure that this is what the OP wanted, which seemed to be to
separately remove NA's from each column and plot the resulting column.
This is what the lapply (and the OP's provided code) does, anyway.

Also, lapply() produces a single list (of vectors), not a "series of lists" .

Corrections happily accepted if I'm in error.

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 Mon, May 2, 2016 at 1:49 AM, Martin Maechler
 wrote:
>> Mike Smith 
>> on Sun, 1 May 2016 08:15:44 +0100 writes:
>
>  On Apr 30, 2016, at 12:58 PM, Mike Smith
>   wrote: Hi
>
>  First post and a relative R newbie
>
>  I am using the vioplot library to produce some violin
>  plots.
>
> DW> It's a package,  not a library.
>
> [yes!]
>
>
>  1. Is there a more elegant way of automatically
>  stripping the NAs, passing the columns to the function
>  along with the header names??
>
> >>> ds2 <- lapply( ds1, na.omit)
>
>
> > Fantastic - that does the trick! Easy when you know how!!
>
> > Follow-on: is there a way feed all the lists from ds2 to
> > vioplot? It is now a series of lists (rather than a
> > dataframe - is that right?).
>
> Yes, that's right.  So after all the above was not really
> perfect :
>
>   na.omit() has been designed as a generic function and has always
>   had a method for "data.frame"; so, really
>
> ds.noNA <- na.omit(ds1)
> or  ds0NA   <- na.omit(ds1)
>
> (choosing "expressive names")
>
> is what you want.
>
> __
> 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] Order of bars w geom_errorbarh ??

2016-05-02 Thread Jeff Newmiller
Ordering of any discrete values in ggplot goes according to the levels of the 
factor. As a convenience, ggplot will convert character values into factor for 
you according to the default order alphabetical). To take control of this you 
have to convert your discrete columns to factors yourself before giving the 
data to ggplot, e.g.

DF$somecol  <- factor( DF$somecol, levels=c("level1","level2",...) )

However, if you pull data from different factors in different input tables, 
ggplot has to combine them internally, and you will lose your specified 
ordering. With no minimum reproducible example I cannot tell whether that is a 
problem for you,  but the solution would be to combine them yourself before you 
give them to ggplot.
-- 
Sent from my phone. Please excuse my brevity.

On May 1, 2016 4:59:23 PM PDT, Judson Blake  wrote:
>Using geom_errorbarh with ggplot, my plot has several error bars.   For
>my
>presentation, the order of these bars from top to bottom is important.
>But errorbarh seems to put these in a random order I can't change.  (
>It
>does not follow the order in the data.frame. )How can I specify the
>order of the bars?   Could I also specify the thickness of the bar
>lines?
>
>   [[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.


Re: [R] how to use AND in grepl

2016-05-02 Thread peter dalgaard

On 02 May 2016, at 12:43 , ch.elahe via R-help  wrote:

> Thanks for your reply tom. After using  
> Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
> Argument "x" is missing, with no default. Actually I don't know how to fix 
> this. Do you have any idea?

Tom's code was missing a ")" but not where you put one. He probably also didn't 
intend to capitalize "subset".

-pd

> Thanks,
> Elahe 
> 
> 
> On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:
> 
> 
> 
> Actually not sure my previous answer does what you wanted. Using your 
> approach:
> t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
> Should work.
> I think the regex pattern you are looking for is:
> Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)
> 
> On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:
> 
> subset(df,grepl("t2|pd",x$Command))
>> 
>> 
>> 
>> 
>> On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  
>> wrote:
>> 
>> Hi all,
>>> 
>>> I have one factor variable in my df and I want to extract the names from it 
>>> which contain both "t2" and "pd":
>>> 
>>> 'data.frame': 36919 obs. of 162 variables
>>>  $TE:int 38,41,11,52,48,75,.
>>>  $TR:int 100,210,548,546,.
>>>  $Command  :factor W/2229 levels 
>>> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>>> 
>>> I have tried this but I did not get result:
>>> 
>>> t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>>> 
>>> 
>>> does anyone know how to apply AND in grepl?
>>> 
>>> Thanks
>>> Elahe
>>> 
>>> __
>>> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] how to use AND in grepl

2016-05-02 Thread ch.elahe via R-help
Thanks for your reply tom. After using  
Subset(df,grepl("(.*t2.*pd.*)|(.*pd.*t2.*)"),df$Command)  I get this error: 
Argument "x" is missing, with no default. Actually I don't know how to fix 
this. Do you have any idea?
Thanks,
Elahe 


On Saturday, April 30, 2016 7:35 PM, Tom Wright  wrote:



Actually not sure my previous answer does what you wanted. Using your approach:
 t2pd=subset(df,grepl("t2",df$Command) & grepl("pd",df$Command))
Should work.
I think the regex pattern you are looking for is:
 Subset(df,grepl("(.* t2.*pd.* )|(.* pd.* t2.*)",df$Command)

On Sat, Apr 30, 2016, 7:07 PM Tom Wright  wrote:

subset(df,grepl("t2|pd",x$Command))
>
>
>
>
>On Sat, Apr 30, 2016 at 2:38 PM, ch.elahe via R-help  
>wrote:
>
>Hi all,
>>
>>I have one factor variable in my df and I want to extract the names from it 
>>which contain both "t2" and "pd":
>>
>>  'data.frame': 36919 obs. of 162 variables
>>   $TE:int 38,41,11,52,48,75,.
>>   $TR:int 100,210,548,546,.
>>   $Command  :factor W/2229 levels 
>> "_localize_PD","_localize_tre_t2","_abdomen_t1_seq","knee_pd_t1_localize","pd_local_abdomen_t2"...
>>
>>I have tried this but I did not get result:
>>
>>  t2pd=subset(df,grepl("t2",Command) & grepl("pd",Command))
>>
>>
>>does anyone know how to apply AND in grepl?
>>
>>Thanks
>>Elahe
>>
>>__
>>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] How to print the frequency table (produced by the command "table" to Excel

2016-05-02 Thread Jim Lemon
Hi jpm miao,
After a fair stretch of fooling around with it, I can't see any way to
add the variable names ("varnames") to the output of delim.table
without breaking it for things other than table objects. You can
probably do this as a one-off hack by setting the names of the
dimnames of the "counts" element in alphatab like this:

names(dimnames(alphatab$counts))<-alphatab$varnames

You can then shoehorn these into the output by adding a line to
display the second varname above the table and add the first varname
to the row of value labels. That's the best I can do at the moment.

Jim


On Sun, May 1, 2016 at 11:19 AM, jpm miao  wrote:
> Thanks.
> Could we print the row/column names, "alpha1" and "alpha2" to the csv file?
>
> 2016-04-30 17:06 GMT-07:00 Jim Lemon :
>>
>> Hi jpm miao,
>> I think you can get what you want like this:
>>
>> alpha1<-sample(LETTERS[1:3],50,TRUE)
>> alpha2<-sample(LETTERS[1:2],50,TRUE)
>> alphas<-data.frame(alpha1,alpha2)
>> library(prettyR)
>> alphatab<-xtab(alpha1~alpha2,alphas)
>> sink("temp_table3.csv",append=TRUE)
>> delim.xtab(alphatab,pct=NA,delim=",")
>> sink()
>>
>> Jim
>>
>> On Sun, May 1, 2016 at 4:47 AM, jpm miao  wrote:
>> > Jim,
>> >
>> >Thanks for creating such a fantastic package "prettyR".
>> >I want to print the pretty frequency table (with row total and column
>> > total) to an excel (or csv ) file. Is it possible?
>> >>alphatab
>> >
>> > A B Total
>> > A 8 10 18
>> > B 7 5 12
>> > C 9 11 20
>> > Total 24 26 50
>> >
>> >Two issues I encountered (See the attached csv file).
>> > 1. When I tried to print the above table to csv file, all elements on
>> > the
>> > same row are printed in one cell.
>> > 2. If I write "delim.table(alpha tab)", the table is distorted (see
>> > attached). Of course, I can adjust it manually but sometimes the number
>> > of
>> > files is big.
>> >
>> > Thanks!
>> >
>> > Miao
>> >
>> >> alpha1<-sample(LETTERS[1:3],50,TRUE)
>> >> alpha2<-sample(LETTERS[1:2],50,TRUE)
>> >>
>> >> alphas<-data.frame(alpha1,alpha2)
>> >> alphatab<-xtab(alpha1~alpha2,alphas)
>> > Crosstabulation of alpha1 by alpha2
>> > alpha2
>> > alpha1  A  B
>> > A  8 10 18
>> >44.44  55.56  -
>> >33.33  38.46  36.00
>> >
>> > B  7  5 12
>> >58.33  41.67  -
>> >29.17  19.23  24.00
>> >
>> > C  9 11 20
>> >   45 55  -
>> >37.50  42.31  40.00
>> >
>> >   24 26 50
>> >   48 52100
>> >> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
>> > alphatab
>> >
>> > A B Total
>> > A 8 10 18
>> > B 7 5 12
>> > C 9 11 20
>> > Total 24 26 50
>> >
>> >> sink("temp_table3.csv")
>> >> delim.xtab(alphatab,pct=NA,interdigitate=TRUE)
>> >> sink()
>> >> sink("temp_table3.csv", append=TRUE)
>> >> delim.table(alphatab)
>> >> sink()
>> >> sink("temp_table3.csv", append=TRUE)
>> >> delim.table(alphatab)
>> >> sink()
>> >> ?delim.xtab
>> >
>> >
>> > 2016-04-26 16:14 GMT-07:00 Jim Lemon :
>> >>
>> >> Hi jpm miao,
>> >> You can get CSV files that can be imported into Excel like this:
>> >>
>> >> library(prettyR)
>> >> sink("excel_table1.csv")
>> >> delim.table(table(df[,c("y","z")]))
>> >> sink()
>> >> sink("excel_table2.csv")
>> >> delim.table(as.data.frame(table(df[,c("y","z")])),label="")
>> >> sink()
>> >> sink("excel_table3.csv")
>> >> delim.table(as.matrix(table(df[,c("y","z")])),label="")
>> >> sink()
>> >>
>> >> Jim
>> >>
>> >> On Wed, Apr 27, 2016 at 8:35 AM, jpm miao  wrote:
>> >> > Hi,
>> >> >
>> >> >How could we print the frequency table (produced by "table") to an
>> >> > Excel
>> >> > file?
>> >> >Is there an easy way to do so? Thanks,
>> >> >
>> >> > Miao
>> >> >
>> >> >> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3])
>> >> >
>> >> >> table(df[,c("y","z")])
>> >> >z
>> >> > y   a b c
>> >> >   1 0 0 1
>> >> >   2 0 1 0
>> >> >   3 1 0 0
>> >> >> test<-table(df[,c("y","z")])
>> >> >> as.data.frame(test)
>> >> >   y z Freq
>> >> > 1 1 a0
>> >> > 2 2 a0
>> >> > 3 3 a1
>> >> > 4 1 b0
>> >> > 5 2 b1
>> >> > 6 3 b0
>> >> > 7 1 c1
>> >> > 8 2 c0
>> >> > 9 3 c0
>> >> >> as.matrix(test)
>> >> >z
>> >> > y   a b c
>> >> >   1 0 0 1
>> >> >   2 0 1 0
>> >> >   3 1 0 0
>> >> >> testm<-as.matrix(test)
>> >> >> testm
>> >> >z
>> >> > y   a b c
>> >> >   1 0 0 1
>> >> >   2 0 1 0
>> >> >   3 1 0 0
>> >> >> typeof(testm)
>> >> > [1] "integer"
>> >> >
>> >> > [[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] Retrieving response variable in the probit

2016-05-02 Thread Achim Zeileis

On Mon, 2 May 2016, Steven Yen wrote:


Can anyone tell me how to retrieve the response (dependent) variable
from a probit regression object (as much as model.matrix(obj)
retrieves the data matrix). Below is a self-runnable set of codes.
Thank you!

library(sampleSelection)
data<-read.csv("https://dl.dropboxusercontent.com/u/220037024/Yen/data/pta.csv;)
eq1<-d~sex+age+educ
p1<-probit(eq1,data=data)
summary(p1)
attributes(p1)


model.frame(p1)

recovers the (possibly transformed) data employed for fitting the model 
and


model.response(model.frame(p1))

extracts the response variable from that model frame.


__
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] Removing NAs from dataframe (for use in Vioplot)

2016-05-02 Thread Martin Maechler
> Mike Smith 
> on Sun, 1 May 2016 08:15:44 +0100 writes:

 On Apr 30, 2016, at 12:58 PM, Mike Smith
  wrote: Hi

 First post and a relative R newbie

 I am using the vioplot library to produce some violin
 plots.

DW> It's a package,  not a library.

[yes!]


 1. Is there a more elegant way of automatically
 stripping the NAs, passing the columns to the function
 along with the header names??

>>> ds2 <- lapply( ds1, na.omit)


> Fantastic - that does the trick! Easy when you know how!!

> Follow-on: is there a way feed all the lists from ds2 to
> vioplot? It is now a series of lists (rather than a
> dataframe - is that right?).

Yes, that's right.  So after all the above was not really
perfect :

  na.omit() has been designed as a generic function and has always
  had a method for "data.frame"; so, really

ds.noNA <- na.omit(ds1)
or  ds0NA   <- na.omit(ds1)

(choosing "expressive names")

is what you want.

__
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] inserting row(column) in array or dataframe at specified row(column)

2016-05-02 Thread PIKAL Petr
Hi

You can use rbind, cbind but you need to be aware of what objects you are 
binding together.

mm<-matrix(rnorm(12), 3,4)
> rbind(mm[1:2,], 1:4, mm[3,])
   [,1]   [,2]   [,3]   [,4]
[1,] -0.2029407 -1.5910628 -0.2582281 -0.1649921
[2,] -0.6913951  0.3591561  0.8236836 -0.3592203
[3,]  1.000  2.000  3.000  4.000
[4,] -0.2096650 -2.3671913 -0.438  0.3846274

Anyway, you can append rows/columns and perform sort/order afterwards if you 
consider ordering important.

Cheers
Petr




> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jan Kacaba
> Sent: Sunday, May 1, 2016 7:54 PM
> To: r-help@r-project.org
> Subject: [R] inserting row(column) in array or dataframe at specified
> row(column)
>
> Hello dear R users,
>
> Is there a function or package which can insert row, column or array in
> another array at specified place (row or column)?
>
> I have made several attempts at this function optimizing both speed, code
> readability and ease of use. The functions are of following format:
>
> appcol=function(original_array, inserted_object, column_number,
> overwrite=FALSE)
>
> # If overwrite=TRUE the columns after column_number are ovewritten by
> inserted_object else the columns after column_number are shifted.
>
> Now I have started using package dplyr and it seams that there is no inserting
> function either. One can only append at the end or at the beginning of
> tbl_df. Is it true?
>
>   [[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.


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 informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
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 

[R] Retrieving response variable in the probit

2016-05-02 Thread Steven Yen
Can anyone tell me how to retrieve the response (dependent) variable
from a probit regression object (as much as model.matrix(obj)
retrieves the data matrix). Below is a self-runnable set of codes.
Thank you!

library(sampleSelection)
data<-read.csv("https://dl.dropboxusercontent.com/u/220037024/Yen/data/pta.csv;)
eq1<-d~sex+age+educ
p1<-probit(eq1,data=data)
summary(p1)
attributes(p1)

__
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] Order of bars w geom_errorbarh ??

2016-05-02 Thread Judson Blake
Using geom_errorbarh with ggplot, my plot has several error bars.   For my
presentation, the order of these bars from top to bottom is important.
But errorbarh seems to put these in a random order I can't change.  ( It
does not follow the order in the data.frame. )How can I specify the
order of the bars?   Could I also specify the thickness of the bar lines?

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