Re: [R] How to do t.test to rows of a dataframe using apply family function?

2014-08-26 Thread PIKAL Petr
Hi

If your function works for you why to bother with apply? If it does not give 
you required results, please post some data and show us what is expected.

I would remove unlist from your function and declare list for storing data, 
which seems to me more natural for storing results.

t.test.list=function(df,paired){
   lll-vector(list, length=nrow(df))
   for(i in 1:nrow(df)){

 lll[[i]]=t.test(df[i,grp1],df[i,grp2],paired=paired)
   }
  names(lll)=rownames(df)
   lll
 }

Regards
Petr


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of my1stbox
 Sent: Tuesday, August 26, 2014 3:26 AM
 To: R Help
 Subject: [R] How to do t.test to rows of a dataframe using apply family
 function?

 Hi All,
 How to do t.test  to rows (with two levels, or in other words, groups
 of samples) of a dataframe using apply family function? I have done
 that using function and loops. And my overall purpose is to calculate
 DE genes from two groups of miRNA microarray samples. And I know limma
 can do that, but it seems limma doesn't support paired t-test.

 t.test.df=function(df,paired){
   df.t=c()
   for(i in 1:nrow(df)){

 df.t=rbind(df.t,unlist(t.test(df[i,grp1],df[i,grp2],paired=paired)))
   }
   rownames(df.t)=rownames(df)
   df.t
 }

 Bests!
 Allen Chiu

 2014-08-26
   [[alternative HTML version deleted]]

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


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
https://stat.ethz.ch/mailman/listinfo/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] yaxs Causes Boundary Line Colour to Change

2014-08-26 Thread Patrick Connolly
I can't reproduce it either using x11 or pdf devices.  I'm curious to
know just how you manage to get that result.


On Mon, 25-Aug-2014 at 10:15AM -0400, Sarah Goslee wrote:

| I can't reproduce this on R 3.1.0 on linux or R 3.1.1 on Mac, using
| the default graphics device on each.
| 
| What graphics device are you using?
| 
| If all else fails, you could use box() to draw over it.
| 
| Sarah
| 
| On Mon, Aug 25, 2014 at 8:00 AM, Dario Strbenac
| dstr7...@uni.sydney.edu.au wrote:
|  Why is the bottom boundary plotted in a different colour to the other 
three sides ?
| 
|  set.seed()
|  data - rpois(10, 2)
|  plot(density(data), ann = FALSE, yaxs = 'i') # Grey bottom boundary.
|  plot(density(data), ann = FALSE) # All boundaries are black.
| 
|  Ideally, there would be black lines on all four sides. The documentation 
doesn't say the colour will change.
| 
|  sessionInfo()
|  R version 3.1.1 (2014-07-10)
|  Platform: x86_64-unknown-linux-gnu (64-bit)
| 
|  --
|  Dario Strbenac
|  PhD Student
|  University of Sydney
|  Camperdown NSW 2050
|  Australia
| 
|  __
|  R-help@r-project.org mailing list
|  https://stat.ethz.ch/mailman/listinfo/r-help
|  PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
|  and provide commented, minimal, self-contained, reproducible code.
| 
| 
| 
| -- 
| Sarah Goslee
| http://www.functionaldiversity.org
| 
| __
| R-help@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-help
| PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
| and provide commented, minimal, self-contained, reproducible code.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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


[R] VennDiagram

2014-08-26 Thread Jurgens de Bruin
Hi,

I am new to R and dont use it very often so I would appreciate some help.

I would like to create a VennDiagram based on the following, I have
analyzed experimental results using different methods and captured the
results of each analysis.
I would like the VennDiagram to show the overlap in results for the
different analysis.

Sample data:
 Analysis   Results
   A  1-5
   B   8-9
   C   4-7
   B   1-5
   A   20-50
   C   8-9

So in this simple example analysis A and B have a single sample overlap and
Analysis B and C also have a single overlap but C and A have no overlap.


-- 
Regards/Groete/Mit freundlichen Grüßen/recuerdos/meilleures salutations/
distinti saluti/siong/duì yú/привет

Jurgens de Bruin

[[alternative HTML version deleted]]

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


Re: [R] VennDiagram

2014-08-26 Thread João Azevedo Patrício

Em 26-08-2014 09:30, Jurgens de Bruin escreveu:

Hi,

I am new to R and dont use it very often so I would appreciate some help.

I would like to create a VennDiagram based on the following, I have
analyzed experimental results using different methods and captured the
results of each analysis.
I would like the VennDiagram to show the overlap in results for the
different analysis.

Sample data:
  Analysis   Results
A  1-5
B   8-9
C   4-7
B   1-5
A   20-50
C   8-9

So in this simple example analysis A and B have a single sample overlap and
Analysis B and C also have a single overlap but C and A have no overlap.



Hi,

I don't know how to do it, but made a search and found this, see if it 
helps you


http://www.ats.ucla.edu/stat/r/faq/venn.htm

--
João Azevedo Patrício
Tel.: +31 91 400 53 63
Portugal
@ http://tripaforra.bl.ee

Take 2 seconds to think before you act

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


Re: [R] VennDiagram

2014-08-26 Thread Jurgens de Bruin
Hi,,
Thanks for the link, I have tried that but it seems my data is in the wrong
format for that to work.


On 26 August 2014 10:35, João Azevedo Patrício joao.patri...@gmx.pt wrote:

 Em 26-08-2014 09:30, Jurgens de Bruin escreveu:

  Hi,

 I am new to R and dont use it very often so I would appreciate some help.

 I would like to create a VennDiagram based on the following, I have
 analyzed experimental results using different methods and captured the
 results of each analysis.
 I would like the VennDiagram to show the overlap in results for the
 different analysis.

 Sample data:
   Analysis   Results
 A  1-5
 B   8-9
 C   4-7
 B   1-5
 A   20-50
 C   8-9

 So in this simple example analysis A and B have a single sample overlap
 and
 Analysis B and C also have a single overlap but C and A have no overlap.


  Hi,

 I don't know how to do it, but made a search and found this, see if it
 helps you

 http://www.ats.ucla.edu/stat/r/faq/venn.htm

 --
 João Azevedo Patrício
 Tel.: +31 91 400 53 63
 Portugal
 @ http://tripaforra.bl.ee

 Take 2 seconds to think before you act

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




-- 
Regards/Groete/Mit freundlichen Grüßen/recuerdos/meilleures salutations/
distinti saluti/siong/duì yú/привет

Jurgens de Bruin

[[alternative HTML version deleted]]

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


[R] What would a typical miRNA microarray analysis workflow look like?

2014-08-26 Thread my1stbox
Hi all,
What would a typical miRNA microarray analysis workflow look like? Say just a 
test group of 5 replicates from bladder cancer tumor and corresponding control 
group from normal tissue of the same patients. What could I do to make the 
analysis seems more sophisticated. I have done differential expression 
analysis, target gene prediction, and GO, pathway enrichments of target genes. 
What else could I do? It would be better if you can specify some packages or 
codes.
Regards,
Allen

PS: Is paired (t)-test necessery? I found that DE gene number from paired 
t-test is about half of that from normal limma functions( which I don't know 
how to do paired test if it could).

2014-08-26
[[alternative HTML version deleted]]

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


Re: [R] How to do t.test to rows of a dataframe using apply family function?

2014-08-26 Thread PIKAL Petr
Hi
Please reply also to rhelp, maybe others can offer better answer.
Well, are you aware that by unlist you get all results as character values and 
not numbers?
Personally I would use lapply and do.call on final result to get it as data 
frame.
Here is example
Some model list data
lll-vector(list,length=2)
lll
[[1]]
NULL
[[2]]
NULL
lll[[1]]-t.test(rnorm(20), rnorm(20))
lll[[2]]-t.test(rnorm(20), rnorm(20))
str(unlist(lll))
Named chr [1:22] 0.0091599930484716 37.9972278626102 ...
- attr(*, names)= chr [1:22] statistic.t parameter.df p.value 
conf.int1 ...
do.call(rbind, lapply(lll, rbind))
 statistic   parameter p.value   conf.int  estimate  null.value alternative
[1,] 0.009159993 37.99723  0.9927394 Numeric,2 Numeric,2 0  two.sided
[2,] 0.1256267   32.93057  0.9007913 Numeric,2 Numeric,2 0  two.sided
 methoddata.name
[1,] Welch Two Sample t-test rnorm(20) and rnorm(20)
[2,] Welch Two Sample t-test rnorm(20) and rnorm(20)
Regards
Petr

From: my1stbox [mailto:my1st...@163.com]
Sent: Tuesday, August 26, 2014 10:44 AM
To: PIKAL Petr
Subject: Re: RE: [R] How to do t.test to rows of a dataframe using apply family 
function?

Hi Petr,
Thank you! I use unlist() and rbind() because I want the result to be in the 
form of a matrix.
Regards
Allen

2014-08-26



