Re: [R] labels in rgl.sphere

2009-05-28 Thread Dieter Menne



Naoki Irie-3 wrote:
> 
> I am using rgl.sphere to visualize scatter plot data in three  dimensional
> space. However, as I can not see the labels of each data point directly in  
> RGL window, I usually look for the values of x, y, z axis to find out the
> label  (or line number of the data point).
> 
> Is there any way that I can label all the (or clicked)  data point (= 
> sphere) ?
> 

I used a function like that below to mark a point, and kept a list of id.
When the point was selected the next time, I erased and redrew it in another
color.

Dieter

# - plotDot

plotDot = function(data,col="black",ptsize=10,offset=30){
  # Plot a lollypop   ()
  # returns id of sphere (assuming line is id +1)
  x = data[1]
  y = data[2]
  z = data[3]
  zoff = z+offset
  # bit ball
  id = spheres3d(x,y,zoff,r=ptsize,color=col)
  # little ball at bottom
  spheres3d(x,y,z,r=3,color=col)
  apply(cbind(x,y,z,zoff),1,
function(X) {lines3d(
  x=rep(X[1],2),
  y=rep(X[2],2), 
  z=c(X[3],X[4]),
  col="black", size=2)
})
  id
}



-- 
View this message in context: 
http://www.nabble.com/labels-in-rgl.sphere-tp23773810p23774895.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] custom sort?

2009-05-28 Thread Wacek Kusnierczyk
Steve Jaffe wrote:
> hmm, that is what I was afraid of. I considered that but thought to myself,
> surely there must be an easier way.  I wonder why this feature isn't
> available. It's there in scripting languages, like perl, but also in
> "hardcore" languages like C++ where std::sort and sorted containers allow
> the user to provide a comparison function (even for builtin types like int).
> It's hard to believe that you have to jump through more hoops to do a custom
> sort in R than in C++ ...
>
>
> You put a class on the vector...
>   

there has been some discussion on sorting here some time ago;  r folks
do not seem to accept the idea of sorting as a generic task, with the
sorting algorithm a separate thing from the comparison operator and the
type of the elements to be sorted.  (hence you can't sort arbitrary
lists, for example.) 

you may want to lookup the archives.

vQ

__
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] RODBC package: how to check whether connection is open

2009-05-28 Thread Dieter Menne



Stavros Macrakis-2 wrote:
> 
> What is the recommended way of checking whether an RODBC connection is
> open?
> 
> Since odbcValidChannel is not exported from namespace RODBC, I suppose I
> shouldn't be using it.
> 
> This is the best I could come up with, but it seems a bit 'dirty' to be
> using a tryCatch for something like this:
> 
>   odbcOpenp <- function(conn)
>  tryCatch({odbcGetInfo(conn);TRUE},error=function(...)FALSE)
> 

Directly after an open, testing for class of the channel should work. As I
understand ODDBC, there is no way of testing if the channel "is still open"
other than doing a test-read, because the other side could be connected
transatlantic. I remember an IBM memo giving an example that sends a
passthrough SQL query to the remote site.


Dieter


library(RODBC)
channel = odbcConnectAccess("db.mdb")
str(channel)
class(channel)
channel = odbcClose(channel)
str(channel) # Still of class RODBC, evidently


-- 
View this message in context: 
http://www.nabble.com/RODBC-package%3A-how-to-check-whether-connection-is-open-tp23771854p23774853.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] String replacement in an expression

2009-05-28 Thread Wacek Kusnierczyk
William Dunlap wrote:
> Bill Dunlap
> TIBCO Software Inc - Spotfire Division
> wdunlap tibco.com  
>
>   
>> -Original Message-
>> From: r-help-boun...@r-project.org 
>> [mailto:r-help-boun...@r-project.org] On Behalf Of Wacek Kusnierczyk
>> Sent: Thursday, May 28, 2009 12:31 PM
>> To: Caroline Bazzoli
>> Cc: r-help@r-project.org
>> Subject: Re: [R] String replacement in an expression
>>
>> Caroline Bazzoli wrote:
>> 
>>> Dear R-experts,
>>>
>>> I need to replace in an expression the character "Cl" by "Cl+beta"
>>>
>>> But in the following case:
>>>
>>> form<-expression((Cl-(V *ka)  ) +(V   *Vm   *exp(-(Clm/Vm)   *t)))
>>>
>>> gsub("Cl","(Cl+beta)",as.character(form))
>>>
>>> We obtain:
>>>
>>> [1] "((Cl+beta) - (V * ka)) + (V * Vm * exp(-((Cl+beta)m/Vm) * t))"
>>>
>>>
>>> the character "Clm" has been also replaced.
>>>
>>>
>>> How could I avoid this unwanted replacement ?
>>>   
>> try '\\bCl\\b' as the pattern, which says 'match Cl as a 
>> separate word'.
>> 
>
> That works in this case, but \\b idea of what a word is not
> same as R's idea of what a name is.  E..g, \\b thinks that
> a period is not in a word but R thinks periods in names are
> fine.
>   

yes, that's right.  i was tuned to the particular example given by the op.

vQ


>> gsub("\\bC1\\b", "(C1+beta)", "C1 * exp(C1.5 / C2.5)")
>[1] "(C1+beta) * exp((C1+beta).5 / C2.5)"
> This is one more reason to use substitute(), which directly
> edits an expression to produce a new one.  It avoids
> the deparse-edit-parse cycle that can corrupt things
> (even if you don't do any editing).
>> substitute(C1 * exp(C1.5 / C2.5), list(C1=Quote(C1+beta)))
>(C1 + beta) * exp(C1.5/C2.5)
>

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

2009-05-28 Thread Nathan S. Watson-Haigh
Are there any particular licences under which R packages must be released or is
it the discretion of the author? The same question if the package is to be
destined for CRAN?

Kind regards,
Nathan

-- 

Dr. Nathan S. Watson-Haigh
OCE Post Doctoral Fellow
CSIRO Livestock Industries
Queensland Bioscience Precinct
St Lucia, QLD 4067
Australia

Tel: +61 (0)7 3214 2922
Fax: +61 (0)7 3214 2900
Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html

__
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] IP-Address

2009-05-28 Thread edwin Sendjaja

Hi,

Is there any way to sort a tabel with a colum with IP-address?

table:

id rank color status ip
138 29746 yellow no 162.131.58.26
138 29746 red  yes  162.131.58.16
138 29746 blue yes  162.131.58.10
138 29746 red no  162.131.58.17
138 29746 yellow no 162.131.58.14
138 29746 red no  162.131.58.13
138 29746 yellow  no 162.132.58.15
139 29746 green no  162.252.20.69
140 29746 red yes  162.254.20.71
141 29746 yellow no  163.253.7.153
142 31804 green yes  163.253.20.114
144 32360 black yes  161.138.45.226



Unfortunately, order doesn't work as I want.

I found an half solusion from John:

mysort <- function(x){
  sort.helper <- function(x){
prefix <- strsplit(x, "[0-9]")
prefix <- sapply(prefix, "[", 1)
prefix[is.na(prefix)] <- ""
suffix <- strsplit(x, "[^0-9]")
suffix <- as.numeric(sapply(suffix, "[", 2))
suffix[is.na(suffix)] <- -Inf
remainder <- sub("[^0-9]+", "", x)
remainder <- sub("[0-9]+", "", remainder)
if (all (remainder == "")) list(prefix, suffix)
else c(list(prefix, suffix), Recall(remainder))
}
  ord <- do.call("order", sort.helper(x))
  x[ord]
   } 


mysort (data$ip)  captured only the ip-adresse. How can I capture the whole 
table and sorted?(ID rank color status ip)



Thank you in advance.

eddie



_


[[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] Step by step: Making an R package with Fortran 95

2009-05-28 Thread sjnovick

Thank you, Duncan.  While your answers didn't quite fix my problems, I
realized that I should probably "go with the flow".  I installed gfortran
and everything worked fine.  Thanks again.

Steve










sjnovick wrote:
> 
> To all.  I need your help.  The big question is:  How do I make an R
> library with Fortran 95 files?  You may assume that I am a pretty decent
> programmer in both R and Fortran.  I lay out a scenario and need your
> help!
> 
> I know how to make an ordinary R package and have dabbled with R + Fortran
> 95 *.dll linking.  I do not have a great handle on the whole Makevars file
> and whatever else I might need to get things working to build a new R
> package.  By the way, I'm using R 2.8.1 and Windows XP (and sometimes
> Linux).
> 
> 
> Let's take this simple situation.  Suppose I'm using Windows XP and place
> the Folder for the package "Testme" in C:\Program
> Files\R\R-2.8.1\src\library\Testme
> 
> Files and folders:
> 
>   DESCRIPTION file -- I understand this file
>   NAMESPACE file:  This one has the contents
>useDynLib("Testme")
>exportPattern("^[^\\.]")
> 
>   man directory:  I put my *.Rd files here.  I understand this part.
>   R directory:   I put my *.R files here.  One of these files calls upon a
> Fortran 95 subroutine with
>  .Fortran("MySubroutine", var1=as.double(x),
> var2=as.double(y), etc.)
>  I understand this part.
> 
>   src directory:  I put my *.f95 files here.  Also, I put a Makevars file
> here.
> 
>   Suppose that I have two *.f95 files, named  CalculatorModule.f95 and 
> ANiceSubroutine.f95.
>   
>   CalculatorModule.f95 contains a Fortran 95 module.
>   ANiceSubroutine.f95 uses the functions in
> Calculator.Module.f95 with the "USE" command.  To be consistent with my R
> file (above), ANiceSubroutine.f95 contains the subroutine: "MySubroutine".
> 
> Finally:  I issue the command from a DOS Shell in the directory C:\Program
> Files\R\R_2.8.1\src\gnuwin32
> 
> make pkg-Testme
> 
> This results in errors.
> 
> 
> 
> Here are the problems:
>   1.  The order of compilation must be f95 -c CalculatorModule.f95
> ANiceSubroutine.f95.  Unfortunately, R compiles them alphabetically.  So,
> I was given errors making the *.o files.
>
>I overcame this problem by renaming the files  
> a01.CalculatorModule.f95 and a02.ANiceSubroutine.f95.  I would rather not
> have to name the files this way if I don't have to!  When I did this, R
> compiled the Fortran files in the correct order, but I still have errors.
> 
>2.  Here was the error output.  Help?
> 
> C:\Program Files\R\R-2.8.1\src\gnuwin32>make pkg-Testme
> 
> -- Making package Testme 
>   adding build stamp to DESCRIPTION
>   installing NAMESPACE file and metadata
>   making DLL ...
> "g95"  -O3 -c a01.CalculatorMod.f95 -o a01.CalculatorMod.o
> "g95"  -O3 -c a02.ANiceSubroutine.f95 -o a02.ANiceSubroutine.o
> windres --preprocessor="gcc -E -xc -DRC_INVOKED" -I
> C:/PROGRA~1/R/R-28~1.1/inclu
> de  -i Testme_res.rc -o Testme_res.o
> "g95" -shared -s  -o Testme.dll Testme.def a01.CalculatorMod.o
> a02.ANiceSubroutine.o
> Testme_res.o  -LC:/PROGRA~1/R/R-28~1.1/bin-lR
> ld: Testme.def:6: syntax error
> ld:Testme.def: file format not recognized; treating as linker script
> ld:Testme.def:2: syntax error
> make[3]: *** [Testme.dll] Error 1
> make[2]: *** [srcDynlib] Error 2
> make[1]: *** [all] Error 2
> make: *** [pkg-Testme] Error 2
> 
> 
> 
> Thanks for helping!!! :)
> 

-- 
View this message in context: 
http://www.nabble.com/Step-by-step%3A-Making-an-R-package-with-Fortran-95-tp23669355p23773479.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] labels in rgl.sphere

2009-05-28 Thread Naoki Irie

Dear R list

I am using rgl.sphere to visualize scatter plot data in three  
dimensional space.
Thanks to the rgl library, I can easily find out the data point that I  
am interested in.


However, as I can not see the labels of each data point directly in  
RGL window,
I usually look for the values of x, y, z axis to find out the label  
(or line number of the data point).


Is there any way that I can label all the (or clicked)  data point (=  
sphere) ?


Thank you.

Naoki

__
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] Drawing schematics

2009-05-28 Thread Gabor Grothendieck
Paul Murrel has an article about using grid graphics
to do this.  He also mentions specialized R packages
that are specifically aimed at this task.
http://journal.r-project.org/current.html

On Thu, May 28, 2009 at 11:00 PM, George Chen  wrote:
> Hi,
>
> I would like to represent the treatment course of a subject with an arrow 
> representing passage through time and various ticks, arrows, or bars 
> representing treatments done to the patient along the arrow.  I would like to 
> generate this sort of schematic for each patient in a database taking 
> information from the database such as time of treatment and type of treatment.
>
> Does anybody know how I can do this?  Is there a premade R package for this 
> sort of thing or should I try to make a new graphics function?  If a new 
> graphics function, where could I start?
>
> Thanks in advance.
>
> George
>
> __
> 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] Drawing schematics

2009-05-28 Thread George Chen
Hi,

I would like to represent the treatment course of a subject with an arrow 
representing passage through time and various ticks, arrows, or bars 
representing treatments done to the patient along the arrow.  I would like to 
generate this sort of schematic for each patient in a database taking 
information from the database such as time of treatment and type of treatment.

Does anybody know how I can do this?  Is there a premade R package for this 
sort of thing or should I try to make a new graphics function?  If a new 
graphics function, where could I start?

Thanks in advance.

George

__
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] how do I decide the best number of observations in MLE?

2009-05-28 Thread Michael
Of course, in MLE, if we collect more and more observations data, MLE
will perform better and better.

But is there a way to find a bound on parameter estimate errors in
order to decide when to stop collect data/observations, say 1000
observations are great, but 500 observations is good enough...

Thanks!

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


[R] GTK Tooltips under Linux

2009-05-28 Thread Ronggui Huang
Dear all,

I want to set tool-tips for a gtkButton. I use the following code
which works under Windows. However, it doesn't work under Linux. Any
hints? Thanks.

library(RGtk2)
b<-gtkButtonNewWithLabel("OK")
gtkTooltips()$setTip(b,"Memo for a Button.")
gw <- gtkWindow(show=F)
gw$Add(b)
gw$Show()

> sessionInfo()
R version 2.8.0 Patched (2008-12-10 r47137)
i686-pc-linux-gnu

locale:
LC_CTYPE=zh_CN.UTF-8;LC_NUMERIC=C;LC_TIME=zh_CN.UTF-8;LC_COLLATE=zh_CN.UTF-8;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=zh_CN.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=zh_CN.UTF-8;LC_IDENTIFICATION=C

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

other attached packages:
[1] RGtk2_2.12.11RQDA_0.1-8   igraph_0.5.2-2
[4] gWidgetsRGtk2_0.0-51 gWidgets_0.0-35  RSQLite_0.7-1
[7] DBI_0.2-4

loaded via a namespace (and not attached):
[1] tools_2.8.0

-- 
HUANG Ronggui, Wincent
PhD Candidate
Dept of Public and Social Administration
City University of Hong Kong
Home page: http://asrr.r-forge.r-project.org/rghuang.html

__
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] I need help. about draw tree.

2009-05-28 Thread yongkook Kwon
Hello~

I have some ploblem.

How can I draw tree picture after plsda.

Please ,help me.

script
--
Result <- plsda(trainDescr, species, ncomp = 5, probMethod = "Bayes")

[[alternative HTML version deleted]]

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


Re: [R] custom sort?

2009-05-28 Thread Duncan Murdoch

On 28/05/2009 8:17 PM, Stavros Macrakis wrote:

I couldn't get your suggested method to work:

  `==.foo` <- function(a,b) unclass(a)==unclass(b)
  `>.foo` <- function(a,b) unclass(a) < unclass(b) # invert comparison
  is.na.foo <- function(a)is.na(unclass(a))

  sort(structure(sample(5),class="foo"))  #-> 1:5  -- not reversed

What am I missing?


I'm not sure:  I've never actually used that, I was basing it on the 
docs.  Looks like it's not as simple as I thought.  Sorry for the 
misinformation.


Duncan Murdoch



   -s

On Thu, May 28, 2009 at 5:48 PM, Duncan Murdoch wrote:


On 28/05/2009 5:34 PM, Steve Jaffe wrote:


Sounds simple but haven't been able to find it in docs: is it possible to
sort a vector using a user-defined comparison function? Seems it must be,
but "sort" doesn't seem to provide that option, nor does "order" sfaics


You put a class on the vector (e.g. using class(x) <- "myvector"), then
define a conversion to numeric (e.g. xtfrm.myvector) or actual comparison
methods (you'll need ==.myvector, >.myvector, and is.na.myvector).

Duncan Murdoch


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





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


Re: [R] lattice::xyplot axis padding with fontfamily="mono"

2009-05-28 Thread Benjamin Tyner

Deepayan,

Many thanks for the quick response and suggested workaround.

Best,
Ben



Deepayan Sarkar wrote:

On Wed, May 27, 2009 at 4:38 PM, Benjamin Tyner  wrote:
  

Hello,

Say I have a predictor taking a very wide value:

 Data <- data.frame(pred="a",resp=1)

 print(xyplot(pred~resp, data=Data)) # enough y-axis padding to accommodate
the wide label

 print(xyplot(pred~resp, data=Data,scales=list(fontfamily="mono"))) # not
enough padding



It's a bug in the layout calculations (fontfamily is not used).

  

What's the recommended way to have enough padding allocated?



Ideally by fixing the bug, but that may not be easy to fix in the
short run. For one-off examples, you could increase the width
manually:

xyplot(pred~resp, data=Data,scales=list(fontfamily="mono"),
par.settings = list(layout.widths = list(axis.left = 1.1)))

-Deepayan
  


__
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] Still can't find missing data

2009-05-28 Thread Farley, Robert
That seems to work for the toy data.  How do I implement this change with my 
real data, which are read from very large Stata and SPSS files and keep the 
factor definitions?  Won't I be losing information (and creating a larger 
dataset) by not using the factor levels?


How do I recover the factor values?  I read my datafile (read.spss using   
use.value.labels = FALSE,) and got this:

  connector
Mode_orig_only19
  1   17.814338 0.00
  3   49.128982 0.00
  4  525.978899 0.00
  5  913.295370 0.00
  6  114.302764 0.00
  7  298.151438 0.00
  8   93.088049 0.00
  9  233.794168 0.00
  10  20.764539 0.00
  11 424.120506 0.00
  12   8.054528 0.00
  13   6.010790 0.00
  141832.748525 0.00
  15   10191.284139 0.00
  162099.771923 0.00
  171630.148576 0.00
   0.00  9491.013249

which does have the "NA" row, but not the factor labels.  If I read the file 
with use.value.labels=TRUE I can see what I'm summarizing, but not the NAs.  
Can't I have both?

The top summary will also omit all 0 value factors (of course) in the variable 
summarized.


The same summary using factors:
 connector

Mode_orig_only OD Passenger
Connector

  Walked/Biked17.814338 
0.00

   I flew in from another a place/connected0.00 
0.00

  Amtrak  49.128982 
0.00

  Bus - Chartered bus or van 525.978899 
0.00

  Bus - Hotel Courtesy van   913.295370 
0.00

  Bus - MTA (Metro) or other public transit bus  114.302764 
0.00

  Bus - Scheduled airport bus or van (e.g. Airport bus or Disn   298.151438 
0.00

  Bus - Union Station Flyaway 93.088049 
0.00

  Bus - Van Nuys Flyaway 233.794168 
0.00

  Green line/light rail   20.764539 
0.00

  Limousine/town car 424.120506 
0.00

  Metrolink8.054528 
0.00

  Motorcycle   6.010790 
0.00

  On-call shuttle/van (e.g. Super Shuttle, Prime Time)  1832.748525 
0.00

  Car/truck/van - Private  10191.284139 
0.00

  Car/truck/van - Rental2099.771923 
0.00

  Taxi  1630.148576 
0.00

  ..Refused0.00 
0.00







Robert Farley
Metro
www.Metro.net


-Original Message-
From: William Dunlap [mailto:wdun...@tibco.com]
Sent: Thursday, May 28, 2009 16:26
To: Farley, Robert
Subject: RE: [R] Still can't find missing data

Try reading it in with read.table's argument stringsAsFactors=FALSE.

I think the underlying problem is that exclude= is used only if
the classifying variables are not already factors.  I haven't studied
the help file well enough to see if that is what is is documented
to do, but it seems misleading.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com

> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Farley, Robert
> Sent: Thursday, May 28, 2009 4:10 PM
> To: R-help
> Subject: Re: [R] Still can't find missing data
>
> In this toy data, each of the tables should sum to 
> None of the tables shows NA columns or rows.
>
>
> > 
> > ToyData <- read.table("C:/Data/R/Toy.csv", header=TRUE,
> sep=",", na.strings="NA", dec=".", row.names="ID_Num")
> > ToyData
> Data1 Data2  Data3 Weight
> 101   Sam   Red Banana  1
> 102   Sam Green Banana  2
> 103   Sam  Blue Orange  2
> 104  Fred   Red Orange  2
> 105  Fred Green  Guava  2
> 106  Fred  Blue  Guava  2
> 107 Red   Pear 50
> 108   Green   Pear 50
> 109Blue  1000
> > xtabs(Weight ~  Data1 + Data2, exclude=NULL,
> na.action=na.pass, ToyData)
>   Data2
> Data1  Blue Green Red
>   Fred2 2   2
>   Sam 2 2   1
> > xtabs(Weight ~  Data1 + Data2, exclude=NULL,
> na.action=na.pass,drop.unused.levels = FALSE, ToyData)
>   Data2
> Data1  Blue Green Red
>   Fred2 2   2
>   S

Re: [R] Error: argument is of length zero

2009-05-28 Thread jim holtman
I would assume that valsum is of zero length:

> valsum <- numeric(0)
> str(valsum)
 num(0)
> if (valsum == 1) 1
Error in if (valsum == 1) 1 : argument is of length zero
check your objects with 'str'

On Thu, May 28, 2009 at 6:39 PM, Derek Lacoursiere  wrote:

> Hi,
>
> I have the following:
>
>for(j in (y.raw+1):(rownum-1)){
>valsum<-tstfframed[min.x,j]+tstfframed[min.x,j+1]
>if(valsum == 1){
>cat("valsum loop")
>int.num<-int.num+1
>}
>
>}
>
> but I get the error message: "Error in if (valsum == 1) { : argument is of
> length zero".  I checked whether to see if all the stated variables have
> associated values (and are not NAs) and every variable (even valsum!) has a
> value.  I have no idea where my error is. Can you help me?
>
> __
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

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


Re: [R] custom sort?

2009-05-28 Thread Stavros Macrakis
I couldn't get your suggested method to work:

  `==.foo` <- function(a,b) unclass(a)==unclass(b)
  `>.foo` <- function(a,b) unclass(a) < unclass(b) # invert comparison
  is.na.foo <- function(a)is.na(unclass(a))

  sort(structure(sample(5),class="foo"))  #-> 1:5  -- not reversed

What am I missing?

   -s

On Thu, May 28, 2009 at 5:48 PM, Duncan Murdoch wrote:

> On 28/05/2009 5:34 PM, Steve Jaffe wrote:
>
>> Sounds simple but haven't been able to find it in docs: is it possible to
>> sort a vector using a user-defined comparison function? Seems it must be,
>> but "sort" doesn't seem to provide that option, nor does "order" sfaics
>>
>
> You put a class on the vector (e.g. using class(x) <- "myvector"), then
> define a conversion to numeric (e.g. xtfrm.myvector) or actual comparison
> methods (you'll need ==.myvector, >.myvector, and is.na.myvector).
>
> Duncan Murdoch
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] avoid a loop

2009-05-28 Thread Martin Morgan

Gabor Grothendieck wrote:

Try this:


sapply(1:n, function(i) sum(abs(outer(a, b, "-")-i)==0))

[1] 10 10 10 10  9


abs(outer(a, b, "-") - i) == 0 ==> outer(a, b, "-") == i.

sum(outer(a, b, "-") == i) asks how many times i is an element of 
outer(a, b, "-"). This is


tabulate(outer(a, b, "-"), n)

I think, anyway.

Martin




On Thu, May 28, 2009 at 5:45 PM, KARAVASILIS GEORGE  wrote:

Hello, R users.
I have the following code:

a=1:10
b=-3:15
n=5
x <- rep(0,n)
for (i in 1:n) x[i] <- sum( outer(a,b, function(s,t)  abs(a-b-i)==0) )

Can someone tell me if I could avoid the for command?

Thank you in advance.

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



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



--
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

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


Re: [R] custom sort?

2009-05-28 Thread Duncan Murdoch

On 28/05/2009 6:06 PM, Steve Jaffe wrote:

hmm, that is what I was afraid of. I considered that but thought to myself,
surely there must be an easier way.  I wonder why this feature isn't
available. It's there in scripting languages, like perl, but also in
"hardcore" languages like C++ where std::sort and sorted containers allow
the user to provide a comparison function (even for builtin types like int).
It's hard to believe that you have to jump through more hoops to do a custom
sort in R than in C++ ...


You put a class on the vector...



Each of the things I described to you would take about a line of code, 
plus the logic of the comparisons.  So the hoops R makes you jump 
through amount to 2-4 extra lines of code.  C++  is probably going to 
take at least that much.


Duncan Murdoch

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


[R] RODBC package: how to check whether connection is open

2009-05-28 Thread Stavros Macrakis
What is the recommended way of checking whether an RODBC connection is open?

Since odbcValidChannel is not exported from namespace RODBC, I suppose I
shouldn't be using it.

This is the best I could come up with, but it seems a bit 'dirty' to be
using a tryCatch for something like this:

  odbcOpenp <- function(conn)
 tryCatch({odbcGetInfo(conn);TRUE},error=function(...)FALSE)

Suggestions?

  -s

[[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] Still can't find missing data

2009-05-28 Thread Farley, Robert
In this toy data, each of the tables should sum to 
None of the tables shows NA columns or rows.


> 
> ToyData <- read.table("C:/Data/R/Toy.csv", header=TRUE, sep=",", 
> na.strings="NA", dec=".", row.names="ID_Num")
> ToyData
Data1 Data2  Data3 Weight
101   Sam   Red Banana  1
102   Sam Green Banana  2
103   Sam  Blue Orange  2
104  Fred   Red Orange  2
105  Fred Green  Guava  2
106  Fred  Blue  Guava  2
107 Red   Pear 50
108   Green   Pear 50
109Blue  1000
> xtabs(Weight ~  Data1 + Data2, exclude=NULL, na.action=na.pass, ToyData)
  Data2
Data1  Blue Green Red
  Fred2 2   2
  Sam 2 2   1
> xtabs(Weight ~  Data1 + Data2, exclude=NULL, 
> na.action=na.pass,drop.unused.levels = FALSE, ToyData)
  Data2
Data1  Blue Green Red
  Fred2 2   2
  Sam 2 2   1
> xtabs(Weight ~  Data1 + Data3, exclude=NULL, 
> na.action=na.pass,drop.unused.levels = FALSE, ToyData)
  Data3
Data1  Banana Guava Orange Pear
  Fred  0 4  20
  Sam   3 0  20
>





Robert Farley
Metro
www.Metro.net


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Dieter Menne
Sent: Thursday, May 28, 2009 05:46
To: r-help@r-project.org
Subject: Re: [R] Still can't find missing data




Farley, Robert wrote:
>
> I can't get the syntax that will allow me to show NA values (rows) in the
> xtabs.
>
> lengthy non-reproducible example removed
>

If you want a reproducible answer, prepare a reproducible result. And check
that the
syntax is

na.action=na.pass

Dieter




--
View this message in context: 
http://www.nabble.com/Still-can%27t-find-missing-data-tp23730627p23761006.html
Sent from the R help mailing list archive at Nabble.com.

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

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


Re: [R] avoid a loop

2009-05-28 Thread Gabor Grothendieck
Try this:

> sapply(1:n, function(i) sum(abs(outer(a, b, "-")-i)==0))
[1] 10 10 10 10  9


On Thu, May 28, 2009 at 5:45 PM, KARAVASILIS GEORGE  wrote:
> Hello, R users.
> I have the following code:
>
> a=1:10
> b=-3:15
> n=5
> x <- rep(0,n)
> for (i in 1:n) x[i] <- sum( outer(a,b, function(s,t)  abs(a-b-i)==0) )
>
> Can someone tell me if I could avoid the for command?
>
> Thank you in advance.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-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] Error: argument is of length zero

2009-05-28 Thread Derek Lacoursiere
Hi,

I have the following:

for(j in (y.raw+1):(rownum-1)){
valsum<-tstfframed[min.x,j]+tstfframed[min.x,j+1]
if(valsum == 1){
cat("valsum loop")
int.num<-int.num+1
}

}

but I get the error message: "Error in if (valsum == 1) { : argument is of 
length zero".  I checked whether to see if all the stated variables have 
associated values (and are not NAs) and every variable (even valsum!) has a 
value.  I have no idea where my error is. Can you help me?

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


Re: [R] custom sort?

2009-05-28 Thread Stavros Macrakis
I agree that it is surprising that R doesn't provide a sort function with a
comparison function as argument. Perhaps that is partly because calling out
to a function for each comparison is relatively expensive; R prefers vector
operations.

That said, many useful custom sorts are easy to define by reordering,
possibly using the 'order' function, e.g.

rr <- function (v) v[order( v %% 10 , v < 500, - v ) ]
# sort first by last digit (ascending), then by whether < 500, then by
magnitude (descending)

set.seed(2009)
rr(sample(1000,30))
 [1] 840 670 580 140 100  10 991 901 881 561 231  71 722 662 432 222  32
473  53
[20]  24 645 796  86 697 607 567 397 257  77 818 568 428 198 619 569 479 439
299

Hope this helps,

 -s

On Thu, May 28, 2009 at 6:06 PM, Steve Jaffe  wrote:

>
> hmm, that is what I was afraid of. I considered that but thought to myself,
> surely there must be an easier way.  I wonder why this feature isn't
> available. It's there in scripting languages, like perl, but also in
> "hardcore" languages like C++ where std::sort and sorted containers allow
> the user to provide a comparison function (even for builtin types like
> int).
> It's hard to believe that you have to jump through more hoops to do a
> custom
> sort in R than in C++ ...
>
>
> You put a class on the vector...
>
> --
> View this message in context:
> http://www.nabble.com/custom-sort--tp23770565p23770964.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] avoid a loop

2009-05-28 Thread David Winsemius


On May 28, 2009, at 5:45 PM, KARAVASILIS GEORGE wrote:


Hello, R users.
I have the following code:

a=1:10
b=-3:15
n=5
x <- rep(0,n)
for (i in 1:n) x[i] <- sum( outer(a,b, function(s,t)  abs(a-b-i)==0) )


You don't seem to be doing anything with s and t? Did you mean:

for (i in 1:n) x[i] <- sum( outer(a,b, function(s,t)  abs(s-t-i) == 0) )




Can someone tell me if I could avoid the for command?

Perhaps with the guess above:

> x <- sapply(1:n, function(i) { sum( outer(a,b, function(s,t)   
{abs(s-t-i)==0 } )) } )

> x
[1] 10 10 10 10  9




Thank you in advance.



Does your code actually run in 2,9.0?

(I'm still using using 2.8.1)

If this isn't useful, then perhaps you should tell us what problem you  
are trying to solve.

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] lattice::xyplot axis padding with fontfamily="mono"

2009-05-28 Thread Deepayan Sarkar
On Wed, May 27, 2009 at 4:38 PM, Benjamin Tyner  wrote:
> Hello,
>
> Say I have a predictor taking a very wide value:
>
>  Data <- data.frame(pred="a",resp=1)
>
>  print(xyplot(pred~resp, data=Data)) # enough y-axis padding to accommodate
> the wide label
>
>  print(xyplot(pred~resp, data=Data,scales=list(fontfamily="mono"))) # not
> enough padding

It's a bug in the layout calculations (fontfamily is not used).

> What's the recommended way to have enough padding allocated?

Ideally by fixing the bug, but that may not be easy to fix in the
short run. For one-off examples, you could increase the width
manually:

xyplot(pred~resp, data=Data,scales=list(fontfamily="mono"),
par.settings = list(layout.widths = list(axis.left = 1.1)))

-Deepayan

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


Re: [R] custom sort?

2009-05-28 Thread Steve Jaffe

hmm, that is what I was afraid of. I considered that but thought to myself,
surely there must be an easier way.  I wonder why this feature isn't
available. It's there in scripting languages, like perl, but also in
"hardcore" languages like C++ where std::sort and sorted containers allow
the user to provide a comparison function (even for builtin types like int).
It's hard to believe that you have to jump through more hoops to do a custom
sort in R than in C++ ...


You put a class on the vector...

-- 
View this message in context: 
http://www.nabble.com/custom-sort--tp23770565p23770964.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] max.col weirdness

2009-05-28 Thread Ben Bolker



Daryl Morris wrote:
> 
> Hi,
> Sorry, I was too hasty.  I see that the tolerance is in the 
> documentation (and that "random" is the default tie-breaker).
> 
> Would it be possible to allow tolerance to be a parameter?
> 
> thanks, Daryl
> 
> 

  Could you just use apply(x,1,which.max) ?

> x <- matrix(c(112345.568,112345.569,112345.567),1) 
> x
 [,1] [,2] [,3]
[1,] 112345.6 112345.6 112345.6
> apply(x,1,which.max)
[1] 2

  It will presumably be less efficient than max.col (which
is implemented in C), and will automatically
pick the first value of the maximum if there are ties, but
should be OK for everyday use?

PS  oddly enough apply(x,1,which.max) is faster -- maybe because
it doesn't try to deal with ties?

> benchmark(max.col(x),apply(x,1,which.max),replications=5)
test replications user.self sys.self elapsed user.child
2 apply(x, 1, which.max)5 7.6490.456   8.110  0
1 max.col(x)511.1850.580  11.828  0
  sys.child
2 0
1 0




-- 
View this message in context: 
http://www.nabble.com/max.col-weirdness-tp23769831p23770927.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Package for Clustering - Query

2009-05-28 Thread Lars Bishop
Dear R users,

Is there any package for Latent Class Analysis (to be used in a clustering
application) which supports mixed indicator variables (categorical and
continuous)?

Alternatively, is there any other clustering algorithm available that
supports this type of data?

Thanks in advance for your help.

Regards,

Lars.

[[alternative HTML version deleted]]

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


Re: [R] custom sort?

2009-05-28 Thread Duncan Murdoch

On 28/05/2009 5:34 PM, Steve Jaffe wrote:

Sounds simple but haven't been able to find it in docs: is it possible to
sort a vector using a user-defined comparison function? Seems it must be, 
but "sort" doesn't seem to provide that option, nor does "order" sfaics


You put a class on the vector (e.g. using class(x) <- "myvector"), then 
define a conversion to numeric (e.g. xtfrm.myvector) or actual 
comparison methods (you'll need ==.myvector, >.myvector, and 
is.na.myvector).


Duncan Murdoch

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


[R] avoid a loop

2009-05-28 Thread KARAVASILIS GEORGE

Hello, R users.
I have the following code:

a=1:10
b=-3:15
n=5
x <- rep(0,n)
for (i in 1:n) x[i] <- sum( outer(a,b, function(s,t)  abs(a-b-i)==0) )

Can someone tell me if I could avoid the for command?

Thank you in advance.

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


[R] why warning appears when set both 'scale' and 'breaks' meanwhile in heatmap.2 of gplots

2009-05-28 Thread Zheng, Xin (NIH) [C]
The warning I met with is attached here:

Warning message:
In heatmap.2(as.matrix(val.sf.ns[-1:-3]), Rowv = F, Colv = T, dendrogram = 
"column",  :
  Using scale="row" or scale="column" when breaks arespecified can produce 
unpredictable results.Please consider using only one or the other.


What does 'unpredictable results' mean? Could anyone explain that? Thanks a lot.

Xin Zheng


[[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] custom sort?

2009-05-28 Thread Steve Jaffe

Sounds simple but haven't been able to find it in docs: is it possible to
sort a vector using a user-defined comparison function? Seems it must be, 
but "sort" doesn't seem to provide that option, nor does "order" sfaics
-- 
View this message in context: 
http://www.nabble.com/custom-sort--tp23770565p23770565.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] max.col weirdness

2009-05-28 Thread Bert Gunter
Try reading the man page, which says:

Details

When ties.method = "random", as per default, ties are broken at random. In
this case, the determination of a tie assumes that the entries are
probabilities: there is a relative tolerance of 1e-5, relative to the
largest (in magnitude, omitting infinity) entry in the row.


Bert Gunter
Genentech Nonclinical Biostatistics

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Daryl Morris
Sent: Thursday, May 28, 2009 1:47 PM
To: r-help@r-project.org
Subject: [R] max.col weirdness

Hi,
I think there's some rounding issue with returning the max column.  
(running 2.9.0 on an Apple, but my buddy found it on his PC)

 > x <- matrix(c(1234.568,1234.569,1234.567),1)
 > max.col(x)
[1] 2
 > x <- matrix(c(12345.568,12345.569,12345.567),1)
 > max.col(x)
[1] 3
 > x <- matrix(c(112345.568,112345.569,112345.567),1)
 > max.col(x)
[1] 3
 > max.col(-x)
[1] 1

Thanks, Daryl

__
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] max.col weirdness

2009-05-28 Thread Daryl Morris

Hi,
Sorry, I was too hasty.  I see that the tolerance is in the 
documentation (and that "random" is the default tie-breaker).


Would it be possible to allow tolerance to be a parameter?

thanks, Daryl



Daryl Morris wrote:

Hi,
I think there's some rounding issue with returning the max column.  
(running 2.9.0 on an Apple, but my buddy found it on his PC)


> x <- matrix(c(1234.568,1234.569,1234.567),1)
> max.col(x)
[1] 2
> x <- matrix(c(12345.568,12345.569,12345.567),1)
> max.col(x)
[1] 3
> x <- matrix(c(112345.568,112345.569,112345.567),1)
> max.col(x)
[1] 3
> max.col(-x)
[1] 1

Thanks, Daryl





__
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] sample unique pairs from a matrix

2009-05-28 Thread jos matejus
Dear All,

Many thanks for all your useful suggestions. Much appreciated.

Jos

2009/5/28 David Winsemius :
> Your last step will either be a single number (not really a sampling
> operation) or a
> non-positive number. So at best you really only have an number that depends
> entirely on the prior sequence of draws.
>
> --
> David.
>
> On May 28, 2009, at 8:21 AM, jos matejus wrote:
>
>> Dear Ritchie and David,
>>
>> Thanks very much for your advice. I had thought of this potential
>> solution, however it doesn't really fullfill my second criteria which
>> is that once a particular cell has been sampled, the row and column of
>> that cell can't be sampled from subsequently. In other words, the next
>> sample would be taken from a 5x5 matrix, and then a 4x4 matrix and so
>> on until I have my 6 values.
>>
>> I will keep thinking!
>> Cheers
>> Jos
>>
>> 2009/5/28 David Winsemius :
>>>
>>> On May 28, 2009, at 6:33 AM, jos matejus wrote:
>>>
 Dear R users,

 I have a matrix of both negative and positive values that I would like
 to randomly sample with the following 2 conditions:

 1. only sample positive values
 2. once a cell in the matrix has been sampled the row and column of
 that cell cannot be sampled from again.

 #some dummy data
 set.seed(101)
 dataf <- matrix(rnorm(36,1,2), nrow=6)

 I can do this quite simply if all the values are positive by using the
 sample function without replacement on the column and row indices.

 samrow <- sample(6,replace=F)
 samcol <- sample(6,replace=F)
 values <- numeric(6)
 for(i in 1:6){
   values[i] <- dataf[samrow[i], samcol[i]]
 }

 However, I am not sure how to include the logical condition to only
 include postitive values
 Any help would be gratefully received.
 Jos
>>>
 M <- matrix(rnorm(36),nrow=6)
>>>
 M[M[,]>0]
>>>
>>>  [1] 1.65619781 0.56182830 0.23812890 0.81493915 1.01279243 1.29188874
>>> 0.64252343 0.53748655 0.31503112
>>> [10] 0.37245358 0.07942883 0.56834586 0.62200056 0.39478167 0.02374574
>>> 0.04974857 0.56219171 0.52901658
>>>
>>>
 sample(M[M[,]>0],6,replace=F)
>>>
>>> [1] 0.56834586 0.07942883 0.31503112 0.62200056 0.02374574 0.64252343
>>>
>>> --
>>> David Winsemius, MD
>>> Heritage Laboratories
>>> West Hartford, CT
>>>
>>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>

__
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] max.col weirdness