发件人:PIKAL Petr petr.pi...@precheza.czmailto:petr.pi...@precheza.cz
发送时间:2014-08-26 14:33
主题:RE: [R] How to do t.test to rows of a dataframe using apply family function?
收件人:my1stboxmy1st...@163.commailto:my1st...@163.com,R 
Helpr-help@r-project.orgmailto:r-help@r-project.org
抄送:

Hi

If your function works for you why to bother with apply? If it does not give 
you required results, please post some data and show us what is expected.

I would remove unlist from your function and declare list for storing data, 
which seems to me more natural for storing results.

t.test.list=function(df,paired){
   lll-vector(list, length=nrow(df))
   for(i in 1:nrow(df)){

 lll[[i]]=t.test(df[i,grp1],df[i,grp2],paired=paired)
   }
  names(lll)=rownames(df)
   lll
 }

Regards
Petr


 -Original Message-
 From: r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org 
 [mailto:r-help-bounces@r-
 project.org] On Behalf Of my1stbox
 Sent: Tuesday, August 26, 2014 3:26 AM
 To: R Help
 Subject: [R] How to do t.test to rows of a dataframe using apply family
 function?

 Hi All,
 How to do t.test  to rows (with two levels, or in other words, groups
 of samples) of a dataframe using apply family function? I have done
 that using function and loops. And my overall purpose is to calculate
 DE genes from two groups of miRNA microarray samples. And I know limma
 can do that, but it seems limma doesn't support paired t-test.

 t.test.df=function(df,paired){
   df.t=c()
   for(i in 1:nrow(df)){

 df.t=rbind(df.t,unlist(t.test(df[i,grp1],df[i,grp2],paired=paired)))
   }
   rownames(df.t)=rownames(df)
   df.t
 }

 Bests!
 Allen Chiu

 2014-08-26
   [[alternative HTML version deleted]]

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


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 

Re: [R] How to do t.test to rows of a dataframe using apply family function?

2014-08-26 Thread my1stbox
Thank you so much!
Why do do.call(rbind,lapply(lll,rbind)) and rbind(lapply(lll,rbind)) act so 
differently? What is the tricky part of that?
 do.call(rbind,lapply(lll,rbind))
statistic parameter p.value conf.int estimate null.value alternative
[1,] 2.775282 37.99977 0.008509272 Numeric,2 Numeric,2 0 two.sided
[2,] -1.498133 37.31294 0.1425116 Numeric,2 Numeric,2 0 two.sided
method data.name 
[1,] Welch Two Sample t-test rnorm(20) and rnorm(20)
[2,] Welch Two Sample t-test rnorm(20) and rnorm(20)
 rbind(lapply(lll,rbind))
[,1] [,2] 
[1,] List,9 List,9

2014-08-26 






发件人:PIKAL Petr petr.pi...@precheza.cz
发送时间:2014-08-26 17:58
主题:RE: RE: [R] How to do t.test to rows of a dataframe using apply family 
function?
收件人:my1stboxmy1st...@163.com
抄送:R Helpr-help@r-project.org

Hi
Please reply also to rhelp, maybe others can offer better answer.
Well, are you aware that by unlist you get all results as character values and 
not numbers?
Personally I would use lapply and do.call on final result to get it as data 
frame.
Here is example
Some model list data
lll-vector(list,length=2)
lll
[[1]]
NULL
[[2]]
NULL
lll[[1]]-t.test(rnorm(20), rnorm(20))
lll[[2]]-t.test(rnorm(20), rnorm(20))
str(unlist(lll))
Named chr [1:22] 0.0091599930484716 37.9972278626102 ...
- attr(*, names)= chr [1:22] statistic.t parameter.df p.value 
conf.int1 ...
do.call(rbind, lapply(lll, rbind))
 statistic   parameter p.value   conf.int  estimate  null.value alternative
[1,] 0.009159993 37.99723  0.9927394 Numeric,2 Numeric,2 0  two.sided
[2,] 0.1256267   32.93057  0.9007913 Numeric,2 Numeric,2 0  two.sided
 methoddata.name
[1,] Welch Two Sample t-test rnorm(20) and rnorm(20)
[2,] Welch Two Sample t-test rnorm(20) and rnorm(20)
Regards
Petr

From: my1stbox [mailto:my1st...@163.com] 
Sent: Tuesday, August 26, 2014 10:44 AM
To: PIKAL Petr
Subject: Re: RE: [R] How to do t.test to rows of a dataframe using apply family 
function?

Hi Petr,
Thank you! I use unlist() and rbind() because I want the result to be in the 
form of a matrix.
Regards
Allen

2014-08-26 







发件人:PIKAL Petr petr.pi...@precheza.cz
发送时间:2014-08-26 14:33
主题:RE: [R] How to do t.test to rows of a dataframe using apply family function?
收件人:my1stboxmy1st...@163.com,R Helpr-help@r-project.org
抄送:

Hi 

If your function works for you why to bother with apply? If it does not give 
you required results, please post some data and show us what is expected. 

I would remove unlist from your function and declare list for storing data, 
which seems to me more natural for storing results. 

t.test.list=function(df,paired){ 
   lll-vector(list, length=nrow(df)) 
   for(i in 1:nrow(df)){ 

 lll[[i]]=t.test(df[i,grp1],df[i,grp2],paired=paired) 
   } 
  names(lll)=rownames(df) 
   lll 
 } 

Regards 
Petr 


 -Original Message- 
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- 
 project.org] On Behalf Of my1stbox 
 Sent: Tuesday, August 26, 2014 3:26 AM 
 To: R Help 
 Subject: [R] How to do t.test to rows of a dataframe using apply family 
 function? 
 
 Hi All, 
 How to do t.test  to rows (with two levels, or in other words, groups 
 of samples) of a dataframe using apply family function? I have done 
 that using function and loops. And my overall purpose is to calculate 
 DE genes from two groups of miRNA microarray samples. And I know limma 
 can do that, but it seems limma doesn't support paired t-test. 
 
 t.test.df=function(df,paired){ 
   df.t=c() 
   for(i in 1:nrow(df)){ 
 
 df.t=rbind(df.t,unlist(t.test(df[i,grp1],df[i,grp2],paired=paired))) 
   } 
   rownames(df.t)=rownames(df) 
   df.t 
 } 
 
 Bests! 
 Allen Chiu 
 
 2014-08-26 
   [[alternative HTML version deleted]] 
 
 __ 
 R-help@r-project.org mailing list 
 https://stat.ethz.ch/mailman/listinfo/r-help 
 PLEASE do read the posting guide http://www.R-project.org/posting- 
 guide.html 
 and provide commented, minimal, self-contained, reproducible code. 

 
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 

Re: [R] How to do t.test to rows of a dataframe using apply family function?

2014-08-26 Thread PIKAL Petr
Hi
That is because do.call is one function and rbind another. For both functions 
you can find its help page and read:
rbind
vectors or matrices. These can be given as named arguments. Other R objects 
will be coerced as appropriate: see sections ‘Details’ and ‘Value’.

The type of a matrix result determined from the highest type of any of the 
inputs in the hierarchy raw  logical  integer  double  complex  character 
 list .
do.call
what

either a function or a non-empty character string naming the function to be 
called.

args

a list of arguments to the function call. The names attribute of args gives the 
argument names.

Actually inner lapply was not necessary and simple
do.call(rbind, lll)
gives the same result.
From what I understand from help page, when argument in rbind is list of lists 
it returns matrix of lists which are printed as
[,1]   [,2]
lll List,9 List,9
do.call takes rbind and uses it on each node of list and this node is coerced 
to matrix, which is suitable for changing to data frame.
as.data.frame(do.call(rbind, lll))
It is some magic of R which I use although I do not know much about its 
internals. If you are interested, the source code is available.
Regards
Petr
From: my1stbox [mailto:my1st...@163.com]
Sent: Tuesday, August 26, 2014 12:24 PM
To: PIKAL Petr
Cc: R Help
Subject: Re: RE: RE: [R] How to do t.test to rows of a dataframe using apply 
family function?

Thank you so much!
Why do do.call(rbind,lapply(lll,rbind)) and rbind(lapply(lll,rbind)) act so 
differently? What is the tricky part of that?
 do.call(rbind,lapply(lll,rbind))
statistic parameter p.value conf.int estimate null.value alternative
[1,] 2.775282 37.99977 0.008509272 Numeric,2 Numeric,2 0 two.sided
[2,] -1.498133 37.31294 0.1425116 Numeric,2 Numeric,2 0 two.sided
method data.name
[1,] Welch Two Sample t-test rnorm(20) and rnorm(20)
[2,] Welch Two Sample t-test rnorm(20) and rnorm(20)
 rbind(lapply(lll,rbind))
[,1] [,2]
[1,] List,9 List,9

2014-08-26



发件人:PIKAL Petr petr.pi...@precheza.czmailto:petr.pi...@precheza.cz
发送时间:2014-08-26 17:58
主题:RE: RE: [R] How to do t.test to rows of a dataframe using apply family 
function?
收件人:my1stboxmy1st...@163.commailto:my1st...@163.com
抄送:R Helpr-help@r-project.orgmailto:r-help@r-project.org

Hi
Please reply also to rhelp, maybe others can offer better answer.
Well, are you aware that by unlist you get all results as character values and 
not numbers?
Personally I would use lapply and do.call on final result to get it as data 
frame.
Here is example
Some model list data
lll-vector(list,length=2)
lll
[[1]]
NULL
[[2]]
NULL
lll[[1]]-t.test(rnorm(20), rnorm(20))
lll[[2]]-t.test(rnorm(20), rnorm(20))
str(unlist(lll))
Named chr [1:22] 0.0091599930484716 37.9972278626102 ...
- attr(*, names)= chr [1:22] statistic.t parameter.df p.value 
conf.int1 ...
do.call(rbind, lapply(lll, rbind))
 statistic   parameter p.value   conf.int  estimate  null.value alternative
[1,] 0.009159993 37.99723  0.9927394 Numeric,2 Numeric,2 0  two.sided
[2,] 0.1256267   32.93057  0.9007913 Numeric,2 Numeric,2 0  two.sided
 methoddata.name
[1,] Welch Two Sample t-test rnorm(20) and rnorm(20)
[2,] Welch Two Sample t-test rnorm(20) and rnorm(20)
Regards
Petr

From: my1stbox [mailto:my1st...@163.com]
Sent: Tuesday, August 26, 2014 10:44 AM
To: PIKAL Petr
Subject: Re: RE: [R] How to do t.test to rows of a dataframe using apply family 
function?

Hi Petr,
Thank you! I use unlist() and rbind() because I want the result to be in the 
form of a matrix.
Regards
Allen

2014-08-26



发件人:PIKAL Petr petr.pi...@precheza.czmailto:petr.pi...@precheza.cz
发送时间:2014-08-26 14:33
主题:RE: [R] How to do t.test to rows of a dataframe using apply family function?
收件人:my1stboxmy1st...@163.commailto:my1st...@163.com,R 
Helpr-help@r-project.orgmailto:r-help@r-project.org
抄送:

Hi

If your function works for you why to bother with apply? If it does not give 
you required results, please post some data and show us what is expected.

I would remove unlist from your function and declare list for storing data, 
which seems to me more natural for storing results.

t.test.list=function(df,paired){
   lll-vector(list, length=nrow(df))
   for(i in 1:nrow(df)){

 lll[[i]]=t.test(df[i,grp1],df[i,grp2],paired=paired)
   }
  names(lll)=rownames(df)
   lll
 }

Regards
Petr


 -Original Message-
 From: r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org 
 [mailto:r-help-bounces@r-
 project.org] On Behalf Of my1stbox
 Sent: Tuesday, August 26, 2014 3:26 AM
 To: R Help
 Subject: [R] How to do t.test to rows of a dataframe using apply family
 function?

 Hi All,
 How to do t.test  to rows (with two levels, or in other words, groups
 of samples) of a dataframe using apply family function? I have done
 that using function and loops. And my overall purpose is to 

Re: [R] VennDiagram

2014-08-26 Thread David L Carlson
Assuming your sample data is called dta:

 table(dta$Results, dta$Analysis)
   
A B C
  1-5   1 1 0
  20-50 1 0 0
  4-7   0 0 1
  8-9   0 1 1


David L. Carlson
Department of Anthropology
Texas AM University


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Jurgens de Bruin
Sent: Tuesday, August 26, 2014 4:08 AM
To: João Azevedo Patrício
Cc: r-help@r-project.org
Subject: Re: [R] VennDiagram

Hi,,
Thanks for the link, I have tried that but it seems my data is in the wrong 
format for that to work.


On 26 August 2014 10:35, João Azevedo Patrício joao.patri...@gmx.pt wrote:

 Em 26-08-2014 09:30, Jurgens de Bruin escreveu:

  Hi,

 I am new to R and dont use it very often so I would appreciate some help.

 I would like to create a VennDiagram based on the following, I have 
 analyzed experimental results using different methods and captured 
 the results of each analysis.
 I would like the VennDiagram to show the overlap in results for the 
 different analysis.

 Sample data:
   Analysis   Results
 A  1-5
 B   8-9
 C   4-7
 B   1-5
 A   20-50
 C   8-9

 So in this simple example analysis A and B have a single sample 
 overlap and Analysis B and C also have a single overlap but C and A 
 have no overlap.


  Hi,

 I don't know how to do it, but made a search and found this, see if it 
 helps you

 http://www.ats.ucla.edu/stat/r/faq/venn.htm

 --
 João Azevedo Patrício
 Tel.: +31 91 400 53 63
 Portugal
 @ http://tripaforra.bl.ee

 Take 2 seconds to think before you act

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




--
Regards/Groete/Mit freundlichen Grüßen/recuerdos/meilleures salutations/ 
distinti saluti/siong/duì yú/привет

Jurgens de Bruin

[[alternative HTML version deleted]]

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


[R] package 'gradientForest' and 'extendedForest'

2014-08-26 Thread Kulupp
Dear experts,