2009-05-28 Thread Daryl Morris

Hi,
I think there's some rounding issue with returning the max column.  
(running 2.9.0 on an Apple, but my buddy found it on his PC)


> x <- matrix(c(1234.568,1234.569,1234.567),1)
> max.col(x)
[1] 2
> x <- matrix(c(12345.568,12345.569,12345.567),1)
> max.col(x)
[1] 3
> x <- matrix(c(112345.568,112345.569,112345.567),1)
> max.col(x)
[1] 3
> max.col(-x)
[1] 1

Thanks, Daryl

__
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] ggplot2 legend

2009-05-28 Thread Felipe Carrillo

Thanks for your help Mike, it works like a charm now!!

--- On Thu, 5/28/09, Mike Lawrence  wrote:

> From: Mike Lawrence 
> Subject: Re: [R] ggplot2 legend
> To: "Felipe Carrillo" 
> Cc: r-h...@stat.math.ethz.ch
> Date: Thursday, May 28, 2009, 1:06 PM
> First, your example didn't work
> because fish_ByMuestreo didn't build
> properly (deleting the first "structure(list(data = " bit
> solves
> this).
> 
> To solve your plotting problem, note that as constructed,
> the Muestreo
> column is numeric, whereas you seem to want to treat it as
> a factor.
> Solution: convert to factor:
> 
> fish_ByMuestreo$Muestreo=factor(fish_ByMuestreo$Muestreo)
> 
> On Thu, May 28, 2009 at 3:47 PM, Felipe Carrillo
> 
> wrote:
> >
> > Hi:
> >  I need some help with the legend. I got 14
> samples(Muestreo) and I
> >  am trying to plot a smooth line for each sample. I
> am able to accomplish that but the problem is that the
> legend only displays every other sample. How can I force the
> legend to show all of my Muestreos? Thanks in advance.
> > library(ggplot2)
> > fishplot <-
>  qplot(PondName,BodyWeight.g.,data=fish_ByMuestreo,colour=Muestreo,position="jitter")+stat_summary(aes(group=Muestreo),fun.data="mean_cl_normal",
colour="green",geom="smooth",fill=NA)+
opts(title="Average weight(grs) by Pond")
print(fishplot)


> > Felipe D. Carrillo
> > Supervisory Fishery Biologist
> > Department of the Interior
> > US Fish & Wildlife Service
> > California, USA

> Mike Lawrence
> Graduate Student
> Department of Psychology
> Dalhousie University





__
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 this addition works?

2009-05-28 Thread Luc Villandre



bogaso.christofer wrote:

I have following addition :

 

  

1:2 + 1:10



 [1]  2  4  4  6  6  8  8 10 10 12

 


I could not understand how R adding those two unequal vector? Any help?


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

Hi,

R recycles the shorter vector to yield:

1+1 = 2
2+2 = 4
3+1 = 4
4+2 = 6
5+1 = 6
6+2 = 8

and so on. Is this what you wanted to know?

Cheers, 
--

*Luc Villandré*
/Biostatistician
McGill University Health Center -
Montreal Children's Hospital Research Institute/

__
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] ggplot2 legend

2009-05-28 Thread Mike Lawrence
First, your example didn't work because fish_ByMuestreo didn't build
properly (deleting the first "structure(list(data = " bit solves
this).

To solve your plotting problem, note that as constructed, the Muestreo
column is numeric, whereas you seem to want to treat it as a factor.
Solution: convert to factor:

fish_ByMuestreo$Muestreo=factor(fish_ByMuestreo$Muestreo)

On Thu, May 28, 2009 at 3:47 PM, Felipe Carrillo
 wrote:
>
> Hi:
>  I need some help with the legend. I got 14 samples(Muestreo) and I
>  am trying to plot a smooth line for each sample. I am able to accomplish 
> that but the problem is that the legend only displays every other sample. How 
> can I force the legend to show all of my Muestreos? Thanks in advance.
>
> fish_ByMuestreo <- structure(list(data = structure(list(SampleDate = 
> structure(c(3L,
> 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 16L, 16L, 16L, 7L, 7L, 7L, 7L,
> 10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 27L, 27L, 27L, 27L, 27L,
> 17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 24L, 24L, 24L, 24L, 24L,
> 30L, 30L, 30L, 30L, 42L, 42L, 42L, 42L, 42L, 33L, 33L, 33L, 33L,
> 36L, 36L, 36L, 36L, 36L, 39L, 39L, 39L, 39L, 39L, 39L, 14L, 14L,
> 14L, 14L, 14L, 14L, 5L, 5L, 5L, 8L, 8L, 8L, 11L, 11L, 11L, 11L,
> 15L, 15L, 15L, 28L, 28L, 28L, 28L, 28L, 18L, 18L, 18L, 18L, 18L,
> 22L, 22L, 22L, 22L, 25L, 25L, 25L, 25L, 40L, 40L, 40L, 40L, 40L,
> 31L, 31L, 31L, 31L, 37L, 37L, 37L, 37L, 1L, 1L, 1L, 1L, 1L, 3L,
> 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 16L, 16L, 16L, 7L, 7L, 7L, 7L,
> 10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 27L, 27L, 27L, 27L, 27L,
> 17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 24L, 24L, 24L, 24L, 24L,
> 30L, 30L, 30L, 30L, 42L, 42L, 42L, 42L, 42L, 33L, 33L, 33L, 33L,
> 36L, 36L, 36L, 36L, 36L, 14L, 14L, 14L, 14L, 14L, 14L, 5L, 5L,
> 5L, 8L, 8L, 8L, 11L, 11L, 11L, 11L, 15L, 15L, 15L, 28L, 28L,
> 28L, 28L, 28L, 18L, 18L, 18L, 18L, 18L, 22L, 22L, 22L, 22L, 25L,
> 25L, 25L, 25L, 40L, 40L, 40L, 40L, 40L, 31L, 31L, 31L, 31L, 34L,
> 34L, 34L, 34L, 34L, 37L, 37L, 37L, 37L, 1L, 1L, 1L, 1L, 1L, 6L,
> 6L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 12L, 12L, 12L, 21L, 21L, 21L,
> 21L, 29L, 29L, 29L, 19L, 19L, 19L, 19L, 19L, 23L, 23L, 23L, 23L,
> 23L, 26L, 26L, 26L, 26L, 41L, 41L, 41L, 41L, 32L, 32L, 32L, 32L,
> 32L, 35L, 35L, 35L, 35L, 38L, 38L, 38L, 38L, 38L, 2L, 2L, 2L,
> 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 16L, 16L, 16L, 7L, 7L,
> 7L, 7L, 10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 27L, 27L, 27L,
> 27L, 27L, 17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 24L, 24L, 24L,
> 24L, 24L, 30L, 30L, 30L, 30L, 42L, 42L, 42L, 42L, 42L, 33L, 33L,
> 33L, 33L, 36L, 36L, 36L, 36L, 36L, 39L, 39L, 39L, 39L, 39L, 39L,
> 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 16L, 16L, 16L, 7L, 7L, 7L,
> 7L, 10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 27L, 27L, 27L, 27L,
> 27L, 17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 24L, 24L, 24L, 24L,
> 24L, 30L, 30L, 30L, 30L, 42L, 42L, 42L, 42L, 42L, 33L, 33L, 33L,
> 33L, 36L, 36L, 36L, 36L, 36L, 39L, 39L, 39L, 39L, 39L, 39L), .Label = 
> c("10/2/2002",
> "10/4/2002", "6/23/2002", "6/30/2002", "7/10/2002", "7/12/2002",
> "7/14/2002", "7/17/2002", "7/19/2002", "7/21/2002", "7/24/2002",
> "7/26/2002", "7/28/2002", "7/3/2002", "7/31/2002", "7/7/2002",
> "8/11/2002", "8/14/2002", "8/16/2002", "8/18/2002", "8/2/2002",
> "8/21/2002", "8/23/2002", "8/25/2002", "8/28/2002", "8/30/2002",
> "8/4/2002", "8/7/2002", "8/9/2002", "9/1/2002", "9/11/2002",
> "9/13/2002", "9/15/2002", "9/18/2002", "9/20/2002", "9/22/2002",
> "9/25/2002", "9/27/2002", "9/29/2002", "9/4/2002", "9/6/2002",
> "9/8/2002"), class = "factor"), PondName = structure(c(1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
> 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
> 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
> 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
> 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
> 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6

Re: [R] How this addition works?

2009-05-28 Thread Sarah Goslee
R recycles the shorter one to match the longer one:

1  2  3  4  5  6  7  8  9 10
+
1  2  1  2  1  2  1   2  1   2
=
2  4  4  6  6  8  8 10 10 12

R does this recycling in many cases, and it can sometimes trap the
unwary.

Sarah

On Thu, May 28, 2009 at 4:00 PM, bogaso.christofer
 wrote:
> I have following addition :
>
>
>
>> 1:2 + 1:10
>
>  [1]  2  4  4  6  6  8  8 10 10 12
>
>
>
> I could not understand how R adding those two unequal vector? Any help?
>




-- 
Sarah Goslee
http://www.functionaldiversity.org

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


Re: [R] How this addition works?

2009-05-28 Thread baptiste auguie

recycling rule: repeat the shorter element as many times as necessary,

all.equal(1:2 + 1:10 , rep(1:2, length=10) + 1:10)
# TRUE

HTH,

baptiste

On 28 May 2009, at 22:00, bogaso.christofer wrote:


I have following addition :




1:2 + 1:10


[1]  2  4  4  6  6  8  8 10 10 12



I could not understand how R adding those two unequal vector? Any  
help?



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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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 this addition works?

2009-05-28 Thread Rolf Turner


On 29/05/2009, at 8:00 AM, bogaso.christofer wrote:


I have following addition :




1:2 + 1:10


 [1]  2  4  4  6  6  8  8 10 10 12



I could not understand how R adding those two unequal vector? Any  
help?


Look at the help for ``+'' (?"+") and look at ``Value''.  There you will
see:


These operators return vectors containing the result of the
element by element operations.  The elements of shorter vectors
are recycled as necessary (with a 'warning' when they are recycled
only _fractionally_).  The operators are '+' for addition, '-' for
subtraction, '*' for multiplication, '/' for division and '^' for
exponentiation.


The key word is ``recycled''.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
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] Labeling barplot bars by multiple factors

2009-05-28 Thread Thomas Levine
Ah, that makes sense. But now another two issues have arisen.

Firstly, the error bars look like confidence intervals, and I'm pretty
sure that they are but does some document verify this? I suppose I
could check the code too.

Secondly, I just read about how dynamite plots should be avoided. It's
quite easy to turn the dynamite plots into dot plots with Inkscape,
but is there an equivalent function that generates _hierarchical_ dot
plots?

Tom

On Thu, May 28, 2009 at 12:32 PM, William Dunlap  wrote:
>> -Original Message-
>> From: r-help-boun...@r-project.org
>> [mailto:r-help-boun...@r-project.org] On Behalf Of Thomas Levine
>> Sent: Thursday, May 28, 2009 5:04 AM
>> To: Jim Lemon
>> Cc: r-help@r-project.org
>> Subject: Re: [R] Labeling barplot bars by multiple factors
>>
>> Both of those worked, but hierobarp looked a bit easier, so I
>> used that. The
>> one annoying thing is that it sorts alphabetically.
>>
>> Tom
>
> The sorts of functions almost always order things by
> the order of the levels of your factors.  The default ordering
> is alphabetical (or increasing numeric, if your factor
> was made from numerical data).  To change the order remake
> the factor and supply the levels argument.  E.g., to reverse the
> order use rev:
>    data$someFactor <- factor(data$someFactor,
> levels=rev(levels(data$someFactor)))
>
> Bill Dunlap
> TIBCO Software Inc - Spotfire Division
> wdunlap tibco.com
>
>>
>> On Thu, May 28, 2009 at 6:46 AM, Jim Lemon  wrote:
>>
>> > Thomas Levine wrote:
>> >
>> >> I want to plot quantitative data as a function of three
>> two-level factors.
>> >> How do I group the bars on a barplot by level through labeling and
>> >> spacing?
>> >> Here
>> 's
>> >> what
>> >> I'm thinking of. Also, I'm pretty sure that I want a
>> barplot, but there
>> >> may
>> >> be something better.
>> >>
>> >>
>> >>
>> > Hi Tom,
>> > You may find that the hierobarp function in the plotrix
>> package will do
>> > what you want.
>> >
>> > Jim
>> >
>> >
>>
>>       [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

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


Re: [R] String replacement in an expression

2009-05-28 Thread William Dunlap


Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Wacek Kusnierczyk
> Sent: Thursday, May 28, 2009 12:31 PM
> To: Caroline Bazzoli
> Cc: r-help@r-project.org
> Subject: Re: [R] String replacement in an expression
> 
> Caroline Bazzoli wrote:
> > Dear R-experts,
> >
> > I need to replace in an expression the character "Cl" by "Cl+beta"
> >
> > But in the following case:
> >
> > form<-expression((Cl-(V *ka)  ) +(V   *Vm   *exp(-(Clm/Vm)   *t)))
> >
> > gsub("Cl","(Cl+beta)",as.character(form))
> >
> > We obtain:
> >
> > [1] "((Cl+beta) - (V * ka)) + (V * Vm * exp(-((Cl+beta)m/Vm) * t))"
> >
> >
> > the character "Clm" has been also replaced.
> >
> >
> > How could I avoid this unwanted replacement ?
> 
> try '\\bCl\\b' as the pattern, which says 'match Cl as a 
> separate word'.

That works in this case, but \\b idea of what a word is not
same as R's idea of what a name is.  E..g, \\b thinks that
a period is not in a word but R thinks periods in names are
fine.
   > gsub("\\bC1\\b", "(C1+beta)", "C1 * exp(C1.5 / C2.5)")
   [1] "(C1+beta) * exp((C1+beta).5 / C2.5)"
This is one more reason to use substitute(), which directly
edits an expression to produce a new one.  It avoids
the deparse-edit-parse cycle that can corrupt things
(even if you don't do any editing).
   > substitute(C1 * exp(C1.5 / C2.5), list(C1=Quote(C1+beta)))
   (C1 + beta) * exp(C1.5/C2.5)

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 

> 
> 
> vQ
> 
> __
> 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] filter function speed

2009-05-28 Thread Bishara, Anthony J
I am trying to use a linear filter to reduce loops and thereby increase
the speed of an existing program.  However,  while the "filter" function
(stats package) should have reduced the looping by about 30-fold, the
time to complete the program remained about the same.  This surprised
me, because I had made an analogous change to a Matlab version of the
same program using Matlab's "filter" function, and that change made the
program run about 9 times as fast.  

In R, is there another function that would be more efficient than
"filter" in the stats package?  Any advice would be appreciated, as I
would hate to see Matlab win this speed battle.

Relevant line from R code:
   
evTemp=filter(lambda*tempterm,1-lambda,method="recursive")
#lambda=scalar between 0 and 1 (representing learning rate in a
reinforcement learning model)
#tempterm=vector with from 1 to 150 elements (representing reinforcement
value data)


Thank you.

Anthony Bishara
Department of Psychology
College of Charleston
http://bisharaa.people.cofc.edu/

__
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 avoid add 'X' before numeric colnames when read.table

2009-05-28 Thread Zheng, Xin (NIH) [C]
substring(header, 2,) works for the purpose perfectly.

Xin Zheng


[[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] How this addition works?

2009-05-28 Thread bogaso.christofer
I have following addition :

 

> 1:2 + 1:10

 [1]  2  4  4  6  6  8  8 10 10 12

 

I could not understand how R adding those two unequal vector? Any help?


[[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 avoid add 'X' before numeric colnames when read.table

2009-05-28 Thread Zheng, Xin (NIH) [C]
Thank you guys. But I also want 'check.names' to help keeping colnames unique. 
It seems there's no proper option for that in 'read.table'. I have to alter 
colnames with strsplit or other similar functions.

From: jim holtman [mailto:jholt...@gmail.com]
Sent: Thursday, May 28, 2009 3:40 PM
To: Zheng, Xin (NIH) [C]
Cc: r-help@r-project.org
Subject: Re: [R] how to avoid add 'X' before numeric colnames when read.table

?read.table  check.names=FALSE
On Thu, May 28, 2009 at 3:25 PM, Zheng, Xin (NIH) [C] 
mailto:zheng...@mail.nih.gov>> wrote:
Hi all,

Is there any way to keep numeric colnames as is? Any hint will be appreicated.

Xin Zheng


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



--
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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 avoid add 'X' before numeric colnames when read.table

2009-05-28 Thread Greg Snow
This really depends on where the 'X' is coming from, which you did not tell us 
(see the posting guide).

For example, if the 'data.frame' function is the one adding the 'X', then you 
can use the 'check.names' argument to prevent the addition (or you can use 
data.frame with the argument to explicitly create your own data frame with the 
names you want, then pass that to the function that is doing the conversion 
currently).

If a different function is adding the 'X', then look at the help page for that 
function, or give us more to go on.

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Zheng, Xin (NIH) [C]
> Sent: Thursday, May 28, 2009 1:26 PM
> To: r-help@r-project.org
> Subject: [R] how to avoid add 'X' before numeric colnames when
> read.table
> 
> Hi all,
> 
> Is there any way to keep numeric colnames as is? Any hint will be
> appreicated.
> 
> Xin Zheng
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] how to avoid add 'X' before numeric colnames when read.table

2009-05-28 Thread jim holtman
?read.table  check.names=FALSE

On Thu, May 28, 2009 at 3:25 PM, Zheng, Xin (NIH) [C]  wrote:

> Hi all,
>
> Is there any way to keep numeric colnames as is? Any hint will be
> appreicated.
>
> Xin Zheng
>
>
>[[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] String replacement in an expression

2009-05-28 Thread Wacek Kusnierczyk
Caroline Bazzoli wrote:
> Dear R-experts,
>
> I need to replace in an expression the character "Cl" by "Cl+beta"
>
> But in the following case:
>
> form<-expression((Cl-(V *ka)  ) +(V   *Vm   *exp(-(Clm/Vm)   *t)))
>
> gsub("Cl","(Cl+beta)",as.character(form))
>
> We obtain:
>
> [1] "((Cl+beta) - (V * ka)) + (V * Vm * exp(-((Cl+beta)m/Vm) * t))"
>
>
> the character "Clm" has been also replaced.
>
>
> How could I avoid this unwanted replacement ?

try '\\bCl\\b' as the pattern, which says 'match Cl as a separate word'.

vQ

__
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] how to avoid add 'X' before numeric colnames when read.table

2009-05-28 Thread Zheng, Xin (NIH) [C]
Hi all,

Is there any way to keep numeric colnames as is? Any hint will be appreicated.

Xin Zheng


[[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] installing "gRain" package on ubuntu 8.10

2009-05-28 Thread Alex Biedermann

Dear all

I am trying to install the "gRain" package on ubuntu 8.10,
running R Vers. 2.9. Unfortunately, I get a bad
Exit-Status. What could cause that problem?

Any help is appreciated.
Many thanks in advance.

A. Biedermann



install.packages("gRain")
Warnung in install.packages("gRain") :
  Argument 'lib' fehlt: nutze
'/home/user1/R/i486-pc-linux-gnu-library/2.9'
versuche URL
'http://cran.ch.r-project.org/src/contrib/gRain_0.8.0.tar.gz'
Content type 'application/x-gzip' length 133482 bytes (130
Kb)
URL geöffnet
==
downloaded 130 Kb

* Installing *source* package ‘gRain’ ...
** R
** demo
** inst
** preparing package for lazy loading
Error in library(pkg, character.only = TRUE,
logical.return = TRUE, lib.loc = lib.loc) :
  'gRbase' is not a valid installed package
Fehler: lazy loading failed für Paket ‘gRain’
* Removing
‘/home/user1/R/i486-pc-linux-gnu-library/2.9/gRain’

Die heruntergeladenen Pakete sind in
‘/tmp/RtmpgVRO21/downloaded_packages’
Warning message:
In install.packages("gRain") :
  Installation des Pakets 'gRain' hatte Exit-Status ungleich
0

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


Re: [R] plotting time series with data gap using type line- but do not want to connect gap with line

2009-05-28 Thread Gabor Grothendieck
Just place a point with an NA value between the two segments.
Here is one way to do it in zoo:

set.seed(123)
library(zoo)

# create sample data
tt <- c(1:1000, 1200:2000)
z <- zoo(rnorm(length(tt)), tt)

# this will fill in omitted values with NAs
z <- as.zoo(as.ts(z))

plot(z)



On Thu, May 28, 2009 at 3:05 PM,   wrote:
> I have a time series of about 1500 measurements.  There are sporadic data
> gaps.  I would like to plot the time series with type "line".  I only want
> a line to connect the periods with data; I don't want a line to connect
> the points across a data gap.  Is there a function or recommended method
> to deal with this?
>
> For example
> there are 2000 days
> days 1:1000 each have one measurement of temperature
> days 1001: 1199 have no data
> days 1200:2000 each have one measurement of temperature
>
> I want the plot to connect points 1:1000 with a line, and to connect
> points 1200: 2000 with a different  line. I don't want a line to connect
> points 1001:1200.
>
> I searched the help archives and google but couldn't find anything. Any
> advice?
>
>
>
> JK
>        [[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] plotting time series with data gap using type line- but do not want to connect gap with line

2009-05-28 Thread Josef . Kardos
I have a time series of about 1500 measurements.  There are sporadic data 
gaps.  I would like to plot the time series with type "line".  I only want 
a line to connect the periods with data; I don't want a line to connect 
the points across a data gap.  Is there a function or recommended method 
to deal with this?

For example
there are 2000 days
days 1:1000 each have one measurement of temperature
days 1001: 1199 have no data
days 1200:2000 each have one measurement of temperature

I want the plot to connect points 1:1000 with a line, and to connect 
points 1200: 2000 with a different  line. I don't want a line to connect 
points 1001:1200. 

I searched the help archives and google but couldn't find anything. Any 
advice?



JK
[[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] Changing point color/character in qqmath

2009-05-28 Thread Kevin W
Apologies once more, there was a slight error in our example.  Here is a
correct version of how to color the points in qqmath according to another
variable.

qqmath(~ yield | variety, data = barley, groups=year,
   auto.key=TRUE,
   prepanel = function(x, ...) {
 list(xlim = range(qnorm(ppoints(length(x)
   },
   panel = function(x, ...) {
 qx <- qnorm(ppoints(length(x)))[rank(x)]
 panel.xyplot(qx, x, ...)
   })

Kevin


On Wed, May 27, 2009 at 4:39 PM, Kevin W  wrote:

> Thanks to Deepayan, I have a corrected version of how to color points in a
> qqmath plot according to another variable.  Using the barley data for a more
> concise example::
>
> qqmath(~ yield | variety, data = barley, groups=year,
>auto.key=TRUE,
>   prepanel = function(x, ...) {
>   list(xlim = range(qnorm(ppoints(length(x)
>   },
>   panel = function(x, ...) {
>   xx <- qnorm(ppoints(length(x)))[order(x)]
>   panel.xyplot(x = xx, y = x, ...)
>   })
>
>
> The example I posted previously (and shown below) is not correct.  My
> apologies.
>
> Kevin
>
>
> On Wed, May 27, 2009 at 11:05 AM, Kevin W  wrote:
>
>> Having solved this problem, I am posting this so that the next time I
>> search for how to do this I will find an answer...
>>
>> Using qqmath(..., groups=num) creates a separate qq distribution for each
>> group (within a panel).  Using the 'col' or 'pch' argument does not
>> (usually) work because panel.qqmath sorts the data (but not 'col' or 'pch')
>> before plotting.  Sorting the data before calling qqmath will ensure that
>> the sorting does not change the order of the data.
>>
>> For example, to obtain one distribution per voice part and color the point
>> by part 1 or part 2:
>>
>> library(lattice)
>> singer <- singer
>> singer <- singer[order(singer$height),]
>> singer$part <- factor(sapply(strsplit(as.character(singer$voice.part),
>> split = " "), "[", 1),
>>  levels = c("Bass", "Tenor", "Alto", "Soprano"))
>> singer$num <- factor(sapply(strsplit(as.character(singer$voice.part),
>> split = " "), "[", 2))
>> qqmath(~ height | part, data = singer,
>>col=singer$num,
>>layout=c(4,1))
>>
>>
>>
>> Kevin
>>
>>
>

[[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] ggplot2 legend

2009-05-28 Thread Felipe Carrillo

Hi:
  I need some help with the legend. I got 14 samples(Muestreo) and I
  am trying to plot a smooth line for each sample. I am able to accomplish that 
but the problem is that the legend only displays every other sample. How can I 
force the legend to show all of my Muestreos? Thanks in advance.

fish_ByMuestreo <- structure(list(data = structure(list(SampleDate = 
structure(c(3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 16L, 16L, 16L, 7L, 7L, 7L, 7L,
10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 27L, 27L, 27L, 27L, 27L,
17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 24L, 24L, 24L, 24L, 24L,
30L, 30L, 30L, 30L, 42L, 42L, 42L, 42L, 42L, 33L, 33L, 33L, 33L,
36L, 36L, 36L, 36L, 36L, 39L, 39L, 39L, 39L, 39L, 39L, 14L, 14L,
14L, 14L, 14L, 14L, 5L, 5L, 5L, 8L, 8L, 8L, 11L, 11L, 11L, 11L,
15L, 15L, 15L, 28L, 28L, 28L, 28L, 28L, 18L, 18L, 18L, 18L, 18L,
22L, 22L, 22L, 22L, 25L, 25L, 25L, 25L, 40L, 40L, 40L, 40L, 40L,
31L, 31L, 31L, 31L, 37L, 37L, 37L, 37L, 1L, 1L, 1L, 1L, 1L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 16L, 16L, 16L, 7L, 7L, 7L, 7L,
10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 27L, 27L, 27L, 27L, 27L,
17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 24L, 24L, 24L, 24L, 24L,
30L, 30L, 30L, 30L, 42L, 42L, 42L, 42L, 42L, 33L, 33L, 33L, 33L,
36L, 36L, 36L, 36L, 36L, 14L, 14L, 14L, 14L, 14L, 14L, 5L, 5L,
5L, 8L, 8L, 8L, 11L, 11L, 11L, 11L, 15L, 15L, 15L, 28L, 28L,
28L, 28L, 28L, 18L, 18L, 18L, 18L, 18L, 22L, 22L, 22L, 22L, 25L,
25L, 25L, 25L, 40L, 40L, 40L, 40L, 40L, 31L, 31L, 31L, 31L, 34L,
34L, 34L, 34L, 34L, 37L, 37L, 37L, 37L, 1L, 1L, 1L, 1L, 1L, 6L,
6L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 12L, 12L, 12L, 21L, 21L, 21L,
21L, 29L, 29L, 29L, 19L, 19L, 19L, 19L, 19L, 23L, 23L, 23L, 23L,
23L, 26L, 26L, 26L, 26L, 41L, 41L, 41L, 41L, 32L, 32L, 32L, 32L,
32L, 35L, 35L, 35L, 35L, 38L, 38L, 38L, 38L, 38L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 16L, 16L, 16L, 7L, 7L,
7L, 7L, 10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 27L, 27L, 27L,
27L, 27L, 17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 24L, 24L, 24L,
24L, 24L, 30L, 30L, 30L, 30L, 42L, 42L, 42L, 42L, 42L, 33L, 33L,
33L, 33L, 36L, 36L, 36L, 36L, 36L, 39L, 39L, 39L, 39L, 39L, 39L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 16L, 16L, 16L, 7L, 7L, 7L,
7L, 10L, 10L, 10L, 13L, 13L, 13L, 13L, 13L, 27L, 27L, 27L, 27L,
27L, 17L, 17L, 17L, 17L, 20L, 20L, 20L, 20L, 24L, 24L, 24L, 24L,
24L, 30L, 30L, 30L, 30L, 42L, 42L, 42L, 42L, 42L, 33L, 33L, 33L,
33L, 36L, 36L, 36L, 36L, 36L, 39L, 39L, 39L, 39L, 39L, 39L), .Label = 
c("10/2/2002",
"10/4/2002", "6/23/2002", "6/30/2002", "7/10/2002", "7/12/2002",
"7/14/2002", "7/17/2002", "7/19/2002", "7/21/2002", "7/24/2002",
"7/26/2002", "7/28/2002", "7/3/2002", "7/31/2002", "7/7/2002",
"8/11/2002", "8/14/2002", "8/16/2002", "8/18/2002", "8/2/2002",
"8/21/2002", "8/23/2002", "8/25/2002", "8/28/2002", "8/30/2002",
"8/4/2002", "8/7/2002", "8/9/2002", "9/1/2002", "9/11/2002",
"9/13/2002", "9/15/2002", "9/18/2002", "9/20/2002", "9/22/2002",
"9/25/2002", "9/27/2002", "9/29/2002", "9/4/2002", "9/6/2002",
"9/8/2002"), class = "factor"), PondName = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L), .Label = c("Pond01",
"Pond02", "Pond03", "Pond04", "Pond05", "Pond06", "Pond07"), class = "factor"),
Muestreo = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 7L, 7L,
7L, 7L, 7L, 8L, 8L, 8L, 8L, 

Re: [R] Hmisc package: deff() command's formula for the design effect

2009-05-28 Thread jjh21

One additional question:

It seems that in practice the design effect is often calculated on the
response variable or on individual predictor variables. I have some OLS
models using observational data that are clustered. Does it make sense to
calculate the design effect on the residuals of one of these models to see
the extent to which there is still clustering left even after including
covariates?



Thomas Lumley wrote:
> 
> The formula in Hmisc is correct (if the correlation doesn't vary with the 
> cluster size).  If you think of the formula for the variance of a sum, it 
> involves adding up all the variances and covariances.  A cluster of size k 
> has k^2-k covariances between members, so the total number of covariances 
> is sum(k^2-k) over all the clusters, plus the sum(k) variances.
> 
> Another way to think of it is that the larger clusters get too much 
> weight, so in addition to the rho*(B-1) factor that you would have for 
> equal-sized clusters there is an additional loss of efficiency due to 
> giving too much weight to the larger clusters.
> 
>   -thomas
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Hmisc-package%3A-deff%28%29-command%27s-formula-for-the-design-effect-tp23415477p23767287.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] boxplot

2009-05-28 Thread Dieter Menne



amor Gandhi wrote:
> 
> Hi gues,
> 

This should read: Hi, guess what I want
 

amor Gandhi wrote:
> 
> Is there any function in R for boxplot with different time points?
> t1 <- c(rep(1,20),rep(2,20))
> t2 <- c(rep(1,10),rep(2,10),rep(1,10),rep(2,10))
> x <- rnorm(40,5,1)
> dat <- data.frame(t1,t2,x)
> 
> boxplot(x~t1,t2)
> 
> 

This might come close

library(lattice)
t1 <- c(rep(1,20),rep(2,20))
t2 <- c(rep(1,10),rep(2,10),rep(1,10),rep(2,10))
x <- rnorm(40,5,1)
dat <- data.frame(t1=as.factor(t1),t2=as.factor(t2),x)
bwplot(x~t1|t2,data=dat)
bwplot(t1+t2~x,data=dat,outer=TRUE)



-- 
View this message in context: 
http://www.nabble.com/boxplot-tp23752278p23767111.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] String replacement in an expression

2009-05-28 Thread William Dunlap
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Caroline Bazzoli
> Sent: Thursday, May 28, 2009 8:41 AM
> To: r-help@r-project.org
> Subject: [R] String replacement in an expression
> 
> Dear R-experts,
> 
> I need to replace in an expression the character "Cl" by "Cl+beta"
> 
> But in the following case:
> 
> form<-expression((Cl-(V *ka)  ) +(V   *Vm   *exp(-(Clm/Vm)   *t)))
> 
> gsub("Cl","(Cl+beta)",as.character(form))
> 
> We obtain:
> 
> [1] "((Cl+beta) - (V * ka)) + (V * Vm * exp(-((Cl+beta)m/Vm) * t))"
> 
> 
> the character "Clm" has been also replaced.
> 
> 
> How could I avoid this unwanted replacement ?

I like to use substitute(), which works with the expression
as an expression, instead of converting it to a string, changing
it, and then parsing the result to make the new expression.
E.g.,

  > form<-expression((Cl-(V *ka)  ) +(V   *Vm   *exp(-(Clm/Vm)   *t)))
  > do.call("substitute", list(form[[1]], list(Cl=Quote(Cl+beta
  (Cl + beta - (V * ka)) + (V * Vm * exp(-(Clm/Vm) * t))
  
Note how it adds parentheses where appropriate:
  > do.call("substitute", list(form[[1]], list(Cl=Quote(Cl+beta), 
Clm=Quote(Clm+gamma
  (Cl + beta - (V * ka)) + (V * Vm * exp(-((Clm + gamma)/Vm) *  t))
 
The do.call() is needed in this case because substitute() does not
evaluate its first argument and the do.call takes care of evaluating
the variable 'form' so substitute sees its value.  (S+'s substitute()
has an evaluator=FALSE/TRUE argument to let you avoid the do.call().)

R's substitute() doesn't seem to go into expression objects, hence
I passed it the first element of the expression and it returned the
converted first element.  You could wrap the output with as.expression
if you really wanted the expression object output.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 

> 
> Thank you in advance for any help.
> 
> -- 
> -
> Caroline BAZZOLI
> 
> 
> INSERM U738 - Université PARIS 7
> UFR de Medecine - Site Bichat
> 16 rue Henri Huchard
> 75018 PARIS, FRANCE
> email: caroline.bazz...@inserm.fr
> 
> www.biostat.fr 
> PFIM: www.pfim.biostat.fr
> 
> __
> 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] Neural Network resource

2009-05-28 Thread jude.ryan
The package AMORE appears to be more flexible, but I got very poor
results using it when I tried to improve the predictive accuracy of a
regression model. I don't understand all the options well enough to be
able to fine tune it to get better predictions. However, using the
nnet() function in package VR gave me decent results and is pretty easy
to use (see the Venables and Ripley book, Modern Applied Statistics with
S, pages 243 to 249, for more details). I tried using package neuralnet
as well but the neural net failed to converge. I could not figure out
how to set the threshold option (or other options) to get the neural net
to converge. I explored package neural as well. Of all these 4 packages,
the nnet() function in package VR worked the best for me.

 

As another R user commented as well, you have too many hidden layers and
too many neurons. In general you do not need more than 1 hidden layer.
One hidden layer is sufficient for the "universal approximator" property
of neural networks to hold true. As you keep adding neurons to the one
hidden layer, the problem becomes more and more non-linear. If you add
too many neurons you will overfit. In general, you do not need to add
more than 10 neurons. The activation function in the hidden layer of
Venables and Ripley's nnet() function is logistic, and you can specify
the activation function in the output layer to be linear using linout =
T in nnet(). Using one hidden layer, and starting with one hidden neuron
and working up to 10 hidden neurons, I built several neural nets (4,000
records) and computed the training MSE. I also computed the validation
MSE on a holdout sample of over 1,000 records. I also started with 2
variables and worked up to 15 variables in a "for" loop, so in all, I
built 140 neural nets using 2 "for" loops, and stored the results in
lists. I arranged my variables in the data frame based on correlations
and partial correlations so that I could easily add variables in a "for"
loop. This was my "crude" attempt to simulate variable selection since,
from what I have seen, neural networks do not have variable selection
methods. In my particular case, neural networks gave me marginally
better results than regression. It all depends on the problem. If the
data has non-linear patterns, neural networks will be better than linear
regression.

 

My code is below. You can modify it to suit your needs if you find it
useful. There are probably lines in the code that are redundant which
can be deleted.

 

HTH.

 

Jude Ryan

 

My code:

 

# set order in data frame train2 based on correlations and partial
correlations

train2 <- train[, c(5,27,19,20,25,26,4,9,3,10,16,6,2,14,21,28)]

dim(train2)

names(train2)

library(nnet)

# skip = T

# train 10 neural networks in a loop and find the one with the minimum
test and validation error

# create various lists to store the results of the neural network
running in two for loops

# The Column List is for the outer for loop, which loops over variables

# The Row List is for the inner for loop, which loops over number of
neurons in the hidden layer

col_nn <- list()  # stores the results of nnet() over variables - outer
loop

row_nn <- list()  # stores the results of nnet() over neurons - inner
loop

col_mse <- list()

# row_mse <- list() # not needed because nn.mse is a data frame with
rows

col_sum <- list()

row_sum <- list()

col_vars <- list()

row_vars <- list()

col_wts <- list()

row_wts <- list()

df_dim <- dim(train2)

df_dim[2]  # number of variables

df_dim[2] - 1

num_of_neurons <- 10

# build data frame to store results of neural net for each run

nn.mse <- data.frame(Train_MSE=seq(1:num_of_neurons),
Valid_MSE=seq(1:num_of_neurons))

# open log file and redirect output to log file

sink("D:\\XXX\\YYY\\ Programs\\Neural_Network_v8_VR_log.txt")

# outer loop - loop over variables

for (i in 3:df_dim[2]) {  # df_dim[2]

  # inner loop - loop over number of hidden neurons

  for (j in 1:num_of_neurons) { # upto 10 neurons in the hidden layer

# need to create a new data frame with just the predictor/input
variables needed

train3 <- train2[,c(1:i)]

coreaff.nn <- nnet(dep_var ~ ., train3, size = j, decay = 1e-3,
linout = T, skip = T, maxit = 1000, Hess = T)

# row_vars[[j]] <- coreaff.nn$call # not what we want

# row_vars[[j]] <- names(train3)[c(2:i)] # not needed in inner loop
- same number of variables for all neurons

row_sum[[j]] <- summary(coreaff.nn)

row_wts[[j]] <- coreaff.nn$wts

rownames(nn.mse)[j] <- paste("H", j, sep="")

nn.mse[j, "Train_MSE"] <- mean((train3$dep_var -
predict(coreaff.nn))^2)

nn.mse[j, "Valid_MSE"] <- mean((valid$dep_var - predict(coreaff.nn,
valid))^2)

  }

  col_vars[[i-2]] <- names(train3)[c(2:i)]

  col_sum[[i-2]] <- row_sum

  col_wts[[i-2]] <- row_wts

  col_mse[[i-2]] <- nn.mse

}

# cbind(col_vars[1],col_vars[2])

col_vars

col_sum

col_wts

sink()

cbind(col_mse[[1]],col_mse[[2]],col_mse[[3]],col_mse[[4]],col_mse[[5]

Re: [R] can you help me please :)

2009-05-28 Thread Stefan Grosse
On Thu, 28 May 2009 15:47:18 +0300 NOUF AL NUMAIR
 wrote:

NAN>  barplot(zz,width = 4,names.arg= xx,axes = TRUE, axisnames = TRUE,
NAN> main=title,xlab=xlab,ylab=ylab,ylim=c(0,1175),xlim=c(0,226),col =
NAN> c(for (i in zz){if i>70 col= "lightblue" else col= "mistyrose"))
NAN> 
NAN> 
NAN> i tried to get red of zero then plot it 

? I have no idea what this means...

NAN> i want to color different result with different colors ?
NAN> 
NAN> any body can help plaaaeee

If you want help try to be more clear about what you want. It is hard
with your mail because there is so much what does not belong to your
current problem, one has to scroll over plenty of numbers and still I am
not sure whether I understood what you want.

Hence you want your bar color conditional on the value or the height,
it is helpful to create a vector beforehand.(for control purposes)

y<-c(1175,  483,  240,  170,   99,   79,   76,   45,   38,   35,
21,   16,   14,   19,   16) 
x<-c( 1,   2,   3,   4,   5,   6,   7,
8,   9,  10,  11,  12,  13,  14,  15) 

d1<-data.frame(x=x,y=y)

Color<-ifelse(d1$y<70,"blue","red")

barplot(as.matrix(d1$y),names.arg=d1$x,col=Color,beside=T)

as an example.

hth
Stefan

__
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] getTree visualization (randomForest)

2009-05-28 Thread Károly Kovács
Dear All,

I would like to visualize a tree extracted from a random forest using
getTree {randomForest}.
I'm wondering if there is any way to do it directly or to convert my tree
to any other class of tree repesentation, which then can be plotted?

Thank you in advance,
Karoly

__
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] String replacement in an expression

2009-05-28 Thread Gabor Grothendieck
Try matching on word boundaries as well:

> gsub("\\bCl\\b","(Cl+beta)",as.character(form))
[1] "((Cl+beta) - (V * ka)) + (V * Vm * exp(-(Clm/Vm) * t))"

See ?regexp

On Thu, May 28, 2009 at 11:41 AM, Caroline Bazzoli
 wrote:
> Dear R-experts,
>
> I need to replace in an expression the character "Cl" by "Cl+beta"
>
> But in the following case:
>
> form<-expression((Cl-(V *ka)  ) +(V   *Vm   *exp(-(Clm/Vm)   *t)))
>
> gsub("Cl","(Cl+beta)",as.character(form))
>
> We obtain:
>
> [1] "((Cl+beta) - (V * ka)) + (V * Vm * exp(-((Cl+beta)m/Vm) * t))"
>
>
> the character "Clm" has been also replaced.
>
>
> How could I avoid this unwanted replacement ?
>
>
> Thank you in advance for any help.
>
> --
> -
> Caroline BAZZOLI
>
>
> INSERM U738 - Université PARIS 7
> UFR de Medecine - Site Bichat
> 16 rue Henri Huchard
> 75018 PARIS, FRANCE
> email: caroline.bazz...@inserm.fr
>
> www.biostat.fr PFIM: www.pfim.biostat.fr
>
> __
> 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] String replacement in an expression

2009-05-28 Thread Caroline Bazzoli

Dear R-experts,

I need to replace in an expression the character "Cl" by "Cl+beta"

But in the following case:

form<-expression((Cl-(V *ka)  ) +(V   *Vm   *exp(-(Clm/Vm)   *t)))

gsub("Cl","(Cl+beta)",as.character(form))

We obtain:

[1] "((Cl+beta) - (V * ka)) + (V * Vm * exp(-((Cl+beta)m/Vm) * t))"


the character "Clm" has been also replaced.


How could I avoid this unwanted replacement ?


Thank you in advance for any help.

--
-
Caroline BAZZOLI


INSERM U738 - Université PARIS 7
UFR de Medecine - Site Bichat
16 rue Henri Huchard
75018 PARIS, FRANCE
email: caroline.bazz...@inserm.fr

www.biostat.fr 
PFIM: www.pfim.biostat.fr


__
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] maximum over one dimension of a 3-dimensional array

2009-05-28 Thread David Winsemius


On May 28, 2009, at 11:25 AM, eric lee wrote:


Hi,

I'm running R 2.7.2 on windows XP.  I'd like to find the maximum of a
3-d array over it's third index to create a 2-d array.  For example:


x <- array(c(1,2,3,10,11,12,3:8),c(2,3,2))
x

, , 1

[,1] [,2] [,3]
[1,]13   11
[2,]2   10   12

, , 2

[,1] [,2] [,3]
[1,]357
[2,]468


x1 <- x[,,1]
x2 <- x[,,2]
pmax(x1,x2)

[,1] [,2] [,3]
[1,]35   11
[2,]4   10   12


Consider:

> apply(x, 1:2, max)
 [,1] [,2] [,3]
[1,]35   11
[2,]4   10   12

or

> apply(x, c(1,2), max)  # not necessarily adjacent dimensions
 [,1] [,2] [,3]
[1,]35   11
[2,]4   10   12







Is there a pre-defined function that I can use to do this without
using a for-loop?  Also, the third index can be long and of variable
length, so I don't want to explicitly write out x1, x2,...  Thanks in
advance for your help.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] sample unique pairs from a matrix

2009-05-28 Thread David Winsemius
Your last step will either be a single number (not really a sampling  
operation) or a
non-positive number. So at best you really only have an number that  
depends

entirely on the prior sequence of draws.

--
David.

On May 28, 2009, at 8:21 AM, jos matejus wrote:


Dear Ritchie and David,

Thanks very much for your advice. I had thought of this potential
solution, however it doesn't really fullfill my second criteria which
is that once a particular cell has been sampled, the row and column of
that cell can't be sampled from subsequently. In other words, the next
sample would be taken from a 5x5 matrix, and then a 4x4 matrix and so
on until I have my 6 values.

I will keep thinking!
Cheers
Jos

2009/5/28 David Winsemius :


On May 28, 2009, at 6:33 AM, jos matejus wrote:


Dear R users,

I have a matrix of both negative and positive values that I would  
like

to randomly sample with the following 2 conditions:

1. only sample positive values
2. once a cell in the matrix has been sampled the row and column of
that cell cannot be sampled from again.

#some dummy data
set.seed(101)
dataf <- matrix(rnorm(36,1,2), nrow=6)

I can do this quite simply if all the values are positive by using  
the

sample function without replacement on the column and row indices.

samrow <- sample(6,replace=F)
samcol <- sample(6,replace=F)
values <- numeric(6)
for(i in 1:6){
   values[i] <- dataf[samrow[i], samcol[i]]
}

However, I am not sure how to include the logical condition to only
include postitive values
Any help would be gratefully received.
Jos



M <- matrix(rnorm(36),nrow=6)



M[M[,]>0]
 [1] 1.65619781 0.56182830 0.23812890 0.81493915 1.01279243  
1.29188874

0.64252343 0.53748655 0.31503112
[10] 0.37245358 0.07942883 0.56834586 0.62200056 0.39478167  
0.02374574

0.04974857 0.56219171 0.52901658



sample(M[M[,]>0],6,replace=F)

[1] 0.56834586 0.07942883 0.31503112 0.62200056 0.02374574 0.64252343

--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT




David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] maximum over one dimension of a 3-dimensional array

2009-05-28 Thread eric lee
Hi,

I'm running R 2.7.2 on windows XP.  I'd like to find the maximum of a
3-d array over it's third index to create a 2-d array.  For example:

> x <- array(c(1,2,3,10,11,12,3:8),c(2,3,2))
> x
, , 1

 [,1] [,2] [,3]
[1,]13   11
[2,]2   10   12

, , 2

 [,1] [,2] [,3]
[1,]357
[2,]468

> x1 <- x[,,1]
> x2 <- x[,,2]
> pmax(x1,x2)
 [,1] [,2] [,3]
[1,]35   11
[2,]4   10   12

Is there a pre-defined function that I can use to do this without
using a for-loop?  Also, the third index can be long and of variable
length, so I don't want to explicitly write out x1, x2,...  Thanks in
advance for your help.

eric

__
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] question about using a remote system

2009-05-28 Thread Greg Snow
Will R be able to send one batch of commands to the remote machine, then wait 
for the output?  Or will there be back and forth with new commands based on the 
output from the first commands?

You may want to look at the nws package for one way to have jobs run on a 
remote machine.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Erin Hodgess
> Sent: Thursday, May 28, 2009 6:56 AM
> To: Mark Wardle
> Cc: R help
> Subject: Re: [R] question about using a remote system
> 
> My goal is for a user to sit down at a Linux laptop, get to an Rcmdr
> type screen, submit jobs on a remote system and then get the results
> back in R.
> 
> We will assume that the user is naive, and the only thing he/she can
> do is get to the Rcmdr screen.
> 
> The Rcmdr plugin will have a "submit jobs" menu.  The user presses
> that option, and gets results, without having to know the "underside".
> 
> thanks,
> Erin
> 
> On Thu, May 28, 2009 at 1:54 AM, Mark Wardle  wrote:
> > Hi.
> >
> > Do you need an interactive session at the remote machine, or are you
> > simply wanting to run a pre-written script?
> >
> > If the latter, then you can ask ssh to execute a remote command,
> which
> > conceivably could be "R CMD x"
> >
> > If you explain exactly why and what you are trying to do, then
> perhaps
> > there's a better solution
> >
> > bw
> >
> > Mark
> >
> > 2009/5/28 Erin Hodgess :
> >> Dear R People:
> >>
> >> I would like to set up a plug-in for Rcmdr to do the following:
> >>
> >> I would start on a Linux laptop.  Then I would log into another
> >> outside system and run a some commands.
> >>
> >> Now, when I tried to do
> >> system("ssh e...@xxx.edu")
> >> password xx
> >>
> >> It goes to the remote system.  how do I continue to issue commands
> >> from the Linux laptop please?
> >>
> >> (hope this makes sense)
> >>
> >> thanks,
> >> Erin
> >>
> >>
> >> --
> >> Erin Hodgess
> >> Associate Professor
> >> Department of Computer and Mathematical Sciences
> >> University of Houston - Downtown
> >> mailto: erinm.hodg...@gmail.com
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> >
> >
> >
> > --
> > Dr. Mark Wardle
> > Specialist registrar, Neurology
> > Cardiff, UK
> >
> 
> 
> 
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

2009-05-28 Thread Richard . Cotton
> I want to plot data such that the 3 time points(a,b,c) lie on the X-axis 
and
> the values of these times points are on Y-axis for n samples (e.g.100).
> 
> So, I have an object x, dim 100 4, it is a dataframe (when checked the
> class)
> x = 
> name   a   b  c
> 10.11  1.11   0.86
> 2   .  .   .
> 3   .  .   .
> .
> .
> .
> 100
> 
> so when i say:
> 
> > plot(1:3, x[,2:4], type="l") - I get the error below
> 
> Error in xy.coords(x, y, xlabel, ylabel, log) : 
>(list) object cannot be coerced to type 'double'
> 
> However if I do:
> > plot(1:3, x[1,2:4], type="l") -- It works for the 1st row, and 
each
> > individual row BUT NOT ALL ROWS
> 
> Please could someone explain what is happening here?
> 
> I wonder if I need to use 'lines' for the remaining, BUT I have another
> dataset y with same dimensions as x, which I want to plot on the same
> graph/plot to see the difference between x and y.

Your data looks like this:
x <- data.frame(name=sample(letters, 10), a=runif(10), b=rnorm(10), 
c=rlnorm(10))

The problem is that the subset x[,2:4] is also a data frame, not a matrix.
class(x[,2:4])  #[1] "data.frame"

The simplest thing is probably to use lines, as you say.
row <- seq_len(nrow(x))
xx <- x[,2:4]
plot(row, xx$a, ylim=range(xx), type="l")
lines(row, xx$b, col="blue")
lines(row, xx$c, col="green")

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

__
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] Urgent Statistician Position near Philadelphia

2009-05-28 Thread José Ignacio Bustos Melo
Dear R-list,

I know is going to be weird, but I need to do something about and I know
the R-list is big group of good people. I’m moving to Philadelphia in
August 2009 (my fiancé is there) and I need to find a job. I know to do so
many things, but my skill is in science and research. I would like to know
if you know a possible position near Philadelphia, New Jersey or New York.

I was working in so many projects, doing statistical analysis, research in
parasitology, cancer research and public health in dentistry problems.  I
would love to work doing cancer research or public health. I was working
with cancer epidemiology using survival analysis and modeling.

I know how work and programing with many softwares, R, SAS, S-plus,
MathLab. I know too Statistica y SPSS in any version.

You are free to give advice to me. I’m applying in so many web pages, but
does not work. I don’t have any problem with visa to be in USA, just I
need some help.

I will send you my resume if you ask me

Best Regards,



   O__   José Bustos M.
  c/ /'_ --- Master in Applied Statistics (University of Concepcion)
 (*) \(*) -- B.S. in Marine Biology (Catholic University of Concepcion)
-Science Faculty
-Catholic University of Concepcion
-Alonso de Ribera 2850 – Concepción, Casilla 297
-Cell phone: +56 9 9 5939144

__
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] Changing data point size in quilt.plot

2009-05-28 Thread Wilson, R.C.
Hi,

I am new to R and am using quilt.plot (from fields package) to plot gas 
concentrations in Europe.

I am using the following code to plot my data
library(maps)
library(fields)

test = read.csv("%change 1996_2005.txt", sep="\t")
colnames(test) = c("Station", "Measurement_BaseO3", "Model_BaseO3", 
"Measuerment_PeakO3",
"Model_PeakO3", "Longitude", "Latitude")

quilt.plot(test$Longitude, test$Latitude, test$Model_BaseO3,
breaks = c(-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50), col = 
tim.colors(10),
xlim=c(-11,25), ylim=c(40,60), zlim=c(-50, 50), xlab="Longitude", 
ylab="Latitude", asp=1,
main="Modelled Base Ozone")

map(add=TRUE)

It all plots beautifully, except the size of the plotted data points is far too 
small.  I have tried using "cex = xx" into quilt.plot() to change the size of 
the data points but that doesn't seem to work. Maybe I am just using this 
wrong?!

I was wondering if someone could help me to alter the data point size (increase 
it to x 3 the current size).

Thanks,

Becca

[[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] Plot error

2009-05-28 Thread NatsS

Hello,

I am an R amateur.

I want to plot data such that the 3 time points(a,b,c) lie on the X-axis and
the values of these times points are on Y-axis for n samples (e.g.100).

So, I have an object x, dim 100 4, it is a dataframe (when checked the
class)
x = 
name   a   b  c
10.11  1.11   0.86
2   .  .   .
3   .  .   .
.
.
.
100

so when i say:

> plot(1:3, x[,2:4], type="l") - I get the error below

Error in xy.coords(x, y, xlabel, ylabel, log) : 
   (list) object cannot be coerced to type 'double'

However if I do:
> plot(1:3, x[1,2:4], type="l") -- It works for the 1st row, and each
> individual row BUT NOT ALL ROWS

Please could someone explain what is happening here?

I wonder if I need to use 'lines' for the remaining, BUT I have another
dataset y with same dimensions as x, which I want to plot on the same
graph/plot to see the difference between x and y.

Thanks,
NS
-- 
View this message in context: 
http://www.nabble.com/Plot-error-tp23761408p23761408.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] re gularly spaced points on multi-segement line

2009-05-28 Thread PLAFF

Dear all ...

I need your help for the following purpose :

I would like to create regularly spaced points on a multi-segment line (a
'psp class' object).

A function of the spatstat library( = pointsOnLines() ) is dedicated to that
objective but the problem is that the probability of falling on a particular
segment is proportional to the length of each segment of the multi-segment
line.

What about a solution using the whole multi-segment line and not individual
segments for points distribution ? 

Many thanks in advance for your help !

Plaff
-- 
View this message in context: 
http://www.nabble.com/regularly-spaced-points-on-multi-segement-line-tp23761782p23761782.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Re ad & name multiple excel sheets using RODBC

2009-05-28 Thread Erich Neuwirth
Using the package rcom (by Thomas Baier) you can do everything you want
since you have the full power of COM at your disposal.


Dieter Menne wrote:
> 
> 
> Hans-Peter Suter wrote:
>>> If you only have the sheet names, you should use package xlsReadWrite
>>> which
>>> is rather fast, but has some limitations in the non-commercial version.
>> what limitations, i.e. features do you miss?
>>
>>
> 
> Reading of named ranges.
> 
> Dieter
> 

-- 
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459

__
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] Re ad & name multiple excel sheets using RODBC

2009-05-28 Thread Dieter Menne



Hans-Peter Suter wrote:
> 
>> If you only have the sheet names, you should use package xlsReadWrite
>> which
>> is rather fast, but has some limitations in the non-commercial version.
> 
> what limitations, i.e. features do you miss?
> 
> 

Reading of named ranges.

Dieter

-- 
View this message in context: 
http://www.nabble.com/Read---name-multiple-excel-sheets-using-RODBC-tp23760020p23761745.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] [Rd] split strings

2009-05-28 Thread William Dunlap


Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com  

> -Original Message-
> From: r-devel-boun...@r-project.org 
> [mailto:r-devel-boun...@r-project.org] On Behalf Of Wacek Kusnierczyk
> Sent: Thursday, May 28, 2009 5:30 AM
> Cc: R help project; r-de...@r-project.org; Allan Engelhardt
> Subject: Re: [Rd] [R] split strings
> 
> (diverted to r-devel, a source code patch attached)
> 
> Wacek Kusnierczyk wrote:
> > Allan Engelhardt wrote:
> >   
> >> Immaterial, yes, but it is always good to test :) and your solution
> >> *is* faster and it is even faster if you can assume byte strings:
> >> 
> >
> > :)
> >
> > indeed;  though if the speed is immaterial (and in this case it
> > supposedly was), it's probably not worth risking fixed=TRUE removing
> > '.tif' from the middle of the name, however unlikely this 
> might be (cf
> > murphy's laws).
> >
> > but if you can assume that each string ends with a '.tif' 
> (or any other
> > \..{3} substring), then substr is marginally faster than 
> sub, even as a
> > three-pass approach, while avoiding the risk of removing 
> '.tif' from the
> > middle:
> >
> > strings = sprintf('f:/foo/bar//%s.tif', replicate(1000,
> > paste(sample(letters, 10), collapse='')))
> > library(rbenchmark)
> > benchmark(columns=c('test', 'elapsed'), 
> replications=1000, order=NULL,
> >substr={basenames=basename(strings); substr(basenames, 1,
> > nchar(basenames)-4)},
> >sub=sub('.tif', '', basename(strings), fixed=TRUE, 
> useBytes=TRUE))
> > # test elapsed
> > # 1 substr   3.176
> > # 2sub   3.296
> >   
> 
> btw., i wonder why negative indices default to 1 in substr:
> 
> substr('foobar', -5, 5)
> # "fooba"
> # substr('foobar', 1, 5)
> substr('foobar', 2, -2)
> # ""
> # substr('foobar', 2, 1)
> 
> this does not seem to be documented in ?substr.

Would your patched code affect the following
use of regexpr's output as input to substr, to
pull out the matched text from the string?
   > x<-c("ooo","good food","bad")
   > r<-regexpr("o+", x)
   > substring(x,r,attr(r,"match.length")+r-1)
   [1] "ooo" "oo"  ""   
   > substr(x,r,attr(r,"match.length")+r-1)
   [1] "ooo" "oo"  ""   
   > r
   [1]  1  2 -1
   attr(,"match.length")
   [1]  3  2 -1
   > attr(r,"match.length")+r-1
   [1]  3  3 -3
   attr(,"match.length")
   [1]  3  2 -1

>  there are 
> ways to make
> negative indices meaningful, e.g., by taking them as indexing from
> behind (as in, e.g., perl):
> 
> # hypothetical
> substr('foobar', -5, 5)
> # "ooba"
> # substr('foobar', 6-5+1, 5)
> substr('foobar', 2, -2)
> # "ooba"
> # substr('foobar', 2, 6-2+1)
> 
> there is a trivial fix to src/main/character.c that gives substr the
> extended functionality -- see the attached patch.  the patch has been
> created and tested as follows:
> 
> svn co https://svn.r-project.org/R/trunk r-devel
> cd r-devel
> # modifications made to src/main/character.c
> svn diff > character.c.diff
> svn revert -R .
> patch -p0 < character.c.diff
>
> ./configure
> make
> make check-all
> # no problems reported
> 
> with the patched substr, the original problem can now be solved more
> concisely, using a two-pass approach, with performance still 
> better than
> the sub/fixed/bytes one, as follows:
> 
> strings = sprintf('f:/foo/bar//%s.tif', replicate(1000,
> paste(sample(letters, 10), collapse='')))
> library(rbenchmark)
> benchmark(columns=c('test', 'elapsed'), 
> replications=1000, order=NULL,
> substr=substr(basename(strings), 1, -5),
> 'substr-nchar'={
> basenames=basename(strings)
> substr(basenames, 1, nchar(basenames)-4) },
> sub=sub('.tif', '', basename(strings), fixed=TRUE, 
> useBytes=TRUE))
> # test elapsed
> # 1   substr   2.981
> # 2 substr-nchar   3.206
> # 3  sub   3.273
> 
> if this sounds interesting, i can update the docs accordingly.
> 
> vQ
> 

__
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] Re ad & name multiple excel sheets using RODBC

2009-05-28 Thread Hans-Peter Suter
2009/5/28 Dieter Menne :
> If you only have the sheet names, you should use package xlsReadWrite which
> is rather fast, but has some limitations in the non-commercial version.

what limitations, i.e. features do you miss?

Cheers,
Hans-Peter

__
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 could I terminate a script (without leaving R)?

2009-05-28 Thread Duncan Murdoch

On 5/28/2009 8:58 AM, Mario Valle wrote:

Good morning!
Which is the preferred method to leave a sourced script and returning back to the 
'>' prompt?

For example I search for certain files to be processed, but nothing should be 
done if they
are not present. Normally I do in my script:
f<-dir(pattern="qq")
if(length(f) > 0) {
...process file list...
}
# script end

But I don't like those {} encompassing the whole script so I'm searching for 
something to
put in place of the '???' here:
f<-dir(pattern="qq")
if(length(f) == 0) '???'
...process file list...
# script end

Using stop("No file found", call.=F) works, but the Error message is ugly in 
this case.

Any suggestion?


Put the code in a function, call the function as the last line of the 
script, and return from the function when you want to exit the script.


Duncan Murdoch

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


[R] can you help me please :)

2009-05-28 Thread NOUF AL NUMAIR


hi there :)
i want to use barplot with if else but i dont know how to do it ?
i tried this but it is not working with me 

SNP <- read.table("my.txt")

 >SNP[,2]
  [1] 1175  483  240  170   99   79   76   45   38   35   21   16   14   19   16
 [16]333   1021686820511
 [31]10620   13050501000
 [46]055010000000000
 [61]000000000000007
 [76]000030000000000
 [91]000000000000030
[106]000000000000000
[121]000000000000000
[136]100011000000000
[151]000000000000000
[166]002000000100000
[181]000000000000001
[196]000000000000000
[211]000000001000000
[226]1

>SNP[,2] == 0
  [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
 [25] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE
 [37]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
 [49]  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 [61]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 [73]  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE
 [85]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
 [97]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE
[109]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[121]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[133]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE
[145]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[157]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE
[169]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[181]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[193]  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[205]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
[217]  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE


> SNP[,2][SNP[,2] == 0]
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[112] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[149] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

> SNP[,2][! SNP[,2] == 0]
 [1] 1175  483  240  170   99   79   76   45   38   35   21   16   14   19   16
[16]333   1021686825111
[31]62   13551551733111
[46]2111   

> SNP[,1]

  [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
 [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
 [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
 [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
 [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
 [91]  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108
[109] 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
[127] 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
[145] 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
[163] 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
[181] 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
[199] 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
[217] 217 218 219 220 221 222 223 224 225 226

> zz <- SNP[,2][! SNP[,2] == 0]
> zz
 [1] 1175  483  240  170   99   79   76   45   38   35   21   16   14   19   16
[16]333   1021686825111
[31]62   13551551733111
[46]21111

 [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19
[20]  20  21  22  23  24  25  26  28 

Re: [R] R-help Digest, Vol 75, Issue 28

2009-05-28 Thread Ista Zahn
> >> From: Jeff Newmiller 
> >> To: "R Heberto Ghezzo, Dr" 
> >> Date: Wed, 27 May 2009 09:00:44 -0700
> >> Subject: Re: [R] R in Ubunto
> >> R Heberto Ghezzo, Dr wrote:
> >>
> >>    Hello , I do not know anything abount Ubunto, but I found a Portable 
> >> Ubunto for Windows and since so many people
> >>    prefer Linux to Windows I decided to give it a try.
> >>    It runs very nicely, so I tried to load R, following Instructions in 
> >> CRAN I added the line
> >>    deb http://probability.ca/cran/bin/linux/ubuntu hardy/ to 
> >> /etc/apt/sources.list and then from a console
> >>    I did
> >>    sudo apt-get update
> >>    sudo apt-get install r-base
> >>    a lot of printout and when it inishes I typed R in the console and 
> >> surprise!
> >>    I got R 2.6.2!! in Windows I have R 2.9.0??
> >>    Did I do something wrong or there is another way to get the latest 
> >> version of R?
>
>>> From: stephen sefick 
>>> To: "R Heberto Ghezzo, Dr" 
>>> Date: Wed, 27 May 2009 11:51:25 -0400
>>> Subject: Re: [R] R in Ubunto
>>> I don't remember what the version of R in deb repositories is, but
>>> 2.6.2 is probably about right.  One of the things the Debian project
>>> is focused on is the stability of the operating system, so they do not
>>> update packages as readily as some other distributions.  I had this
>>> with Debian 5.0 and just decided to compile R from source after
>>> getting the R development package and some x11 development libraries.
>>>
>>> sudo apt-get install r-base-dev
>>>
>>>
>>> I can help you through this process if you like, or there are good
>>> instructions for this process at the R website.
>>>
>>> FAQ 2.5.1 How can R be installed (Unix)
>
> > On the web page
> >
> > http://probability.ca/cran/bin/linux/ubuntu/
> >
> > it presents instructions for activating this repository.  Special
> > instructions are included for hardy regarding activating backports
> > also.

I'm running the latest Ubuntu version, and I get the latest version of
R no problem. I see that
http://probability.ca/cran/bin/linux/ubuntu/hardy/ does list R 2.9.0,
so it seems to me that if the repository was correctly added you
should get it. Were there any errors when you ran sudo apt-get update?
Also, I second the idea of activating the backports repository.

-Ista

__
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] How could I terminate a script (without leaving R)?

2009-05-28 Thread Mario Valle
Good morning!
Which is the preferred method to leave a sourced script and returning back to 
the '>' prompt?

For example I search for certain files to be processed, but nothing should be 
done if they
are not present. Normally I do in my script:
f<-dir(pattern="qq")
if(length(f) > 0) {
...process file list...
}
# script end

But I don't like those {} encompassing the whole script so I'm searching for 
something to
put in place of the '???' here:
f<-dir(pattern="qq")
if(length(f) == 0) '???'
...process file list...
# script end

Using stop("No file found", call.=F) works, but the Error message is ugly in 
this case.

Any suggestion?

Thanks for your help!
mario

-- 
Ing. Mario Valle
Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)  | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82

__
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] question about using a remote system

2009-05-28 Thread Erin Hodgess
My goal is for a user to sit down at a Linux laptop, get to an Rcmdr
type screen, submit jobs on a remote system and then get the results
back in R.

We will assume that the user is naive, and the only thing he/she can
do is get to the Rcmdr screen.

The Rcmdr plugin will have a "submit jobs" menu.  The user presses
that option, and gets results, without having to know the "underside".

thanks,
Erin

On Thu, May 28, 2009 at 1:54 AM, Mark Wardle  wrote:
> Hi.
>
> Do you need an interactive session at the remote machine, or are you
> simply wanting to run a pre-written script?
>
> If the latter, then you can ask ssh to execute a remote command, which
> conceivably could be "R CMD x"
>
> If you explain exactly why and what you are trying to do, then perhaps
> there's a better solution
>
> bw
>
> Mark
>
> 2009/5/28 Erin Hodgess :
>> Dear R People:
>>
>> I would like to set up a plug-in for Rcmdr to do the following:
>>
>> I would start on a Linux laptop.  Then I would log into another
>> outside system and run a some commands.
>>
>> Now, when I tried to do
>> system("ssh e...@xxx.edu")
>> password xx
>>
>> It goes to the remote system.  how do I continue to issue commands
>> from the Linux laptop please?
>>
>> (hope this makes sense)
>>
>> thanks,
>> Erin
>>
>>
>> --
>> Erin Hodgess
>> Associate Professor
>> Department of Computer and Mathematical Sciences
>> University of Houston - Downtown
>> mailto: erinm.hodg...@gmail.com
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
>
> --
> Dr. Mark Wardle
> Specialist registrar, Neurology
> Cardiff, UK
>



-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


Re: [R] Still can't find missing data

2009-05-28 Thread Dieter Menne



Farley, Robert wrote:
> 
> I can't get the syntax that will allow me to show NA values (rows) in the
> xtabs.
> 
> lengthy non-reproducible example removed
> 

If you want a reproducible answer, prepare a reproducible result. And check
that the 
syntax is 

na.action=na.pass

Dieter




-- 
View this message in context: 
http://www.nabble.com/Still-can%27t-find-missing-data-tp23730627p23761006.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Re ad & name multiple excel sheets using RODBC

2009-05-28 Thread Dieter Menne



simeon duckworth wrote:
> 
> I'd like to be able to read multiple sheets from an excel workbook and use
> the sheet name to name the resulting dataframe using RODBC.  
> 

In Microsoft theory, something like the below should be ok (note the $), but
never managed to get this to work. The same method works perfectly when you
have name ranges within a spreadsheet.

If you only have the sheet names, you should use package xlsReadWrite which
is rather fast, but has some limitations in the non-commercial version.

Dieter


library(RODBC)
filepath <- "workbook.xlsx"
tabls  = list()
channel <- odbcConnectExcel2007(filepath)
for (i in 1:2)
  tabls[[i]] =  sqlQuery(channel, paste("SELECT * from
[Tabelle",i,"$]",sep=""))
odbcClose(channel) # I prefer an explicit odbcClose, but generic close.RODBC
should work.



-- 
View this message in context: 
http://www.nabble.com/Read---name-multiple-excel-sheets-using-RODBC-tp23760020p23760912.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] split strings

2009-05-28 Thread Wacek Kusnierczyk
(diverted to r-devel, a source code patch attached)

Wacek Kusnierczyk wrote:
> Allan Engelhardt wrote:
>   
>> Immaterial, yes, but it is always good to test :) and your solution
>> *is* faster and it is even faster if you can assume byte strings:
>> 
>
> :)
>
> indeed;  though if the speed is immaterial (and in this case it
> supposedly was), it's probably not worth risking fixed=TRUE removing
> '.tif' from the middle of the name, however unlikely this might be (cf
> murphy's laws).
>
> but if you can assume that each string ends with a '.tif' (or any other
> \..{3} substring), then substr is marginally faster than sub, even as a
> three-pass approach, while avoiding the risk of removing '.tif' from the
> middle:
>
> strings = sprintf('f:/foo/bar//%s.tif', replicate(1000,
> paste(sample(letters, 10), collapse='')))
> library(rbenchmark)
> benchmark(columns=c('test', 'elapsed'), replications=1000, order=NULL,
>substr={basenames=basename(strings); substr(basenames, 1,
> nchar(basenames)-4)},
>sub=sub('.tif', '', basename(strings), fixed=TRUE, useBytes=TRUE))
> # test elapsed
> # 1 substr   3.176
> # 2sub   3.296
>   

btw., i wonder why negative indices default to 1 in substr:

substr('foobar', -5, 5)
# "fooba"
# substr('foobar', 1, 5)
substr('foobar', 2, -2)
# ""
# substr('foobar', 2, 1)

this does not seem to be documented in ?substr.  there are ways to make
negative indices meaningful, e.g., by taking them as indexing from
behind (as in, e.g., perl):

# hypothetical
substr('foobar', -5, 5)
# "ooba"
# substr('foobar', 6-5+1, 5)
substr('foobar', 2, -2)
# "ooba"
# substr('foobar', 2, 6-2+1)

there is a trivial fix to src/main/character.c that gives substr the
extended functionality -- see the attached patch.  the patch has been
created and tested as follows:

svn co https://svn.r-project.org/R/trunk r-devel
cd r-devel
# modifications made to src/main/character.c
svn diff > character.c.diff
svn revert -R .
patch -p0 < character.c.diff
   
./configure
make
make check-all
# no problems reported

with the patched substr, the original problem can now be solved more
concisely, using a two-pass approach, with performance still better than
the sub/fixed/bytes one, as follows:

strings = sprintf('f:/foo/bar//%s.tif', replicate(1000,
paste(sample(letters, 10), collapse='')))
library(rbenchmark)
benchmark(columns=c('test', 'elapsed'), replications=1000, order=NULL,
substr=substr(basename(strings), 1, -5),
'substr-nchar'={
basenames=basename(strings)
substr(basenames, 1, nchar(basenames)-4) },
sub=sub('.tif', '', basename(strings), fixed=TRUE, useBytes=TRUE))
# test elapsed
# 1   substr   2.981
# 2 substr-nchar   3.206
# 3  sub   3.273

if this sounds interesting, i can update the docs accordingly.

vQ
__
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] sample unique pairs from a matrix

2009-05-28 Thread jim holtman
This is one way of sampling all the values in the matrix that meet your
criteria:

> set.seed(1)
> (x <- matrix(rnorm(100), 10))
[,1][,2][,3][,4]   [,5]
[,6][,7] [,8]   [,9]  [,10]
 [1,] -0.6264538  1.51178117  0.91897737  1.35867955 -0.1645236  0.3981059
2.40161776  0.475509529 -0.5686687 -0.5425200
 [2,]  0.1836433  0.38984324  0.78213630 -0.10278773 -0.2533617 -0.6120264
-0.03924000 -0.709946431 -0.1351786  1.2078678
 [3,] -0.8356286 -0.62124058  0.07456498  0.38767161  0.6969634  0.3411197
0.68973936  0.610726353  1.1780870  1.1604026
 [4,]  1.5952808 -2.21469989 -1.98935170 -0.05380504  0.5566632 -1.1293631
0.02800216 -0.934097632 -1.5235668  0.7002136
 [5,]  0.3295078  1.12493092  0.61982575 -1.37705956 -0.6887557  1.4330237
-0.74327321 -1.253633400  0.5939462  1.5868335
 [6,] -0.8204684 -0.04493361 -0.05612874 -0.41499456 -0.7074952  1.9803999
0.18879230  0.291446236  0.3329504  0.5584864
 [7,]  0.4874291 -0.01619026 -0.15579551 -0.39428995  0.3645820 -0.3672215
-1.80495863 -0.443291873  1.0630998 -1.2765922
 [8,]  0.7383247  0.94383621 -1.47075238 -0.05931340  0.7685329 -1.0441346
1.46555486  0.001105352 -0.3041839 -0.5732654
 [9,]  0.5757814  0.82122120 -0.47815006  1.10002537 -0.1123462  0.5697196
0.15325334  0.074341324  0.3700188 -1.2246126
[10,] -0.3053884  0.59390132  0.41794156  0.76317575  0.8811077 -0.1350546
2.17261167 -0.589520946  0.2670988 -0.4734006
> # create new matrix with R/C indicator
> x.ind <- cbind(R=as.vector(row(x)), C=as.vector(col(x)), val=as.vector(x))
> # only keep positive values
> x.ind <- x.ind[x.ind[, 'val'] >= 0,, drop=FALSE]
> # now loop and select a value then delete others in the same R/C
> while (nrow(x.ind) > 0){
+ i <- sample(nrow(x.ind), 1)
+ cat("sample:", x.ind[i,], "\n")
+ # remove matching R/C
+ x.ind <- x.ind[!((x.ind[, "R"] == x.ind[i, "R"]) | (x.ind[, "C"] ==
x.ind[i, "C"])),, drop=FALSE]
+ }
sample: 3 3 0.07456498
sample: 8 2 0.9438362
sample: 4 7 0.02800216
sample: 10 4 0.7631757
sample: 9 1 0.5757814
sample: 5 9 0.5939462
sample: 1 8 0.4755095
sample: 7 5 0.3645820
sample: 6 6 1.9804
sample: 2 10 1.207868
>


On Thu, May 28, 2009 at 8:21 AM, jos matejus wrote:

> Dear Ritchie and David,
>
> Thanks very much for your advice. I had thought of this potential
> solution, however it doesn't really fullfill my second criteria which
> is that once a particular cell has been sampled, the row and column of
> that cell can't be sampled from subsequently. In other words, the next
> sample would be taken from a 5x5 matrix, and then a 4x4 matrix and so
> on until I have my 6 values.
>
> I will keep thinking!
> Cheers
> Jos
>
> 2009/5/28 David Winsemius :
>  >
> > On May 28, 2009, at 6:33 AM, jos matejus wrote:
> >
> >> Dear R users,
> >>
> >> I have a matrix of both negative and positive values that I would like
> >> to randomly sample with the following 2 conditions:
> >>
> >> 1. only sample positive values
> >> 2. once a cell in the matrix has been sampled the row and column of
> >> that cell cannot be sampled from again.
> >>
> >> #some dummy data
> >> set.seed(101)
> >> dataf <- matrix(rnorm(36,1,2), nrow=6)
> >>
> >> I can do this quite simply if all the values are positive by using the
> >> sample function without replacement on the column and row indices.
> >>
> >> samrow <- sample(6,replace=F)
> >> samcol <- sample(6,replace=F)
> >> values <- numeric(6)
> >> for(i in 1:6){
> >>values[i] <- dataf[samrow[i], samcol[i]]
> >> }
> >>
> >> However, I am not sure how to include the logical condition to only
> >> include postitive values
> >> Any help would be gratefully received.
> >> Jos
> >
> >> M <- matrix(rnorm(36),nrow=6)
> >
> >> M[M[,]>0]
> >  [1] 1.65619781 0.56182830 0.23812890 0.81493915 1.01279243 1.29188874
> > 0.64252343 0.53748655 0.31503112
> > [10] 0.37245358 0.07942883 0.56834586 0.62200056 0.39478167 0.02374574
> > 0.04974857 0.56219171 0.52901658
> >
> >
> >> sample(M[M[,]>0],6,replace=F)
> > [1] 0.56834586 0.07942883 0.31503112 0.62200056 0.02374574 0.64252343
> >
> > --
> > David Winsemius, MD
> > Heritage Laboratories
> > West Hartford, CT
> >
> >
>
> __
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[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] sample unique pairs from a matrix

2009-05-28 Thread jos matejus
Dear Ritchie and David,

Thanks very much for your advice. I had thought of this potential
solution, however it doesn't really fullfill my second criteria which
is that once a particular cell has been sampled, the row and column of
that cell can't be sampled from subsequently. In other words, the next
sample would be taken from a 5x5 matrix, and then a 4x4 matrix and so
on until I have my 6 values.

I will keep thinking!
Cheers
Jos

2009/5/28 David Winsemius :
>
> On May 28, 2009, at 6:33 AM, jos matejus wrote:
>
>> Dear R users,
>>
>> I have a matrix of both negative and positive values that I would like
>> to randomly sample with the following 2 conditions:
>>
>> 1. only sample positive values
>> 2. once a cell in the matrix has been sampled the row and column of
>> that cell cannot be sampled from again.
>>
>> #some dummy data
>> set.seed(101)
>> dataf <- matrix(rnorm(36,1,2), nrow=6)
>>
>> I can do this quite simply if all the values are positive by using the
>> sample function without replacement on the column and row indices.
>>
>> samrow <- sample(6,replace=F)
>> samcol <- sample(6,replace=F)
>> values <- numeric(6)
>> for(i in 1:6){
>>        values[i] <- dataf[samrow[i], samcol[i]]
>> }
>>
>> However, I am not sure how to include the logical condition to only
>> include postitive values
>> Any help would be gratefully received.
>> Jos
>
>> M <- matrix(rnorm(36),nrow=6)
>
>> M[M[,]>0]
>  [1] 1.65619781 0.56182830 0.23812890 0.81493915 1.01279243 1.29188874
> 0.64252343 0.53748655 0.31503112
> [10] 0.37245358 0.07942883 0.56834586 0.62200056 0.39478167 0.02374574
> 0.04974857 0.56219171 0.52901658
>
>
>> sample(M[M[,]>0],6,replace=F)
> [1] 0.56834586 0.07942883 0.31503112 0.62200056 0.02374574 0.64252343
>
> --
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
>

__
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] Labeling barplot bars by multiple factors

2009-05-28 Thread Thomas Levine
Both of those worked, but hierobarp looked a bit easier, so I used that. The
one annoying thing is that it sorts alphabetically.

Tom

On Thu, May 28, 2009 at 6:46 AM, Jim Lemon  wrote:

> Thomas Levine wrote:
>
>> I want to plot quantitative data as a function of three two-level factors.
>> How do I group the bars on a barplot by level through labeling and
>> spacing?
>> Here 's
>> what
>> I'm thinking of. Also, I'm pretty sure that I want a barplot, but there
>> may
>> be something better.
>>
>>
>>
> Hi Tom,
> You may find that the hierobarp function in the plotrix package will do
> what you want.
>
> Jim
>
>

[[alternative HTML version deleted]]

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


Re: [R] How do I get removed from this mailing list?

2009-05-28 Thread Peter Dalgaard
Wacek Kusnierczyk wrote:
> Gavin Simpson wrote:
>> The "View message source" would be a more direct way of viewing the full
>> email, not just the bits TBird shows you in the preview pane. I forget
>> how it is named exactly and under which menu it is found as it has been
>> quite a while since I used TBird.
>>   
> 
> indeed;  it's C-U, or under view >> message source

Nice, thanks.


-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
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] Full likelihood from survreg

2009-05-28 Thread Terry Therneau
> How can I find out what survreg generates: the full likelihood or a
> likelihood with "unnecessary" constants dropped?

 Survreg returns a log-likelihood, not a deviance (LL with parameters dropped); 
and the result is labeled as such.  
 
It turns out that the deviance is not as easily defined for censored data.

Terry Therneau

__
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] Read & name multiple excel sheets using RODBC

2009-05-28 Thread simeon duckworth
I'd like to be able to read multiple sheets from an excel workbook and use
the sheet name to name the resulting dataframe using RODBC.  at the moment
i've figured out how to do it the long way (see below) but feel sure that
there is a speedier & possibly automatic way to do it in R.  i've tried to
run a loop using sqlTables but it seemed to break the connection.  unless
i've missed something, i cant see a solution to this on the help list.

grateful for any help or pointers

simeon

# long way
library(RODBC)
filepath <- "C:/Data/workbook.xlsx"
connect <- odbcConnectExcel2007(filepath)
tbls <- sqlTables(connect)
sheet1 <-sqlFetch(channel=connect,sqtable='sheet1')
sheet2 <-sqlFetch(channel=connect,sqtable='sheet2')
sheet3 <-sqlFetch(channel=connect,sqtable='sheet3')
.. etc
close(connect)

[[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] no internal function "int.unzip" in R 2.9.0 for Windows

2009-05-28 Thread Uwe Ligges
Will respond privately, since the thread becomes uninteresting for 
R-help, I guess.


Uwe


Romain Francois wrote:

Hello Uwe,

I have recently taken over maintenance of the package, which is now 
version controlled at r-forge 
(http://r-forge.r-project.org/projects/r2html/), and I am planning these 
changes:
- rework the HTML function so that the html code is generated from a 
brew template, which in time will give more control to the user/package 
using R2HTML
- enhance the sweave html driver so that it can take advantage of the 
source code highlighter I am currently writing.


Do you know the extent of the modification. I'd like to propagate this 
to the r-forge version.


Romain

Uwe Ligges wrote:


The most recent version on CRAN is already fixed. We had a 
non-maintainer update end of March that fixed the R2HTML issues - the 
maintainer was unresponsive to our requests, unfortunately.


Hence please update from CRAN.

Best,
Uwe Ligges



Romain Francois wrote:

Hi,

I'll try to fix this soon. Could you log a bug request here:
http://r-forge.r-project.org/tracker/?atid=1643&group_id=405&func=browse

Regards,

Romain

Carson, John wrote:

library(R2HTML)



Loading required package: R2HTML

Error in .Internal(int.unzip(zipname, NULL, dest)) :
  no internal function "int.unzip"

Error : .onLoad failed in 'loadNamespace' for 'R2HTML'

Error: package 'R2HTML' could not be loaded

Version: R 2.9.0 for Windows
  











__
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] sample unique pairs from a matrix

2009-05-28 Thread David Winsemius


On May 28, 2009, at 6:33 AM, jos matejus wrote:


Dear R users,

I have a matrix of both negative and positive values that I would like
to randomly sample with the following 2 conditions:

1. only sample positive values
2. once a cell in the matrix has been sampled the row and column of
that cell cannot be sampled from again.

#some dummy data
set.seed(101)
dataf <- matrix(rnorm(36,1,2), nrow=6)

I can do this quite simply if all the values are positive by using the
sample function without replacement on the column and row indices.

samrow <- sample(6,replace=F)
samcol <- sample(6,replace=F)
values <- numeric(6)
for(i in 1:6){
values[i] <- dataf[samrow[i], samcol[i]]
}

However, I am not sure how to include the logical condition to only
include postitive values
Any help would be gratefully received.
Jos


> M <- matrix(rnorm(36),nrow=6)

> M[M[,]>0]
 [1] 1.65619781 0.56182830 0.23812890 0.81493915 1.01279243  
1.29188874 0.64252343 0.53748655 0.31503112
[10] 0.37245358 0.07942883 0.56834586 0.62200056 0.39478167 0.02374574  
0.04974857 0.56219171 0.52901658



> sample(M[M[,]>0],6,replace=F)
[1] 0.56834586 0.07942883 0.31503112 0.62200056 0.02374574 0.64252343

--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] consultation

2009-05-28 Thread David Winsemius


http://cran.r-project.org/web/views/Survival.html

On May 11, 2009, at 1:46 PM, Nancy Tejerina wrote:


*Dear R Users;*

* *

*I´m writing to ask you how can I do Survivals Curves using Time- 
dependent

covariates? Which packages I need to Install?*
*Thanks for your help, I look foward you reply.*
**
*Sincerelly.*
**

*Nancy Tejerina.*


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] sample unique pairs from a matrix

2009-05-28 Thread Richard . Cotton
> I have a matrix of both negative and positive values that I would like
> to randomly sample with the following 2 conditions:
> 
> 1. only sample positive values
> 2. once a cell in the matrix has been sampled the row and column of
> that cell cannot be sampled from again.
> 
> #some dummy data
> set.seed(101)
> dataf <- matrix(rnorm(36,1,2), nrow=6)
> 
> I can do this quite simply if all the values are positive by using the
> sample function without replacement on the column and row indices.
> 
> samrow <- sample(6,replace=F)
> samcol <- sample(6,replace=F)
> values <- numeric(6)
> for(i in 1:6){
>values[i] <- dataf[samrow[i], samcol[i]]
> }
> 
> However, I am not sure how to include the logical condition to only
> include postitive values

You could create a new variable containing only the positive values of 
dataf, and sample from that, e.g.
dataf <- matrix(rnorm(36,1,2), nrow=6)
posdata <- dataf[dataf > 0]
sample(posdata, 6, replace=FALSE)

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

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


Re: [R] R connectivity with Oracle DB

2009-05-28 Thread Duncan Murdoch

On 28/05/2009 6:03 AM, Madan Mohan wrote:

Hi Friends,

I am working on R-2.9.0 and i want to connect oracle through R, but i could
not find ROracle (zip file for windows) on CRAN Packages. Can anyone suggest
me how to connect Oracle from R in windows platform? I would be grateful if
u can provide me code aswell.


Get an ODBC driver from Oracle, and use RODBC.

Duncan Murdoch

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


Re: [R] "1L" and "0L"

2009-05-28 Thread Duncan Murdoch

On 28/05/2009 3:20 AM, bogaso.christofer wrote:
Hi, 


Recently I come through those R-expressions and understood that "1L" means
"1" and "0L" means "0". Why they are so? I mean, what the excess meanings
they carry, instead writing simple "1" or "0"? Is there any more this kind
of expressions in R?


Gavin explained the L marks the number as being stored as an integer. 
The i in 1i is somewhat similar: it marks the number as complex (but 
also changes the value, 1i is the imaginary value, not the real one). 
There's a discussion on this in section 3.1.1 "Constants" in the R 
Language Definition.


Duncan Murdoch

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


  1   2   >