I have 5 environmental predictors and abundance data (300 samples, 60 
species, transformation: log(x + min(x,x  0) and use the function 
'gradientForest' to estimate (R�-weighted) predictor importance 
(regression trees). The resulting predictor importance in decreasing 
order is as follows: pred1, pred2, pred3, pred4, pred5. The two species 
with the highest R� (goodness-of-fit; output value 'result' of function 
'gradientForest') are species 1 (R�=0.76), species 2 (R�=0.74), and 
species 3 (R�=0.72). To my understanding this means that the model (i.e. 
the predictor importance ranking) fits best to species 1, 2, and 3 in 
decreasing order. In a further step I want to know which predictors are 
the most important for selected species. Thus, I ran separate forests 
using the 'extendedForest' function with the same parameter settings 
(and the same set.seed()) as in the function call of 'gradientForest' 
for species 1, 2, and 3 (and others). Now the resulting predictor 
importance is (in decreasing order): species1: pred1, pred2, pred4, 
pred3, pred5; species2: pred1, pred4, pred2, pred5, pred3; species3: 
pred2, pred4, pred5, pred1, pred3. This seems strange to me, because I 
believed that the 'extendedForest' function should give similar 
predictor importance rankings as the 'gradientForest' predictor 
importance ranking for the species with the highest R� values obtained 
by 'gradientForest' . I'd be grateful for any help. Thanks a lot in 
anticipation.

Best regards

Thomas


[[alternative HTML version deleted]]

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


[R] StackRaster problem

2014-08-26 Thread Guilherme Leite
Hi,

This is the process I want to do:

 files - list.files(path=paste(system.file(package=dismo), '/ex',
sep=''), pattern='grd', full.names=TRUE )

 # The above finds all the files with extension grd in the
 # examples (ex) directory of the dismo package. You do not
 # need such a complex statement to get your own files.

 files
[1] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio1.grd
[2] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio12.grd
[3] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio16.grd
[4] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio17.grd
[5] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio5.grd
[6] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio6.grd
[7] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio7.grd
[8] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio8.grd
[9] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/biome.grd

 predictors - stack(files)
 predictors

class : RasterStack
dimensions : 192, 186, 35712, 9 (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5 (x, y)
extent : -125, -32, -56, 40 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
names : bio1, bio12, bio16, bio17, bio5, bio6, bio7, bio8, biome
min values : -23, 0, 0, 0, 61, -212, 60, -66, 1
max values : 289, 7682, 2458, 1496, 422, 242, 461, 323, 14

But what happen is:

 files - list.files(path=paste(system.file(package=dismo), '/ex',
sep=''), pattern='grd', full.names=TRUE )

 files

[1] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio1.grd
[2] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio12.grd
[3] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio16.grd
[4] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio17.grd
[5] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio5.grd
[6] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio6.grd
[7] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio7.grd
[8] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio8.grd
[9] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/biome.grd

 predictors - stack(files)
Error in rep.int(names(x), lapply(x, length)) : invalid 'times' value

Do you know how to fix it?

Thank you,
Guilherme

[[alternative HTML version deleted]]

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


[R] Weighted Mann-Whitney-Wilcoxon-Test

2014-08-26 Thread Alexander Sommer
On Tuesday, August 19, 2014 9:46 PM Thomas Lumley tlum...@uw.edu wrote:

 Is anyone aware of an(other) implementation in R?
 survey::svyranktest

Oh, that easy. Thanks a lot.

Actually, in my case the weights do not derive from some selection 
probabilities, but your test works anyway.


For completeness (and this time with a working example):

set.seed(seed = 123)
count.x - NULL
count.y - NULL
j - 1
for (i in sample(x = 10:20, size = 20, replace = TRUE)){
 count.x[j] - sample(x = 0:i, size = 1)
 count.y[j] - i - count.x[j]
 j  - j + 1
}
data - data.frame(x.portion = (count.x/(count.x + count.y)),
   y.portion = (count.y/(count.x + count.y)),
   group = c(rep(A, 12), rep(B, 8)),
   weight= (count.x + count.y)
  )

I first considered the unweighted case with

library(package = survey)
design - svydesign(ids = ~0, data = data)
svyranktest(formula = x.portion ~ group, design = design)

and compared it to the default Wilcoxon test by

wilcox.test(formula = x.portion ~ group, data = data, exact = FALSE, correct = 
FALSE)

Or, if you prefer

library(package = coin)
wilcox_test(formula = x.portion ~ group, data = data)

The resulting p-values differ, as I understood due to an approximation in 
package /survey/.

Now, finally, the weighted case:

design - svydesign(ids = ~0, data = data, weights = ~weight)
svyranktest(formula = x.portion ~ group, design)

And, by the way, package /survey/ seems also to be the preferable way, if you 
want to go for a parametric test. Once again, the unweighted case first:

design - svydesign(ids = ~0, data = data)
svyttest(formula = x.portion ~ group, design)

And, yet again, the results differ from the default t test

t.test(formula = x.portion ~ group, data = data)

This time, I guess, it is due to the way standard errors are computed.

Finally (this time for real), the weighted case:

design - svydesign(ids = ~0, data = data, weights = ~weight)
svyttest(x.portion ~ group, design)

Note that function /wtd.t.test/ from package /weights/ depends on the scale of 
the weights, /svyttest/ not.


Thomas, one more time: thank you for your help.

Cheers,

Alex


-- 
Alexander Sommer
wissenschaftlicher Mitarbeiter

Technische Universität Dortmund 
Fakultät Erziehungswissenschaft, Psychologie und Soziologie
Forschungsverbund Deutsches Jugendinstitut/Technische Universität Dortmund
Vogelpothsweg 78
44227 Dortmund

Telefon: +49 231 755-8189
Fax: +49 231 755-6553
E-Mail:  alexander.som...@tu-dortmund.de
WWW: http://www.forschungsverbund.tu-dortmund.de/

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


[R] Plot survreg and intcox

2014-08-26 Thread Silong Liao
Dear R users,
I'm trying to plot survival probability against time(in years) using survreg 
and intcox. Please can you help me with this problem?
My code shows 
below:mod.reg1=survreg(s_new~type+sex+eye+preopiop+preopva,dist=weibull)summary(mod.reg1)
Call:survreg(formula = s_new ~ type + sex + eye + preopiop + preopva, dist 
= weibull) Value Std. Error  zp(Intercept) 40.539 
20.582  1.970 4.89e-02typeTrab-6.606  4.279 -1.544 1.23e-01sexM
-1.055  3.765 -0.280 7.79e-01eyeR-2.112  3.587 -0.589 
5.56e-01preopiop-0.308  0.269 -1.147 2.52e-01preopva -0.461  
1.771 -0.260 7.95e-01Log(scale)   2.058  0.285  7.222 5.12e-13
Scale= 7.83 
Weibull distributionLoglik(model)= -78.7   Loglik(intercept only)= -81.4
Chisq= 5.37 on 5 degrees of freedom, p= 0.37 Number of Newton-Raphson 
Iterations: 10 n= 339
-cox.fit=intcox(s_new~type+eye+sex+age+preopiop+preopva,data=glaucoma_new)summary(cox.fit)Call:intcox(formula
 = s_new ~ type + eye + sex + age + preopiop + preopva, data = glaucoma_new)
  n= 339
 coef exp(coef) se(coef)  z Pr(|z|)typeTrab  0.59391   1.81106 
  NA NA   NAeyeR  0.28419   1.32868   NA NA   NAsexM 
-0.11597   0.89050   NA NA   NAage  -0.06556   0.93655   NA NA  
 NApreopiop  0.03903   1.03980   NA NA   NApreopva  -0.05517   
0.94632   NA NA   NA
 exp(coef) exp(-coef) lower .95 upper .95typeTrab1.8111 0.5522  
  NANAeyeR1.3287 0.7526NANAsexM
0.8905 1.1230NANAage 0.9365 1.0678NA
NApreopiop1.0398 0.9617NANApreopva 0.9463 
1.0567NANA
Rsquare= NA   (max possible= 0.327 )Likelihood ratio test= NA  on 6 df,   
p=NAWald test= NA  on 6 df,   p=NAScore (logrank) test = NA  on 6 
df,   p=NA


Kind regards,Sid

  
[[alternative HTML version deleted]]

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


Re: [R] StackRaster problem

2014-08-26 Thread Jon Skoien
Did you attach the raster package with library(raster)? It seems the 
newest version of dismo does not depend on raster, so you will not be 
able to use raster-functions if you only attach dismo.
This error message typically comes when R tries to use 
utils:::stack.default instead of the stack-function defined in the 
raster-package.


If this is not the case, please give the output from sessionInfo().

Cheers,
Jon

On 8/26/2014 3:21 PM, Guilherme Leite wrote:

Hi,

This is the process I want to do:


files - list.files(path=paste(system.file(package=dismo), '/ex',

sep=''), pattern='grd', full.names=TRUE )


# The above finds all the files with extension grd in the
# examples (ex) directory of the dismo package. You do not
# need such a complex statement to get your own files.



files

[1] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio1.grd
[2] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio12.grd
[3] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio16.grd
[4] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio17.grd
[5] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio5.grd
[6] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio6.grd
[7] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio7.grd
[8] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio8.grd
[9] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/biome.grd


predictors - stack(files)
predictors


class : RasterStack
dimensions : 192, 186, 35712, 9 (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5 (x, y)
extent : -125, -32, -56, 40 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
names : bio1, bio12, bio16, bio17, bio5, bio6, bio7, bio8, biome
min values : -23, 0, 0, 0, 61, -212, 60, -66, 1
max values : 289, 7682, 2458, 1496, 422, 242, 461, 323, 14

But what happen is:


files - list.files(path=paste(system.file(package=dismo), '/ex',

sep=''), pattern='grd', full.names=TRUE )


files


[1] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio1.grd
[2] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio12.grd
[3] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio16.grd
[4] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio17.grd
[5] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio5.grd
[6] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio6.grd
[7] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio7.grd
[8] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/bio8.grd
[9] d:/temp/Rtmp8Mttik/Rinst1fe4202d2ea5/dismo/ex/biome.grd


predictors - stack(files)

Error in rep.int(names(x), lapply(x, length)) : invalid 'times' value

Do you know how to fix it?

Thank you,
Guilherme

[[alternative HTML version deleted]]

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



--
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Climate Risk Management Unit

Via Fermi 2749, TP 100-01,  I-21027 Ispra (VA), ITALY

jon.sko...@jrc.ec.europa.eu
Tel:  +39 0332 789205

Disclaimer: Views expressed in this email are those of the individual 
and do not necessarily represent official views of the European Commission.


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


Re: [R] What the difference between .Golbalenv and package:base?

2014-08-26 Thread William Dunlap
as.environment(characterString) maps an entry from the output of
search() to the environment at the named position in the search list.
as.environment(number) maps an index into the output of search() to
the the environment at that position in the search list.  If
'characterString' is not in the output of search() or 'number' is not
in seq_along(search()) then as.environment throws an error.  As far as
I can tell, as.environment does not deal with the name of the
environment at all.  (When you attach an environment, attach will add
a name attribute to the copied environment so the attached
environment's name matches the name on the output of search(), but I
don't think as.environment ever looks at that attribute.)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Aug 25, 2014 at 9:07 PM, PO SU rhelpmaill...@163.com wrote:
 First, sorry for my pool english expression which make you misunderstanding 
 of my original purpose.

 Sometimes, suppose  a object in both stats and base, then i type the object 
 name, then after R search the search() list, R will use the object in stats, 
 is it right?( I just suppose, stats can be any package which libraried into 
 R.)
 Then i know that, .GlobalEnv or globalenv() is the global environment object, 
 baseenv() returns the base environment object.
 I also know that, i can convert the environment name into the real 
 environment object by using stats-as.environment(package:stats),  And the 
 stats environment's name can be obtained using environmentName(stats), but it 
 returns .   (why?)
 Then i use  environmentName(.GlobalEnv) then i get R_GlobalEnv, then i use 
 as.environment(R_GlobalEnv), it does't work.(why?)


 In one word, as.environment(x), x is somthing not the environment's name.


 But, when i add a environment into the search() list, after i 
 attr(newenvir,name)-new_name
 I can use the  as.environment(new_name) to obtain the added environment. 
 (why?)


 Hope you understand my meaning :)












 --

 PO SU
 mail: desolato...@163.com
 Majored in Statistics from SJTU



 At 2014-08-26 02:51:54, MacQueen, Don macque...@llnl.gov wrote:
Put simply,
   .GlobalEnvstores objects you create
   package:base  contains functions and objects provided by R itself

You don¹t need to use   .GlobalEnv$a   to use the variable named a. Just
is ³a² by itself.

 a - 4
 b - 2*a
print(a)
print(b)

Not necessary to use
  print(.GlobalEnv$a)

Similarly, to find an object in the base package, just type its name.

I don¹t know what you are trying to do, or why you think you have to use
.GlobalEnv$a
But in more than 20 years of using R for many different tasks, I have
never had to do that.

Furthermore, if you are new to R (which I would guess is the case), it
seems unlikely to me that you need to work with environments or use
attach() or assign(). In the vast majority of cases there are simpler ways
that are easier to understand.

You are aware, I hope, that
   ls('.GlobalEnv')
   ls(1)
   ls()
all return the same result?


--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 8/24/14, 11:07 PM, PO SU rhelpmaill...@163.com wrote:



Dear rusers,

As we know, there are a lot of environments in the search() path,
such as   .Golbalenv and package:base .
And  i can just use  .Golbalenv$a ,.Golbalenv$b to use the virable,  but
i must use as.envrionment(package:base) to find virable, i feel it not
very convenient.


For example, when i use the following codes to add a new env into the
search() path.



 tmp-attach(NULL,name=new_name)
 assign(a,2,envir=as.environment(new_name))
 a
[1] 2
 as.environment(new_name)$a
[1] 2
 I must always convert the name to the environment, How can i just use
the following form:



 tmp-attach(NULL,name=new_name)
 assign(a,2,envir=new_name)   #like using  .GlobalEnv
 a
[1] 2
 new_name$a

[1] 2







--

PO SU
mail: desolato...@163.com
Majored in Statistics from SJTU
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

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

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


Re: [R] Plot survreg and intcox

2014-08-26 Thread David Winsemius

On Aug 26, 2014, at 4:17 AM, Silong Liao wrote:

 Dear R users,
 I'm trying to plot survival probability against time(in years) using 
 survreg and intcox. Please can you help me with this problem?

That line at the bottom of the message delivered to the list subscribers saying 
that the HTL version was deleted explains why this is such a mess. Please read 
the Posting Guide and post in plain text:

-- 
David.
 My code shows 
 below:mod.reg1=survreg(s_new~type+sex+eye+preopiop+preopva,dist=weibull)summary(mod.reg1)
 Call:survreg(formula = s_new ~ type + sex + eye + preopiop + preopva, 
 dist = weibull) Value Std. Error  zp(Intercept) 
 40.539 20.582  1.970 4.89e-02typeTrab-6.606  4.279 -1.544 
 1.23e-01sexM-1.055  3.765 -0.280 7.79e-01eyeR-2.112  
 3.587 -0.589 5.56e-01preopiop-0.308  0.269 -1.147 2.52e-01preopva 
 -0.461  1.771 -0.260 7.95e-01Log(scale)   2.058  0.285  7.222 5.12e-13
 Scale= 7.83 
 Weibull distributionLoglik(model)= -78.7   Loglik(intercept only)= -81.4  
 Chisq= 5.37 on 5 degrees of freedom, p= 0.37 Number of Newton-Raphson 
 Iterations: 10 n= 339
 -cox.fit=intcox(s_new~type+eye+sex+age+preopiop+preopva,data=glaucoma_new)summary(cox.fit)Call:intcox(formula
  = s_new ~ type + eye + sex + age + preopiop + preopva, data = 
 glaucoma_new)
  n= 339
 coef exp(coef) se(coef)  z Pr(|z|)typeTrab  0.59391   1.81106
NA NA   NAeyeR  0.28419   1.32868   NA NA   NAsexM 
 -0.11597   0.89050   NA NA   NAage  -0.06556   0.93655   NA 
 NA   NApreopiop  0.03903   1.03980   NA NA   NApreopva  -0.05517  
  0.94632   NA NA   NA
 exp(coef) exp(-coef) lower .95 upper .95typeTrab1.8111 0.5522 
NANAeyeR1.3287 0.7526NANAsexM  
   0.8905 1.1230NANAage 0.9365 1.0678
 NANApreopiop1.0398 0.9617NANApreopva 
 0.9463 1.0567NANA
 Rsquare= NA   (max possible= 0.327 )Likelihood ratio test= NA  on 6 df,   
 p=NAWald test= NA  on 6 df,   p=NAScore (logrank) test = NA  on 6 
 df,   p=NA
 
 
 Kind regards,Sid
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

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


[R] buit a package using Rstudio and existing R files

2014-08-26 Thread Karim Mezhoud
Dear All,
I am trying to built for the first time a package. I am following this
tutorial:
https://support.rstudio.com/hc/en-us/articles/200486488-Developing-Packages-with-RStudio

I create a new Project (package) and I added 44 .R sources files
(functions).
After, I got error message when I built and reload the project (please, see
bellow).

Any suggestion?

I need to fill the doc informations (title, manual, vignette, description).
Can I do these directly from Rd files located in Man folder?
Thanks!

Karim

#00install.out
* installing *source* package ‘CanceR’ ...
** R
** preparing package for lazy loading
** help
Warning:
/home/mezhoud/CGDS-R/CanceR.Rcheck/00_pkg_src/CanceR/man/CanceR-package.Rd:33:
All text must be in a section
Warning:
/home/mezhoud/CGDS-R/CanceR.Rcheck/00_pkg_src/CanceR/man/CanceR-package.Rd:34:
All text must be in a section
Warning:
/home/mezhoud/CGDS-R/CanceR.Rcheck/00_pkg_src/CanceR/man/CanceR-package.Rd:35:
All text must be in a section
*** installing help indices
Error in Rd_info(db[[i]]) :
  missing/empty \title field in
'/home/mezhoud/CGDS-R/CanceR.Rcheck/00_pkg_src/CanceR/man/CanceR.Rd'
Rd files must have a non-empty \title.
See chapter 'Writing R documentation' in manual 'Writing R Extensions'.
* removing ‘/home/mezhoud/CGDS-R/CanceR.Rcheck/CanceR’

###CanceR-package.Rd  #

\name{CanceR-package}
\alias{CanceR-package}
\alias{CanceR}
\docType{package}
\title{
What the package does (short line)
~~ package title ~~
}
\description{
More about what it does (maybe more than one line)
~~ A concise (1-5 lines) description of the package ~~
}
\details{
\tabular{ll}{
Package: \tab CanceR\cr
Type: \tab Package\cr
Version: \tab 1.0\cr
Date: \tab 2014-08-26\cr
License: \tab What license is it under?\cr
}
~~ An overview of how to use the package, ~~
~~ including the most important functions ~~
}
\author{
Who wrote it

Maintainer: Who to complain to yourfa...@somewhere.net
~~ The author and/or maintainer of the package ~~
}
\references{
~~ Literature or other references for background information ~~
}
~~ Optionally other standard keywords, ~~
~~ one per line, from file KEYWORDS in ~~
~~ the R documentation directory ~~
\keyword{ package }
\seealso{
~~ Optional links to other man pages, e.g. ~~
~~ \code{\link[pkg:pkg-package]{pkg}} ~~
}
\examples{
~~ simple examples of the most important functions ~~
}

[[alternative HTML version deleted]]

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


Re: [R] Help with lsmeans

2014-08-26 Thread Ben Bolker
Dan Dillon dgdillon at gmail.com writes:

 
 Colleagues:
 

 [snip]

 
 My data are from a behavioral experiment in which two groups of subjects
 complete 200+ trials of a task with two conditions. Each subject is tested
 in one of four separate locations. I record accuracy (0 or 1) and response
 time (RT) on each trial--these are the DVs for the two regressions. Thus,
 my dataframe has columns location, group, subject, trial,
 condition, accuracy, and RT.
 
 The regression model for accuracy looks like this:
 
 acc.fm = glmer(accuracy ~ location + group*condition + (1|subject),
 family=binomial, data=my_data)
 
 The results look as expected and I'm using lsmeans to do some follow-up
 analyses. For example, to compare accuracy by group and condition, I'm
 doing this:
 
 acc.lsm - lsmeans(acc.fm, ~group|condition)
 
 pairs(acc.lsm)
 


 [snip]

 Here is my model for the RT data
 (RT is a continuous variable so no logistic regression here):
 
 rt.fm = lmer(rt ~ location + group*condition*accuracy + (1|subject),
 data=my_data)
 
 The results from this regression look fine, but if I try this . . .
 
 rt.lsm - lsmeans(rt.fm ~ group|condition)
 
 . . . or if I try to specify a reference grid like this . . .
 
 rt.rg - ref.grid(rt.fm)
 
 . . . my machine hangs.
 

  [snip]

  It's a little hard to say without a reproducible example, and
this question would probably be slightly more appropriate for
r-sig-mixed-mod...@r-project.org (although I can't actually tell
for sure whether it is an lme4-specific problem or a more general
ls.means::ref.grid question), but: how big a reference is ref.grid()
trying to construct?  Is it fairly high-resolution/high-dimensional?
I would probably try some experiments with small subsets of your data
to see how the results scale.

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


Re: [R] buit a package using Rstudio and existing R files

2014-08-26 Thread Jeff Newmiller
I would suggest building your first package with as few functions as you can 
(one?). Once you get that working, try adding more functions and keep 
rebuilding as you go so the error messages don't drown you. In any event, your 
immediate problem is that CanceR-package.Rd has not been properly edited.

You should take the advice given in your error message and read the Writing R 
Extensions manual. While there are some shortcuts such as roxygen to creating 
the required files, when things go wrong the errors will generally be about 
files that are documented in the WRE document.

You should also read the Posting Guide which among other things mentions that 
this is a plain text mailing list. We are more likely to be able to decipher 
your email if you don't let your email program format it as HTML.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On August 26, 2014 11:45:07 AM PDT, Karim Mezhoud kmezh...@gmail.com wrote:
Dear All,
I am trying to built for the first time a package. I am following this
tutorial:
https://support.rstudio.com/hc/en-us/articles/200486488-Developing-Packages-with-RStudio

I create a new Project (package) and I added 44 .R sources files
(functions).
After, I got error message when I built and reload the project (please,
see
bellow).

Any suggestion?

I need to fill the doc informations (title, manual, vignette,
description).
Can I do these directly from Rd files located in Man folder?
Thanks!

Karim

#00install.out
* installing *source* package ‘CanceR’ ...
** R
** preparing package for lazy loading
** help
Warning:
/home/mezhoud/CGDS-R/CanceR.Rcheck/00_pkg_src/CanceR/man/CanceR-package.Rd:33:
All text must be in a section
Warning:
/home/mezhoud/CGDS-R/CanceR.Rcheck/00_pkg_src/CanceR/man/CanceR-package.Rd:34:
All text must be in a section
Warning:
/home/mezhoud/CGDS-R/CanceR.Rcheck/00_pkg_src/CanceR/man/CanceR-package.Rd:35:
All text must be in a section
*** installing help indices
Error in Rd_info(db[[i]]) :
  missing/empty \title field in
'/home/mezhoud/CGDS-R/CanceR.Rcheck/00_pkg_src/CanceR/man/CanceR.Rd'
Rd files must have a non-empty \title.
See chapter 'Writing R documentation' in manual 'Writing R Extensions'.
* removing ‘/home/mezhoud/CGDS-R/CanceR.Rcheck/CanceR’

###CanceR-package.Rd  #

\name{CanceR-package}
\alias{CanceR-package}
\alias{CanceR}
\docType{package}
\title{
What the package does (short line)
~~ package title ~~
}
\description{
More about what it does (maybe more than one line)
~~ A concise (1-5 lines) description of the package ~~
}
\details{
\tabular{ll}{
Package: \tab CanceR\cr
Type: \tab Package\cr
Version: \tab 1.0\cr
Date: \tab 2014-08-26\cr
License: \tab What license is it under?\cr
}
~~ An overview of how to use the package, ~~
~~ including the most important functions ~~
}
\author{
Who wrote it

Maintainer: Who to complain to yourfa...@somewhere.net
~~ The author and/or maintainer of the package ~~
}
\references{
~~ Literature or other references for background information ~~
}
~~ Optionally other standard keywords, ~~
~~ one per line, from file KEYWORDS in ~~
~~ the R documentation directory ~~
\keyword{ package }
\seealso{
~~ Optional links to other man pages, e.g. ~~
~~ \code{\link[pkg:pkg-package]{pkg}} ~~
}
\examples{
~~ simple examples of the most important functions ~~
}

   [[alternative HTML version deleted]]

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

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


[R] plot for survreg and intcox (rewritten)

2014-08-26 Thread Silong Liao
Dear R users,

I'm trying to plot survival probability against time(in years) using survreg 
and intcox. Please can you help me with this problem? (I have rewritten using 
plain text.) I tried to use curve function but have no clue.

For survreg,
mod.reg1=survreg(s_new~type+sex+eye+preopiop+preopva,dist=weibull)
summary(mod.reg1)
Call:
survreg(formula = s_new ~ type + sex + eye + preopiop + preopva, dist = 
weibull)
Value Std. Error z p
(Intercept) 40.539 20.582 1.970 4.89e-02
typeTrab -6.606 4.279 -1.544 1.23e-01
sexM -1.055 3.765 -0.280 7.79e-01
eyeR -2.112 3.587 -0.589 5.56e-01
preopiop -0.308 0.269 -1.147 2.52e-01
preopva -0.461 1.771 -0.260 7.95e-01
Log(scale) 2.058 0.285 7.222 5.12e-13

Scale= 7.83
Weibull distribution
Loglik(model)= -78.7 Loglik(intercept only)= -81.4
Chisq= 5.37 on 5 degrees of freedom, p= 0.37
Number of Newton-Raphson Iterations: 10
n= 339

For intcox,
cox.fit=intcox(s_new~type+eye+sex+age+preopiop+preopva,data=glaucoma_new)
summary(cox.fit)
Call:
intcox(formula = s_new ~ type + eye + sex + age + preopiop +preopva, data = 
glaucoma_new)

n= 339

coef exp(coef) se(coef) z Pr(|z|)
typeTrab 0.59391 1.81106 NA NA NA
eyeR 0.28419 1.32868 NA NA NA
sexM -0.11597 0.89050 NA NA NA
age -0.06556 0.93655 NA NA NA
preopiop 0.03903 1.03980 NA NA NA
preopva -0.05517 0.94632 NA NA NA

exp(coef) exp(-coef) lower .95 upper .95
typeTrab 1.8111 0.5522 NA NA
eyeR 1.3287 0.7526 NA NA
sexM 0.8905 1.1230 NA NA
age 0.9365 1.0678 NA NA
preopiop 1.0398 0.9617 NA NA
preopva 0.9463 1.0567 NA NA

Rsquare= NA (max possible= 0.327 )
Likelihood ratio test= NA on 6 df, p=NA
Wald test = NA on 6 df, p=NA
Score (logrank) test = NA on 6 df, p=NA
  
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] plot for survreg and intcox (rewritten)

2014-08-26 Thread David Winsemius

On Aug 26, 2014, at 2:33 PM, Silong Liao wrote:

 Dear R users,
 
 I'm trying to plot survival probability against time(in years) using 
 survreg and intcox. Please can you help me with this problem? (I have 
 rewritten using plain text.) I tried to use curve function but have no clue.
 

I suspect you want survfit (in the survial package which is where I suspect 
survreg is coming from. It returns an object that has a plot method. You could 
also scroll through help(pack=survival) to see other plotting functions.

You could also use survest in the rms package.

 For survreg,
 mod.reg1=survreg(s_new~type+sex+eye+preopiop+preopva,dist=weibull)
 summary(mod.reg1)
 Call:
 survreg(formula = s_new ~ type + sex + eye + preopiop + preopva, dist = 
 weibull)
 Value Std. Error z p
 (Intercept) 40.539 20.582 1.970 4.89e-02
 typeTrab -6.606 4.279 -1.544 1.23e-01
 sexM -1.055 3.765 -0.280 7.79e-01
 eyeR -2.112 3.587 -0.589 5.56e-01
 preopiop -0.308 0.269 -1.147 2.52e-01
 preopva -0.461 1.771 -0.260 7.95e-01
 Log(scale) 2.058 0.285 7.222 5.12e-13
 
 Scale= 7.83
 Weibull distribution
 Loglik(model)= -78.7 Loglik(intercept only)= -81.4
 Chisq= 5.37 on 5 degrees of freedom, p= 0.37
 Number of Newton-Raphson Iterations: 10
 n= 339
 
 For intcox,

You are asked to provide the package name  for functions that are not in the 
base or default packages. I have quite a few packages loaded including 
survival_2.37-7 , coxme_2.2-3, and rms_4.2-0  but I get:

 ?intcox
No documentation for ‘intcox’ in specified packages and libraries:
you could try ‘??intcox’
 

-- 
David.


 
 cox.fit=intcox(s_new~type+eye+sex+age+preopiop+preopva,data=glaucoma_new)
 summary(cox.fit)
 Call:
 intcox(formula = s_new ~ type + eye + sex + age + preopiop +preopva, data = 
 glaucoma_new)
 
 n= 339
 
 coef exp(coef) se(coef) z Pr(|z|)
 typeTrab 0.59391 1.81106 NA NA NA
 eyeR 0.28419 1.32868 NA NA NA
 sexM -0.11597 0.89050 NA NA NA
 age -0.06556 0.93655 NA NA NA
 preopiop 0.03903 1.03980 NA NA NA
 preopva -0.05517 0.94632 NA NA NA
 
 exp(coef) exp(-coef) lower .95 upper .95
 typeTrab 1.8111 0.5522 NA NA
 eyeR 1.3287 0.7526 NA NA
 sexM 0.8905 1.1230 NA NA
 age 0.9365 1.0678 NA NA
 preopiop 1.0398 0.9617 NA NA
 preopva 0.9463 1.0567 NA NA
 
 Rsquare= NA (max possible= 0.327 )
 Likelihood ratio test= NA on 6 df, p=NA
 Wald test = NA on 6 df, p=NA
 Score (logrank) test = NA on 6 df, p=NA
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

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


[R] lattice: packet.number() versus panel.number()

2014-08-26 Thread Benjamin Tyner
Hi,

According to
https://svn.r-project.org/R-packages/trunk/lattice/R/print.trellis.R,

[panel.number] is usually the same as, but can be different from
packet.number

and I had been under the impression that as long as the user is not
using a custom index.cond nor perm.cond, the panel.number would in fact
be the same as the packet.number.

However, I have recently come across a case where the two are *not* the
same, even though I am not using a custom index.cond nor perm.cond.

So my question is, what might be some other possible situations in which
the two would be expected to differ?

Regards,
Ben

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


[R] Clip smaller domain from large domain netCDF file

2014-08-26 Thread Aseem Sharma
Hi,
I have this huge ( ~30GB) .nc file (NC_FORMAT_NETCDF4_CLASSIC)) for the
whole country 141.00 to 52.00 W, 41.00 to 84.00 N.
I am trying to clip this big dataset for a small region specific domain
(120.00 to 130.00 W, 50.00 to 60.00 N).
I am trying to do using netCDF4 r package but could not figure out how to
do so.
Kindly please suggest me how should i proceed.


Thank you,

[[alternative HTML version deleted]]

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


[R] Mixed sorting/ordering of strings acknowledging roman numerals?

2014-08-26 Thread Henrik Bengtsson
Hi,

does anyone know of an implementation/function that sorts strings that
*contain* roman numerals (I, II, III, IV, V, ...) which are treated as
numbers.  In 'gtools' there is mixedsort() which does this for strings
that contains (decimal) numbers.  I'm looking for a mixedsortroman()
function that does the same but with roman numbers, e.g.

## DECIMAL NUMBERS
 x - sprintf(chr %d, 12:1)
 x
 [1] chr 12 chr 11 chr 10 chr 9  chr 8
 [6] chr 7  chr 6  chr 5  chr 4  chr 3
[11] chr 2  chr 1

 sort(x)
 [1] chr 1  chr 10 chr 11 chr 12 chr 2
 [6] chr 3  chr 4  chr 5  chr 6  chr 7
[11] chr 8  chr 9

 gtools::mixedsort(x)
 [1] chr 1  chr 2  chr 3  chr 4  chr 5
 [6] chr 6  chr 7  chr 8  chr 9  chr 10
[11] chr 11 chr 12


## ROMAN NUMBERS
 y - sprintf(chr %s, as.roman(12:1))
 y
 [1] chr XII  chr XI   chr Xchr IX
 [5] chr VIII chr VII  chr VI   chr V
 [9] chr IV   chr III  chr II   chr I

 sort(y)
 [1] chr Ichr II   chr III  chr IV
 [5] chr IX   chr Vchr VI   chr VII
 [9] chr VIII chr Xchr XI   chr XII

 mixedsortroman(y)
 [1] chr Ichr II   chr III  chr IV
 [5] chr Vchr VI   chr VII  chr VIII
 [9] chr IX   chr Xchr XI   chr XII

The latter is what I'm looking for.

Before hacking together something myself (e.g. identify roman numerals
substrings, translate them to decimal numbers, use gtools::mixedsort()
to sort them and then translate them back to roman numbers), I'd like
to hear if someone already has this implemented/know of a package that
does this.

Thanks,

Henrik

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


Re: [R] Clip smaller domain from large domain netCDF file

2014-08-26 Thread Roy Mendelssohn
Using the ncdf4 library  requires some knowledge of netcdf files and how they 
work.  However, if you can provide the following information I may be able to 
provide some pointers.  I am assuming your file is named myFile.nc.  Where 
you see that replace with the actual name.

library(ncdf4)
myFile-nc_open('myFile.nc')
str(myFile)


The output of the last command will show what is basically a dump of metadata 
content of the file, showing its structure.From the bounds I assume this is 
a Canadian dataset?

-Roy

On Aug 26, 2014, at 4:46 PM, Aseem Sharma nature.as...@gmail.com wrote:

 Hi,
 I have this huge ( ~30GB) .nc file (NC_FORMAT_NETCDF4_CLASSIC)) for the
 whole country 141.00 to 52.00 W, 41.00 to 84.00 N.
 I am trying to clip this big dataset for a small region specific domain
 (120.00 to 130.00 W, 50.00 to 60.00 N).
 I am trying to do using netCDF4 r package but could not figure out how to
 do so.
 Kindly please suggest me how should i proceed.
 
 
 Thank you,
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

**
The contents of this message do not reflect any position of the U.S. 
Government or NOAA.
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new address and phone***
110 Shaffer Road
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/

Old age and treachery will overcome youth and skill.
From those who have been given much, much will be expected 
the arc of the moral universe is long, but it bends toward justice -MLK Jr.

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


Re: [R] Mixed sorting/ordering of strings acknowledging roman numerals?

2014-08-26 Thread David Winsemius

On Aug 26, 2014, at 5:24 PM, Henrik Bengtsson wrote:

 Hi,
 
 does anyone know of an implementation/function that sorts strings that
 *contain* roman numerals (I, II, III, IV, V, ...) which are treated as
 numbers.  In 'gtools' there is mixedsort() which does this for strings
 that contains (decimal) numbers.  I'm looking for a mixedsortroman()
 function that does the same but with roman numbers, e.g.

It's pretty easy to sort something you know to be congruent with the existing 
roman class:

romanC - as.character( as.roman(1:3899) )
match(c(I, II, III,X,V), romanC)
#[1]  1  2  3 10  5

But I guess you already know that, so you want a regex approach to parsing. 
Looking at the path taken by Warnes, it would involve doing something like his 
regex based insertion of a delimiter for Roman numeral but simpler because he 
needed to deal with decimal points and signs and exponent notation, none of 
which you appear to need. If you only need to consider character and Roman, 
then this hack of Warnes tools succeeds:

 mixedorderRoman - function (x) 
{
if (length(x)  1) 
return(NULL)
else if (length(x) == 1) 
return(1)
if (is.numeric(x)) 
return(order(x))
delim = \\$\\@\\$
roman - function(x) {
suppressWarnings(match(x, romanC))
}
nonnumeric - function(x) {
suppressWarnings(ifelse(is.na(as.numeric(x)), toupper(x), 
NA))
}
x - as.character(x)
which.nas - which(is.na(x))
which.blanks - which(x == )
if (length(which.blanks)  0) 
x[which.blanks] - -Inf
if (length(which.nas)  0) 
x[which.nas] - Inf
delimited - gsub(([IVXCL]+), 
paste(delim, \\1, delim, sep = ), x)
step1 - strsplit(delimited, delim)
step1 - lapply(step1, function(x) x[x  ])
step1.roman - lapply(step1, roman)
step1.character - lapply(step1, nonnumeric)
maxelem - max(sapply(step1, length))
step1.roman.t - lapply(1:maxelem, function(i) sapply(step1.roman, 
function(x) x[i]))
step1.character.t - lapply(1:maxelem, function(i) sapply(step1.character, 
function(x) x[i]))
rank.roman - sapply(step1.roman.t, rank)
rank.character - sapply(step1.character.t, function(x) 
as.numeric(factor(x)))
rank.roman[!is.na(rank.character)] - 0
rank.character - t(t(rank.character) + apply(matrix(rank.roman), 
2, max, na.rm = TRUE))
rank.overall - ifelse(is.na(rank.character), rank.numeric, 
rank.character)
order.frame - as.data.frame(rank.overall)
if (length(which.nas)  0) 
order.frame[which.nas, ] - Inf
retval - do.call(order, order.frame)
return(retval)
}

y[mixedorderRoman(y)]
 [1] chr Ichr II   chr III  chr IV   chr IX  
 [6] chr Vchr VI   chr VII  chr VIII chr X   
[11] chr XI   chr XII 


-- 
David.
 
 ## DECIMAL NUMBERS
 x - sprintf(chr %d, 12:1)
 x
 [1] chr 12 chr 11 chr 10 chr 9  chr 8
 [6] chr 7  chr 6  chr 5  chr 4  chr 3
 [11] chr 2  chr 1
 
 sort(x)
 [1] chr 1  chr 10 chr 11 chr 12 chr 2
 [6] chr 3  chr 4  chr 5  chr 6  chr 7
 [11] chr 8  chr 9
 
 gtools::mixedsort(x)
 [1] chr 1  chr 2  chr 3  chr 4  chr 5
 [6] chr 6  chr 7  chr 8  chr 9  chr 10
 [11] chr 11 chr 12
 
 
 ## ROMAN NUMBERS
 y - sprintf(chr %s, as.roman(12:1))
 y
 [1] chr XII  chr XI   chr Xchr IX
 [5] chr VIII chr VII  chr VI   chr V
 [9] chr IV   chr III  chr II   chr I
 
 sort(y)
 [1] chr Ichr II   chr III  chr IV
 [5] chr IX   chr Vchr VI   chr VII
 [9] chr VIII chr Xchr XI   chr XII
 
 mixedsortroman(y)
 [1] chr Ichr II   chr III  chr IV
 [5] chr Vchr VI   chr VII  chr VIII
 [9] chr IX   chr Xchr XI   chr XII
 
 The latter is what I'm looking for.
 
 Before hacking together something myself (e.g. identify roman numerals
 substrings, translate them to decimal numbers, use gtools::mixedsort()
 to sort them and then translate them back to roman numbers), I'd like
 to hear if someone already has this implemented/know of a package that
 does this.
 
 Thanks,
 
 Henrik
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

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


[R] Where to find source of C_pbinom?

2014-08-26 Thread Marius Hofert
Dear expeRts,

I would like to find out how R computes pbinom(). A grep in the
source code reveiled src/library/stats/R/distn.R:146:
.External(C_pbinom, q, size, prob, lower.tail, log.p), so
'C_pbinom' refers to compiled C/C++ code loaded into R. Where can
I find the source code of C_pbinom?

Cheers,

Marius

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


Re: [R] What the difference between .Golbalenv and package:base?

2014-08-26 Thread PO SU
So, the decisive factor is  whether the input string be on the search() name 
list, and not related with the envir's name attribute.
When we using attach, it is becasue the name attribute just match the search() 
name list(or say,search() name list just use the name attribute), so 
as.environment() can work  well. 
Tks!


--

PO SU
mail: desolato...@163.com
Majored in Statistics from SJTU



At 2014-08-27 00:02:07, William Dunlap wdun...@tibco.com wrote:
as.environment(characterString) maps an entry from the output of
search() to the environment at the named position in the search list.
as.environment(number) maps an index into the output of search() to
the the environment at that position in the search list.  If
'characterString' is not in the output of search() or 'number' is not
in seq_along(search()) then as.environment throws an error.  As far as
I can tell, as.environment does not deal with the name of the
environment at all.  (When you attach an environment, attach will add
a name attribute to the copied environment so the attached
environment's name matches the name on the output of search(), but I
don't think as.environment ever looks at that attribute.)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Aug 25, 2014 at 9:07 PM, PO SU rhelpmaill...@163.com wrote:
 First, sorry for my pool english expression which make you misunderstanding 
 of my original purpose.

 Sometimes, suppose  a object in both stats and base, then i type the object 
 name, then after R search the search() list, R will use the object in stats, 
 is it right?( I just suppose, stats can be any package which libraried into 
 R.)
 Then i know that, .GlobalEnv or globalenv() is the global environment 
 object, baseenv() returns the base environment object.
 I also know that, i can convert the environment name into the real 
 environment object by using stats-as.environment(package:stats),  And the 
 stats environment's name can be obtained using environmentName(stats), but 
 it returns .   (why?)
 Then i use  environmentName(.GlobalEnv) then i get R_GlobalEnv, then i use 
 as.environment(R_GlobalEnv), it does't work.(why?)


 In one word, as.environment(x), x is somthing not the environment's name.


 But, when i add a environment into the search() list, after i 
 attr(newenvir,name)-new_name
 I can use the  as.environment(new_name) to obtain the added environment. 
 (why?)


 Hope you understand my meaning :)












 --

 PO SU
 mail: desolato...@163.com
 Majored in Statistics from SJTU



 At 2014-08-26 02:51:54, MacQueen, Don macque...@llnl.gov wrote:
Put simply,
   .GlobalEnvstores objects you create
   package:base  contains functions and objects provided by R itself

You don¹t need to use   .GlobalEnv$a   to use the variable named a. Just
is ³a² by itself.

 a - 4
 b - 2*a
print(a)
print(b)

Not necessary to use
  print(.GlobalEnv$a)

Similarly, to find an object in the base package, just type its name.

I don¹t know what you are trying to do, or why you think you have to use
.GlobalEnv$a
But in more than 20 years of using R for many different tasks, I have
never had to do that.

Furthermore, if you are new to R (which I would guess is the case), it
seems unlikely to me that you need to work with environments or use
attach() or assign(). In the vast majority of cases there are simpler ways
that are easier to understand.

You are aware, I hope, that
   ls('.GlobalEnv')
   ls(1)
   ls()
all return the same result?


--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 8/24/14, 11:07 PM, PO SU rhelpmaill...@163.com wrote:



Dear rusers,

As we know, there are a lot of environments in the search() path,
such as   .Golbalenv and package:base .
And  i can just use  .Golbalenv$a ,.Golbalenv$b to use the virable,  but
i must use as.envrionment(package:base) to find virable, i feel it not
very convenient.


For example, when i use the following codes to add a new env into the
search() path.



 tmp-attach(NULL,name=new_name)
 assign(a,2,envir=as.environment(new_name))
 a
[1] 2
 as.environment(new_name)$a
[1] 2
 I must always convert the name to the environment, How can i just use
the following form:



 tmp-attach(NULL,name=new_name)
 assign(a,2,envir=new_name)   #like using  .GlobalEnv
 a
[1] 2
 new_name$a

[1] 2







--

PO SU
mail: desolato...@163.com
Majored in Statistics from SJTU
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

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

[[alternative 

[R] NA's introduced by coercion

2014-08-26 Thread madhvi.gupta

Hi,

I am applyin function as.numeric to a vector having many values as NA 
and it is giving :

Warning message:
NAs introduced by coercion

Can anyone help me to know how to remove this warning and sor it out?

Thanks
Madhvi

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


Re: [R] NA's introduced by coercion

2014-08-26 Thread Steve Lianoglou
Hi,

On Tue, Aug 26, 2014 at 9:56 PM, madhvi.gupta madhvi.gu...@orkash.com wrote:
 Hi,

 I am applyin function as.numeric to a vector having many values as NA and it
 is giving :
 Warning message:
 NAs introduced by coercion

 Can anyone help me to know how to remove this warning and sor it out?

Let's say that the vector you are calling `as.numeric` over is called
`x`. If you could show us the output of the following command:

R head(x[is.na(as.numeric(x))])

You'll see why you are getting the warning.

How you choose to sort it out probably depends on what you are trying
to do with your data after you convert it to a numeric

-steve

-- 
Steve Lianoglou
Computational Biologist
Genentech

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


[R-es] color de fondo de un gráfico creado con ggplot

2014-08-26 Thread Hector Gómez Fuerte
En un grfico creado con el comando ggplot (de la librera ggplot2) se puede establecer un fondo blanco con theme_set(theme_bw()), o volver al grs (que tiene por defecto) con theme_gray(). Es posible establecer un fondo de otro color? Otra pregunta: si dibujamos un grfico usando facets, es decir con facet_wrap(), el encabezado de cada panel tiene un fondo grs; cmo se puede cambiar este color de fondo?

Muchas gracias y saludos.

H. Gmez



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


Re: [R-es] color de fondo de un gráfico creado con ggplot

2014-08-26 Thread daniel
Intenta con esto,

library(ggplot2)
DF - data.frame( nombre = c( uno, dos, tres, cuatro), sector = c(
1,2), x = rnorm(400))
m - ggplot(data = DF, aes(x = sector, y = x)) + geom_point() +
facet_wrap(~nombre)
m + theme(panel.background = element_rect(fill = blue), strip.background
= element_rect(fill=orange))

También puedes consultar http://docs.ggplot2.org/current/

Espero te sirva,

Daniel Merino



El 26 de agosto de 2014, 15:16, Hector Gómez Fuerte hect...@gmx.es
escribió:

 En un gráfico creado con el comando ggplot (de la librería ggplot2) se
 puede establecer un fondo blanco con theme_set(theme_bw()), o volver al
 grís (que tiene por defecto) con theme_gray(). ¿Es posible establecer un
 fondo de otro color? Otra pregunta: si dibujamos un gráfico usando facets,
 es decir con facet_wrap(), el encabezado de cada panel tiene un fondo grís;
 ¿cómo se puede cambiar este color de fondo?
 Muchas gracias y saludos.
 H. Gómez


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




-- 
Daniel

[[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-es] color de fondo de un gráfico creado con ggplot

2014-08-26 Thread Hector Gómez Fuerte
Muchas gracias por las respuestas!

Saludos,

H. Gmez


Enviar:martes 26 de agosto de 2014 a las 21:17
De:Carlos Ortega c...@qualityexcellence.es
Para:Hector Gmez Fuerte hect...@gmx.es
CC:Lista R r-help-es@r-project.org
Asunto:Re: [R-es] color de fondo de un grfico creado con ggplot



Hola,


Aqu tienes una solucion para cada una de las preguntas:

http://stackoverflow.com/questions/6736378/how-do-i-change-the-background-color-of-a-plot-made-with-ggplot2
http://stackoverflow.com/questions/24169675/multiple-colors-in-a-facet-strip-background


Saludos,
Carlos Ortega
www.qualityexcellence.es



El 26 de agosto de 2014, 20:16, Hector Gmez Fuerte hect...@gmx.es escribi:




En un grfico creado con el comando ggplot (de la librera ggplot2) se puede establecer un fondo blanco con theme_set(theme_bw()), o volver al grs (que tiene por defecto) con theme_gray(). Es posible establecer un fondo de otro color? Otra pregunta: si dibujamos un grfico usando facets, es decir con facet_wrap(), el encabezado de cada panel tiene un fondo grs; cmo se puede cambiar este color de fondo?

Muchas gracias y saludos.

H. Gmez





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





--
Saludos,
Carlos Ortega
www.qualityexcellence.es





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