[R] Odp: R not recognizing words

2012-01-06 Thread Petr PIKAL
Hi
 
 Hello all
 
 I'm new to R and am experiencing a problem with a categorical variable. 
All
 the data of this variable are Low, High, or NA.  When I put
 summary(x$y), it gives me the number of High, Low, and NA entries. 
However,
 when I try to subset by writing x$y==Low  or x$y==High, R does 
not
 recognize the word and it writes FALSE for all the entries (but not the 
NA
 entries). 
 
 Can anybody help me out?

You are not telling the whole story

x- sample(c(Low, High), 20, replace=T)
 x
 [1] Low  Low  Low  High Low  Low  Low  Low  Low  High
[11] Low  High High Low  Low  High Low  Low  High Low 
 x[5:7] - NA
 x-data.frame(y=x)
 x$y==Low
 [1]  TRUE  TRUE  TRUE FALSENANANA  TRUE  TRUE FALSE  TRUE 
FALSE
[13] FALSE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE

 x[x$y==Low,]
 [1] Low  Low  Low  NA NA NA Low  Low  Low  Low  Low  Low  Low  Low 
Levels: High Low

Works as expected. So probably your expectation is wrong.

Regards
Petr




 
 Thanks
 
 
 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/R-not-
 recognizing-words-tp4268283p4268283.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] question about rev

2012-01-06 Thread Petr PIKAL
Hi

 [R] question about rev
 
 Hi,all:
 I have a vector,and wanna get the opposite value via rev function.
 
 
  a
 [1] FALSE FALSE  TRUE  TRUE  TRUE
  
  rev(a)
 [1]  TRUE  TRUE  TRUE FALSE FALSE
  
 
 
 I don't know why the 3rd TRUE has not been reversed,while all other 
 values are reversed?

Misunderstanding what rev function does.

see

letters
rev(letters)
!a

Regards
Petr


 
 
 
 
 Thanks 
 
 
 My best
[[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] Reply on ggplot2 - tricky problem

2012-01-06 Thread Mario Giesel
That comes really close to what I had in mind.
Thanks a lot for helping out, Justin!

Good luck,
 Mario


Re: [R] ggplot2 - tricky problem 
 
how bout:

dat-data.frame(id=1:4,city=c('berlin','munich'),likeability=c(5,4,6,5),uniqueness=c(3,4,4,4))

ggplot(ddply(melt(dat,
                          id.vars=c('id','city')),
                  .(variable,city),
                  summarise,
                  value=mean(value)),
          aes(x=factor(city),y=value)) +
geom_point() +
facet_wrap(~variable)

the line drawing is a bit more tricky...  Since the x values are factors 
rather than continuous, fitting a line to them is kind of nonsense.  It 
matters which order they are in for example.  If instead you want to 
plot something like:

ggplot(dat,aes(x=likeability,y=uniqueness,colour=city))+geom_point()+geom_smooth(aes(group=city),method='lm')

You could draw fit lines that make a bit more sense.  Forgive me if I'm over 
simplifying your problem!


Justin

On Thu, Jan 5, 2012 at 7:46 AM, Mario Giesel rr.gie...@yahoo.de wrote:

Hello, R friends,

 I've been struggling quite a bit with ggplot2.
Having worked through Hadleys book twice I still wonder how to solve this task.


1. Short example Dataframe:

id    city    Likeability    Uniqueness
1    Berlin    5    3
2    Munich    4    4
3    Berlin    6    4
4    Munich    5    4

2. Task:

a) Facetting plots for each attitude (1 plot for likeability and uniqueness 
each, horizontally on one page)
b) Showing Berlin and Munich together on x axis
c) Showing the means of Berlin and Munich on y axis (means of cities in 
likeability on first plot, means of cities in uniqueness on second plot)
d) Drawing a line through mean points on each plot



Hope I could explain it understandably. Any help is appreciated!

Thanks a lot,
 Mario

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



Antwort an: Antwort an Justin Haynes Senden
[[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 to remove an element from list or character

2012-01-06 Thread arunkumar1111
HI 

I want to remove an element from a list or character. i can any of the class
type

like

cat=  [1] mac med

if my input is 2 i need to remove med and if my input is one i need to
remove mac from cat

Please help

-
Thanks in Advance
Arun
--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-remove-an-element-from-list-or-character-tp4268556p4268556.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] Bayesian estimate of prevalence with an imperfect test

2012-01-06 Thread LianD
Thanks Bert 

I've been through my variables again and have managed to get the code
working - shouldn't have tried to deal with it at the end of the day
yesterday!

all the best

Lian

--
View this message in context: 
http://r.789695.n4.nabble.com/Bayesian-estimate-of-prevalence-with-an-imperfect-test-tp4265595p4268526.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] question about rev

2012-01-06 Thread 孟欣
Yes£¬I find out later.


rev is only reverse the order.
What I use is !




Thanks





At 2012-01-06 16:07:11,Petr PIKAL petr.pi...@precheza.cz wrote:
Hi

 [R] question about rev
 
 Hi,all:
 I have a vector,and wanna get the opposite value via rev function.
 
 
  a
 [1] FALSE FALSE  TRUE  TRUE  TRUE
  
  rev(a)
 [1]  TRUE  TRUE  TRUE FALSE FALSE
  
 
 
 I don't know why the 3rd TRUE has not been reversed,while all other 
 values are reversed?

Misunderstanding what rev function does.

see

letters
rev(letters)
!a

Regards
Petr


 
 
 
 
 Thanks 
 
 
 My best
[[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.


[[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] need help with connecting to SQL Server2008 Express with RJDBC

2012-01-06 Thread cvez
i have been trying RJDBC for many hours but still failed to connect  to my
sql server. 
platform: win7 professional; SQL server 2008 express; 

the code is : 
drv - JDBC(com.microsoft.sqlserver.jdbc.SQLServerDriver, 
C:/Users/myname/sqljdbc_3.0/enu/sqljdbc4.jar);
dbConnect(drv,jdbc:sqlserver://mypc/MyDB:1433;databaseName=bkt1;)

and I got this err message:
jcall(drv@jdrv, Ljava/sql/Connection;, connect, as.character(url)[1],  : 
  com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to
the host cvez-PC/MyDB, port 1433 has failed. Error: null. Verify the
connection properties, check that an instance of SQL Server is running on
the host and accepting TCP/IP connections at the port, and that no firewall
is blocking TCP connections to the port..

I have turned down MS fire wall and I have opened port 1433,  as you can see
in this pic  http://r.789695.n4.nabble.com/file/n4268704/sql_port_config.png  

Any help will be appreciated, thank you very much! 

--
View this message in context: 
http://r.789695.n4.nabble.com/need-help-with-connecting-to-SQL-Server2008-Express-with-RJDBC-tp4268704p4268704.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] question about rev

2012-01-06 Thread cvez
the function /rev / REVERSEs the order of the vector, as
v= c(1,2,3)
rev(v)= 3,2,1
if you want the opposite value , just add a exclamation in front of the
vector:
v=c(T,F,T,T);
!v is F,T,F,F


--
View this message in context: 
http://r.789695.n4.nabble.com/question-about-rev-tp4268518p4268716.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] how to remove an element from list or character

2012-01-06 Thread Milan Bouchet-Valat
Le jeudi 05 janvier 2012 à 23:52 -0800, arunkumar a écrit :
 HI 
 
 I want to remove an element from a list or character. i can any of the class
 type
 
 like
 
 cat=  [1] mac med
 
 if my input is 2 i need to remove med and if my input is one i need to
 remove mac from cat
This is really basic, please read the R intro or some tutorial.

Basically, you can do:
input - 1 (or input - 2)
cat - cat[-input]


Cheers

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


Re: [R] plot rq lm

2012-01-06 Thread Tal Galili
I asked a while ago what diagnostic plots exists for quantile regression,
here:
http://stats.stackexchange.com/questions/19291/what-diagnostic-plots-exists-for-quantile-regression
And had received no answer.

I hope some more information will become available regarding this.

Best,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Jan 4, 2012 at 7:52 PM, agent dunham crossp...@hotmail.com wrote:

 Dear Community,

 I'd like to plot an rq object the same way I do with a lm one, is it
 possible? Something like this

 plot(rqmodel , 1:4, id.labels=rownames(pga1)); where

 rqmodel - rq(log(vd) ~ v1 + log(v2) +log(v3) + v4 + v5 ,data =dat)


 Thanks in advance and apologies, I'm pretty newbie with this,
 u...@host.com


 --
 View this message in context:
 http://r.789695.n4.nabble.com/plot-rq-lm-tp4262170p4262170.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] R not recognizing words

2012-01-06 Thread peter dalgaard

On Jan 6, 2012, at 06:20 , arabarkev wrote:

 Hello all
 
 I'm new to R and am experiencing a problem with a categorical variable.  All
 the data of this variable are Low, High, or NA.  When I put
 summary(x$y), it gives me the number of High, Low, and NA entries.  However,
 when I try to subset by writing x$y==Low  or x$y==High, R does not
 recognize the word and it writes FALSE for all the entries (but not the NA
 entries). 
 
 Can anybody help me out?

Trailing whitespace? Check levels(x$y)

 
 Thanks
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/R-not-recognizing-words-tp4268283p4268283.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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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] add data to a file while doing a loop

2012-01-06 Thread Joao Fadista
Hi,

I would like to know how can I keep adding data to a file while doing a loop 
and without deleting the data of the previous iteration. Thanks.

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


Re: [R] add data to a file while doing a loop

2012-01-06 Thread Stephen Sefick
Without context, read reproducible code, it is hard to answer this 
question.  What system are you on?  Do you need to write one line of 
data or a data frame or a list out?  Are trying to write a graphic out? 
It will be easier to answer your question with some context.  Good 
luck!


Stephen

On Fri 06 Jan 2012 05:49:01 AM CST, Joao Fadista wrote:

Hi,

I would like to know how can I keep adding data to a file while doing a loop 
and without deleting the data of the previous iteration. Thanks.

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


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


[R] Spatial data, rpoispp, using window with fixed radius?

2012-01-06 Thread herbert8686
Dear All,

I was searching through the spatstat manual in order to find a function to 
simulate a Poisson pattern only within a fixed radius (circular moving window) 
around individual points. If points are distributed heterogeneously over a 
large area this may help to only assess deviation from CSR within the window 
and thus does not require additional information on a covariate. I could not 
find such a function in spatstat. Can please anyone help?

Thanks,

Herb

--

__
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] add data to a file while doing a loop

2012-01-06 Thread Joao Fadista
Thanks for the reply. Every iteration produces a text data.frame directly into 
a file without saving it in R. And every iteration overwrites the data produced 
from the previous iteration. So what I would like to do is being able not to 
overwrite the data of any iteration but adding it to the same file with maybe 
the functions paste or rbind.


 sessionInfo()
R version 2.13.2 (2011-09-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252
LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C
LC_TIME=Swedish_Sweden.1252

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

other attached packages:
[1] MatrixEQTL_1.2.0

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


Best regards,
João Fadista, Ph.D.
Post Doc

Lund University Diabetes Centre
CRC, Malmö University Hospital
Entrance 72, building 60, level 13
SE-205 02 Malmö, Sweden
Tel: +46 (0)40 391237
e-mail: joao.fadi...@med.lu.se


-Original Message-
From: stephen sefick [mailto:ssef...@gmail.com] On Behalf Of Stephen Sefick
Sent: den 6 januari 2012 14:14
To: Joao Fadista
Cc: r-help@r-project.org
Subject: Re: [R] add data to a file while doing a loop

Without context, read reproducible code, it is hard to answer this question.  
What system are you on?  Do you need to write one line of data or a data frame 
or a list out?  Are trying to write a graphic out? 
 It will be easier to answer your question with some context.  Good luck!

Stephen

On Fri 06 Jan 2012 05:49:01 AM CST, Joao Fadista wrote:
 Hi,

 I would like to know how can I keep adding data to a file while doing a loop 
 and without deleting the data of the previous iteration. Thanks.

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


[R] [R-pkgs] The BRugs 0.7-4 interface to OpenBUGS released

2012-01-06 Thread Uwe Ligges
After so many questions and a considerable delay (almost entirely my 
fault), the BRugs package version 0.7-4 has been released yesterday. The 
BRugs package is available from CRAN master already as source and in 
binary form for Windows and will be synced by the mirrors shortly.


Note the following changes (more details in the NEWS file):

BRugs works on Linux now

BRugs now supports 64-bit R on Windows

BRugs works with an existing installation of OpenBUGS (at least 3.2.1) 
instead of being distributed with the OpenBUGS library, hence the 
OpenBUGS installation is a requirement.


Both the Linux version as well as the 64-bit version for 64-bit R on 
Windows are  typically slower than the more native interface used for 
32-bit R on Windows.


Thanks to all who helped to get so far. Special thanks to Chris Jackson 
for many improvement and all his work to build the Linux part of the 
interface.


Best,
Uwe Ligges

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

__
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] Problem with axes in a plot of Kaplan-Meier

2012-01-06 Thread Terry Therneau
After changing involuntarily some of the graphics parameters with
the command par() (I did not know that changes with this command are
permanent), now when I made a plot of the survival Kaplan-Meier
function, the Y axis does not start at 1, and the X axis does starts
at 0. The commands that I use are:

-

  Par command are cumulative PER graphics device.  Your unfortunate
par commands would not affect a new plot with pdf() for instance.
I often resort to the simple solution of
dev.off()  #close the current window
x11() # start a new one
(If not on Unix replace x11 with the appropriate command for your
system).

  David's solution is the more elegant one.

Terry T.

__
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 not recognizing words

2012-01-06 Thread Nutter, Benjamin
I've developed a preference for 

x$y %in% Low

when subsetting.  

  Benjamin Nutter |  Biostatistician     |  Quantitative Health Sciences
  Cleveland Clinic    |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 
445-1365


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of arabarkev
Sent: Friday, January 06, 2012 12:20 AM
To: r-help@r-project.org
Subject: [R] R not recognizing words

Hello all

I'm new to R and am experiencing a problem with a categorical variable.  All 
the data of this variable are Low, High, or NA.  When I put summary(x$y), 
it gives me the number of High, Low, and NA entries.  However,
when I try to subset by writing x$y==Low  or x$y==High, R does not
recognize the word and it writes FALSE for all the entries (but not the NA 
entries). 

Can anybody help me out?

Thanks
 



--
View this message in context: 
http://r.789695.n4.nabble.com/R-not-recognizing-words-tp4268283p4268283.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.


===

 Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S.News  World Report (2010).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
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] automatic SI prefixes as ticklabels on axis

2012-01-06 Thread Rui Barradas
Ben's solution is much better, I was using only Jonas'  code.

There might be typo with large values of 'x',

 getSIstring(1e309)
[1] Inf Y

I don't believe this will happen, the range upper limit is much smaller.
Anyway, it can be easily solved.
(Ben's code, slightly changed.)

getSIstring - function(x){

  lut - rev(c(1e24,1e21,1e18,1e15,1e12,1e9,1e6,1e3,1e0,
 1e-3,1e-6,1e-9,1e-12,1e-15,1e-18,1e-21,1e-24))
  pre - rev(c(Y, Z, E, P, T, G, M, k,  ,
 m, u, n, p, f, a, z, y))

  ix - findInterval(x, lut)

  ifelse(length(ix)  0, sistring - paste(x/lut[ix], pre[ix]),
 sistring - as.character(x))

  sistring[which(sistring ==  Inf Y)] - Inf   # make it look better

  return(sistring)
}

getSIstring(c(4.2e-3, 2e7))

x1 - .Machine$double.xmax
x2 - x1 + 10^(308 - 16)
getSIstring(c(x1, x2))


Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/automatic-SI-prefixes-as-ticklabels-on-axis-tp4266141p4269182.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] What is wrong with this plotting?

2012-01-06 Thread raphael.felber
Hello

I have a data frame, called input, like this:

   DateTime CO2_A1cont
1 2011-04-08 11:47:01 NA
2 2011-04-08 12:42:018.9
3 2011-04-08 13:07:01 NA
4 2011-04-08 13:32:01 NA
5 2011-04-08 13:57:01   7.556482
6 2011-04-08 14:22:01 NA

57 2011-04-09 16:52:01   4.961558

And like to plot this series with plot() and connected lines, no interruption 
by the NAs.
I found that this code works:

y-input[,2]
times - DateTime

plot(y~as.POSIXct(times, format=%d.%m. %H:%M), type=l, 
data=na.omit(data.frame(y,times)))

whereas this plot command...

 plot(input[,2]~as.POSIXct(DateTime, format=%d.%m. %H:%M), type=l, 
data=na.omit(data.frame(input[,2],DateTime)))

... produces the error:

Error in model.frame.default(formula = input[, 2] ~ as.POSIXct(DateTime,  :
  variable lengths differ (found for 'as.POSIXct(DateTime, format = %d.%m. 
%H:%M)')

I already checked the length of y, times, input[,2], DateTime, 
as.POSIXct(DateTime, format=%d.%m. %H:%M) which give all 57! 
nrow(data.frame(input[,2],DateTime)) and nrow(data.frame(y,times)) give both  
57! Too.

Thanks for any help.

Best regards

Raphael


[[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] add data to a file while doing a loop

2012-01-06 Thread Rui Barradas
Hello,

See

?open and ?capture.output

or

?textConnection

To open a connection (with 'open') then write to it is probably the
solution.

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/add-data-to-a-file-while-doing-a-loop-tp4269086p4269396.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] lme model specification problem (Error in MEEM...)

2012-01-06 Thread Pascal A. Niklaus

Dear all,

In lme, models in which a factor is fully contained in another lead to 
an error. This is not the case when using lm/aov.


I understand that these factors are aliased, but believe that such 
models make sense when the factors are fitted sequentially. For example, 
I sometimes fit a factor first as linear term (continuous variable with 
discrete levels, e.g. 1,2,4,6), and then as factor, with the latter then 
accounting for the deviation from linearity.


If x contains the values 1,2,4,6, the model formula then would be y ~ x 
+ as.factor(x)


A complete example is here:

library(nlme)

d - data.frame(x=rep(c(1,2,4,6),each=2),subj=factor(rep(1:16,each=2)))
d$y - rnorm(32) + rnorm(length(levels(d$subj)))[d$subj]

anova(lme(y~x,random=~1|subj,data=d))   ## works
anova(lme(y~as.factor(x),random=~1|subj,data=d))## works

anova(lme(y~x+as.factor(x),random=~1|subj,data=d))  ## fails:
# Error in MEEM(object, conLin, control$niterEM) :
#  Singularity in backsolve at level 0, block 1

summary(aov(y~x+as.factor(x)+Error(subj),data=d))   ## works:

# Error: subj
#  Df Sum Sq Mean Sq F value Pr(F)
# x 1  8.434   8.434   4.780 0.0493 *
# as.factor(x)  2 10.459   5.230   2.964 0.0900 .
# Residuals12 21.176   1.765
# ... rest of output removed ...

I understand I can to some extent work around this limitation by 
modifying the contrast encoding, but I then still don't get an overall 
test for as.factor(x) (in the example above, a test for deviation from 
linearity).


d$xfac - factor(d$x)
contrasts(d$xfac)-c(1,2,4,6)
summary(lme(y~xfac,random=~1|subj,data=d))

Is there a way to work around this limitation of lme? Or do I 
mis-specify the model? Thanks for your advice.


Pascal

__
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 not recognizing words

2012-01-06 Thread arabarkev
There was a trailing white space!

Now I feel not so smart 

Thanks a lot for your help!

--
View this message in context: 
http://r.789695.n4.nabble.com/R-not-recognizing-words-tp4268283p4269326.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] add data to a file while doing a loop

2012-01-06 Thread Sander Timmer
So you're looking for:

write.table(dataset, file=x.txt, append=TRUE)

Or do I understand your question wrongly? 


__
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] add data to a file while doing a loop

2012-01-06 Thread David Winsemius


On Jan 6, 2012, at 8:27 AM, Joao Fadista wrote:

Thanks for the reply. Every iteration produces a text data.frame  
directly into a file without saving it in R. And every iteration  
overwrites the data produced from the previous iteration. So what I  
would like to do is being able not to overwrite the data of any  
iteration but adding it to the same file with maybe the functions  
paste or rbind.


If you are using write.table, then pay more attention to the append  
parameter documented in the help file.

--
David.




sessionInfo()

R version 2.13.2 (2011-09-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252 
LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C 
LC_TIME=Swedish_Sweden.1252


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

other attached packages:
[1] MatrixEQTL_1.2.0

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


Best regards,
João Fadista, Ph.D.
Post Doc

Lund University Diabetes Centre
CRC, Malmö University Hospital
Entrance 72, building 60, level 13
SE-205 02 Malmö, Sweden
Tel: +46 (0)40 391237
e-mail: joao.fadi...@med.lu.se


-Original Message-
From: stephen sefick [mailto:ssef...@gmail.com] On Behalf Of Stephen  
Sefick

Sent: den 6 januari 2012 14:14
To: Joao Fadista
Cc: r-help@r-project.org
Subject: Re: [R] add data to a file while doing a loop

Without context, read reproducible code, it is hard to answer this  
question.  What system are you on?  Do you need to write one line of  
data or a data frame or a list out?  Are trying to write a graphic  
out?
It will be easier to answer your question with some context.  Good  
luck!


Stephen

On Fri 06 Jan 2012 05:49:01 AM CST, Joao Fadista wrote:

Hi,

I would like to know how can I keep adding data to a file while  
doing a loop and without deleting the data of the previous  
iteration. Thanks.


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

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


David Winsemius, MD
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] venneuler plots may be inaccurate

2012-01-06 Thread Carl Witthoft

Hi,
I just started playing w/ venneuler, and have a question about the last 
method listed for creating inputs.  This is the method where the source 
is a matrix X, for which each column represents a set, and the 
co-occurrence is defined by the rows.  So, for example:


Rgames foo
  [,1] [,2] [,3] [,4] [,5]
 [1,]0110   NA
 [2,]0110   NA
 [3,]0110   NA
 [4,]0110   NA
 [5,]0110   NA
 [6,]0111   NA
 [7,]0111   NA
 [8,]0111   NA
 [9,]0111   NA
[10,]0111   NA
[11,]1011   NA
[12,]1011   NA
[13,]1011   NA
[14,]1011   NA
[15,]1011   NA
[16,]1010   NA
[17,]1010   NA
[18,]1010   NA
[19,]1010   NA
[20,]1010   NA
Rgames plot(venneuler(foo[,1:3]))

The result I get is at http://home.comcast.net/~cgwcgw2/venndiagram.pdf

I would not expect either A or B to extend outside C, and they shouldn't 
overlap either.
Any ideas?   So far as I can tell, the first method (define weights for 
each 'overlap' region, e.g. AB=.2, seems to work correctly).


thanks
Carl
--

Sent from my Cray XK6
Pendeo-navem mei anguillae plena est.

__
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] ggplot using scale_x_date gives Error in seq.int(r1$year, to$year, by)

2012-01-06 Thread Aidan Corcoran
Dear all,

ggplot gives me an error when trying to plot time series data using a
date variable as the x axis.

g-structure(list(Date = c(2011-12-23, 2011-12-30, 2012-01-06,
2011-12-23, 2011-12-30, 2012-01-06, 2011-12-23, 2011-12-30,
2012-01-06), variable = structure(c(1L, 1L, 1L, 2L, 2L, 2L,
3L, 3L, 3L), .Label = c(Price, Yield, CDS Spread), class = factor),
value = c(86.777, 86.037, 86.437, 9.737, 9.542, 9.683, 580.132,
576.866, 573.564)), .Names = c(Date, variable, value
), row.names = c(100L, 101L, 102L, 202L, 203L, 204L, 304L, 305L,
306L), class = data.frame)

 g
  Date   variable value
100 2011-12-23  Price  86.8
101 2011-12-30  Price  86.0
102 2012-01-06  Price  86.4
202 2011-12-23  Yield   9.7
203 2011-12-30  Yield   9.5
204 2012-01-06  Yield   9.7
304 2011-12-23 CDS Spread 580.1
305 2011-12-30 CDS Spread 576.9
306 2012-01-06 CDS Spread 573.6
 gp-ggplot(g,aes(x=Date,y=value,group=variable,lty=variable)) +geom_line()
 gp
 #THIS WORKS FINE (BUT AXIS LABELLING NOT VISIBLE WITH MORE DATA, HENCE I 
 WOULD LIKE TO USE SCALE_X_DATE)
 gp-gp+   scale_x_date()
 gp
Error in seq.int(r1$year, to$year, by) : 'from' must be finite
In addition: Warning messages:
1: In get(x, envir = this, inherits = inh)(this, ...) :
  NAs introduced by coercion
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf
4: In min(x) : no non-missing arguments to min; returning Inf
5: In max(x) : no non-missing arguments to max; returning -Inf


In previous help requests, the workaround of specifying the unit was suggested:
gp-gp+   scale_x_date(major=years)
but this doesn't work for me (same error).

Any help is very much appreciated! Thanks in advance.

Aidan

R version 2.14.1 (2011-12-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_Ireland.1252  LC_CTYPE=English_Ireland.1252
LC_MONETARY=English_Ireland.1252
[4] LC_NUMERIC=C LC_TIME=English_Ireland.1252

attached base packages:
 [1] datasets  tools grDevices grid  splines   graphics  stats
tcltk utils
[10] methods   base

other attached packages:
 [1] micEcon_0.6-6  miscTools_0.6-12   np_0.40-11
cubature_1.0   boot_1.3-3
 [6] RODBC_1.3-3sqldf_0.4-6.1  chron_2.3-41
gsubfn_0.5-7   DBI_0.2-5
[11] Haver_1.0  xtable_1.5-6   plm_1.2-7
sandwich_2.2-7 MASS_7.3-16
[16] Formula_1.0-1  nlme_3.1-102   bdsmatrix_1.0
RBloomberg_0.4-150 rJava_0.9-1
[21] gtools_2.6.2   gdata_2.8.2ggplot2_0.8.9
proto_0.3-9.2  zoo_1.7-4
[26] reshape_0.8.4  plyr_1.6   svSocket_0.9-52
TinnR_1.0.3R2HTML_2.2
[31] Hmisc_3.8-3survival_2.36-10

loaded via a namespace (and not attached):
[1] cluster_1.14.1digest_0.5.0  lattice_0.20-0
RSQLite_0.10.0
[5] RSQLite.extfuns_0.0.1 svMisc_0.9-63


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


Re: [R] What is wrong with this plotting?

2012-01-06 Thread Gabor Grothendieck
On Fri, Jan 6, 2012 at 5:49 AM,  raphael.fel...@art.admin.ch wrote:
 Hello

 I have a data frame, called input, like this:

           DateTime CO2_A1cont
 1 2011-04-08 11:47:01         NA
 2 2011-04-08 12:42:01    8.9
 3 2011-04-08 13:07:01         NA
 4 2011-04-08 13:32:01         NA
 5 2011-04-08 13:57:01   7.556482
 6 2011-04-08 14:22:01         NA
 
 57 2011-04-09 16:52:01   4.961558

 And like to plot this series with plot() and connected lines, no interruption 
 by the NAs.
 I found that this code works:

 y-input[,2]
 times - DateTime

 plot(y~as.POSIXct(times, format=%d.%m. %H:%M), type=l, 
 data=na.omit(data.frame(y,times)))

 whereas this plot command...

  plot(input[,2]~as.POSIXct(DateTime, format=%d.%m. %H:%M), type=l, 
 data=na.omit(data.frame(input[,2],DateTime)))

 ... produces the error:

 Error in model.frame.default(formula = input[, 2] ~ as.POSIXct(DateTime,  :
  variable lengths differ (found for 'as.POSIXct(DateTime, format = %d.%m. 
 %H:%M)')

 I already checked the length of y, times, input[,2], DateTime, 
 as.POSIXct(DateTime, format=%d.%m. %H:%M) which give all 57! 
 nrow(data.frame(input[,2],DateTime)) and nrow(data.frame(y,times)) give both  
 57! Too.

Try this reading DF into a zoo object.  (tz= has the effect of
setting its index to POSIXct using the current time zone -- you might
need tz = GMT depending on what you want):

library(zoo)
z - read.zoo(DF, tz = )
plot(na.approx(z))


Assuming DF is:

DF - structure(list(DateTime = structure(1:6, .Label = c(2011-04-08
11:47:01,
2011-04-08 12:42:01, 2011-04-08 13:07:01, 2011-04-08 13:32:01,
2011-04-08 13:57:01, 2011-04-08 14:22:01), class = factor),
CO2_A1cont = c(NA, 8.9, NA, NA, 7.556482, NA)), .Names = c(DateTime,
CO2_A1cont), class = data.frame, row.names = c(NA, -6L))


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] VarCov matrix between coefficients across quantiles - summary.rq

2012-01-06 Thread Julia Lira

Dear all,
I am trying to design a Wald test to verify whether some coefficients are 
statistically equal.
I would like to test not only whether they are jointly equal for a given 
quantile, but for a range of quantiles. Hence, I need to extract the 
variance-covariance matrix among the coefficients of a rq object:
qf2 - summary(rq(wb2 ~ apv2 + vol2, tau=c(a1,a2)), cov=TRUE)
I need not only the varcov matrix between the coefficients beta_0, beta_1, 
beta_2, but also between beta_0(a1) and beta_0(a2), and so on... (i.e., across 
quantiles)
it is not a simple anova.rq test because I am comparing two different samples. 
The samples are independent, so, the varcov matrix between them is zero. 
However, I need to find the varcov between the coefficients across quantiles 
for each sample. Then, i will include the matrix in my Wald Test.
I have tried the command qf2[[3]], but it does not work.
Is there any other command that gives me the varcov between all those 
coefficients across quantiles?
Thanks a lot! 
Julia 
[[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] Dropping columns from data frame

2012-01-06 Thread Mike Harwood
How does R do it, and should I ever be worried?  I always remove
columns by index, and it works exactly as I would naively expect - but
HOW?  The second illustration, which deletes non contiguous columns,
represents what I do all the time and have some trepidation about
because I don't know the mechanics (e.g. why doesn't the column
formerly-known-as-4 become 3 after column 1 is dropped: doesn't vector
removal from a df/list invoke a loop in C?).  Can I delete a named
list of columns, which are examples 4 and 5 and which generate the
unary error' mesages, without resorting to orig.df$num1.10 - NULL?

Thanks!

orig.df - data.frame(cbind(
1:10
,11:20
,letters[1:10]
,letters[11:20]
,LETTERS[1:10]
,LETTERS[11:20]
))
names(orig.df) - c(
'num1.10'
,'num11.20'
,'lc1.10'
,'lc11.20'
,'uc1.10'
,'uc11.20'
)
# Illustration 1: contiguous columns at beginning of data frame
head(orig.df[,-c(1:3)])

# Illustration 2: non-contiguous columns
head(orig.df[,-c(1,3,5)])

# Illustration 3: contiguous columns at end of data frame
head(orig.df[,-c(4:6)]) ## as expected

# Illustrations 4-5: unary errors
head(orig.df[,-c(as.list('num1.10', 'lc1.10', 'uc1.10'))])
head(orig.df[,-c('num1.10', 'lc1.10', 'uc1.10')])


Mike

__
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 use rgl to plot dynamic orbit

2012-01-06 Thread Phillip Von
Dear all,
I have a question about the plotting of the dynamical orbit by using rgl.
My code is as follows:
open3d()
par3d(cex=2)
bg3d(white)
for(i in 1:out.length){
ind-which
plot3d(x[1:i],y[1:i],out[,z][1:i],xlim=c(-10,10),ylim=c(-10,10),zlim=c(-10,10),col=red,cex=2)
Sys.sleep(0.0001)
}
,where x,y,out[,z] are the position of the object in different time. I
would like to show the orbit evoluting with time. However, I can just get
animation with flash windows. I don't know how to use play3d to realise
this dynamical orbit, are there anyone could help me for this?
Thanks a lot!
Fabo

[[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] data.frame: temporal complexity

2012-01-06 Thread ikuzar
Hello,

I created a data.frame which contains two columns: df$P (Power) et
df$DateTime (time). I'd like to add a new column df$diffP (difference of
Power between T and T-2).

I made a loop :

for (i in 3:length(df$DateTime)){
df$diffP[i] = df$P[i] - df$P[i-2] 
}
execution time result is unaceptable: 24s !!

Is there any way to reduce complexity about O(n) ? for example 2 or 3s (10s
maxi)

Does anybody find better than ~24s ?

thanks for your help

--
View this message in context: 
http://r.789695.n4.nabble.com/data-frame-temporal-complexity-tp4269585p4269585.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] plots for residual analysis

2012-01-06 Thread jose romero
Hello List:

I'm writing in R some code to produce plots for residual analysis and 
diagnostics in linear regressions.  An example of the plots produced is given 
for downloading at http://dl.dropbox.com/u/25445316/res_plots.png .  Regarding 
the example plot, I'd like to point out that: 1) Tendency lines based on lowess 
estimations are drawn as green continuous curves, 2) Extra variables or 
components (variables not in the model formula, but in the original dataframe 
or otherwise specified by the user) are plotted and labeled with an extra: 
preffix. 3) Moderate and extreme atipical levels of residuals are drawn as 
dashed yellow or red horizontal lines.  The dashed green lines represent the 0 
mean residuals are supposed to have, according to model assumptions.  

This plotting function is part of a set of tools I'm developing for 
spanish-sepaking  pre-grad students.  For more information, please consult 
https://sites.google.com/site/unamatematicaseltigre/trabajos-de-estadistica .


The questions I'd like to put forth to the list are:
1) This plot is based on one I saw with similar dashed lines for atipical value 
limits, but now I can't recall in which package I saw this.  Does anyone know 
of any package that produces very similar residual plots?  I need to know this 
in order to give due credit.
2) What do the experts think of the green trend lines? Are they effective for 
spotting residuals/predictor variables relationships or are they misleading?
3) In the future, I would like to plot a grey shaded region approximately 
corresponding to the dispersion cloud, in order to appreciate homocedasticity 
or the lack thereof.  Perhaps this could be done by calculating upper and 
lower limit trend lines? Any ideas on how to do this?

Thanks in advance,

José Loreto Romero Palma
[[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] data.frame: temporal complexity

2012-01-06 Thread Bert Gunter
1. You are doing exactly what one is recommended to avoid in R. Have
you read an Introduction to R? -- especially about vectorization?

2. To answer your question: ?diff

It will probably be an order or 2 of magnitude faster.

-- Bert


On Fri, Jan 6, 2012 at 6:39 AM, ikuzar raz...@hotmail.fr wrote:
 Hello,

 I created a data.frame which contains two columns: df$P (Power) et
 df$DateTime (time). I'd like to add a new column df$diffP (difference of
 Power between T and T-2).

 I made a loop :

 for (i in 3:length(df$DateTime)){
    df$diffP[i] = df$P[i] - df$P[i-2]
 }
 execution time result is unaceptable: 24s !!

 Is there any way to reduce complexity about O(n) ? for example 2 or 3s (10s
 maxi)

 Does anybody find better than ~24s ?

 thanks for your help

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/data-frame-temporal-complexity-tp4269585p4269585.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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] data.frame: temporal complexity

2012-01-06 Thread jim holtman
Try this:

 df - data.frame(power = runif(1))
 # add difference
 diffGap - 2
 df$diff - c(rep(NA, diffGap), head(df$power, -diffGap) - tail(df$power, 
 -diffGap))
 head(df, 10)
powerdiff
1  0.86170585  NA
2  0.90672473  NA
3  0.96868367 -0.10697782
4  0.44199262  0.46473211
5  0.48593923  0.48274443
6  0.99409592 -0.55210330
7  0.72790728 -0.24196804
8  0.38070013  0.61339579
9  0.69913680  0.02877047
10 0.07902925  0.30167088



On Fri, Jan 6, 2012 at 9:39 AM, ikuzar raz...@hotmail.fr wrote:
 Hello,

 I created a data.frame which contains two columns: df$P (Power) et
 df$DateTime (time). I'd like to add a new column df$diffP (difference of
 Power between T and T-2).

 I made a loop :

 for (i in 3:length(df$DateTime)){
    df$diffP[i] = df$P[i] - df$P[i-2]
 }
 execution time result is unaceptable: 24s !!

 Is there any way to reduce complexity about O(n) ? for example 2 or 3s (10s
 maxi)

 Does anybody find better than ~24s ?

 thanks for your help

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/data-frame-temporal-complexity-tp4269585p4269585.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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] add data to a file while doing a loop

2012-01-06 Thread William Dunlap
Is this an example of what you want to do?

  fileName - tempfile(fileext=.txt)
  fileCon - file(fileName, wt) # a file connection, opened for writing text
  for(i in 1:5) {
  cat(file=fileCon, Line, i, \n) # write to connection, not file name
  }
  close(fileCon)

Then look to see what the file contains:

   readLines(fileName)
  [1] Line 1  Line 2  Line 3  Line 4  Line 5 

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Joao Fadista
 Sent: Friday, January 06, 2012 5:27 AM
 To: sas0...@auburn.edu
 Cc: r-help@r-project.org
 Subject: Re: [R] add data to a file while doing a loop
 
 Thanks for the reply. Every iteration produces a text data.frame directly 
 into a file without saving
 it in R. And every iteration overwrites the data produced from the previous 
 iteration. So what I would
 like to do is being able not to overwrite the data of any iteration but 
 adding it to the same file
 with maybe the functions paste or rbind.
 
 
  sessionInfo()
 R version 2.13.2 (2011-09-30)
 Platform: x86_64-pc-mingw32/x64 (64-bit)
 
 locale:
 [1] LC_COLLATE=Swedish_Sweden.1252  LC_CTYPE=Swedish_Sweden.1252
 LC_MONETARY=Swedish_Sweden.1252
 LC_NUMERIC=CLC_TIME=Swedish_Sweden.1252
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base
 
 other attached packages:
 [1] MatrixEQTL_1.2.0
 
 loaded via a namespace (and not attached):
 [1] tools_2.13.2
 
 
 Best regards,
 João Fadista, Ph.D.
 Post Doc
 
 Lund University Diabetes Centre
 CRC, Malmö University Hospital
 Entrance 72, building 60, level 13
 SE-205 02 Malmö, Sweden
 Tel: +46 (0)40 391237
 e-mail: joao.fadi...@med.lu.se
 
 
 -Original Message-
 From: stephen sefick [mailto:ssef...@gmail.com] On Behalf Of Stephen Sefick
 Sent: den 6 januari 2012 14:14
 To: Joao Fadista
 Cc: r-help@r-project.org
 Subject: Re: [R] add data to a file while doing a loop
 
 Without context, read reproducible code, it is hard to answer this question.  
 What system are you on?
 Do you need to write one line of data or a data frame or a list out?  Are 
 trying to write a graphic
 out?
  It will be easier to answer your question with some context.  Good luck!
 
 Stephen
 
 On Fri 06 Jan 2012 05:49:01 AM CST, Joao Fadista wrote:
  Hi,
 
  I would like to know how can I keep adding data to a file while doing a 
  loop and without deleting
 the data of the previous iteration. Thanks.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
__
R-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] Dropping columns from data frame

2012-01-06 Thread David Winsemius


On Jan 6, 2012, at 10:00 AM, Mike Harwood wrote:


How does R do it, and should I ever be worried?  I always remove
columns by index, and it works exactly as I would naively expect - but
HOW?  The second illustration, which deletes non contiguous columns,
represents what I do all the time and have some trepidation about
because I don't know the mechanics (e.g. why doesn't the column
formerly-known-as-4 become 3 after column 1 is dropped: doesn't vector
removal from a df/list invoke a loop in C?).


You are NOT removing columns. You are returning (to `head` and then  
to `print`) an extract from the dataframe, but that does not change  
the original dataframe. To effect a change you would need to assign  
the value back to the same name as the original daatframe.


--
David

 Can I delete a named
list of columns, which are examples 4 and 5 and which generate the
unary error' mesages, without resorting to orig.df$num1.10 - NULL?

Thanks!

orig.df - data.frame(cbind(
1:10
,11:20
,letters[1:10]
,letters[11:20]
,LETTERS[1:10]
,LETTERS[11:20]
))
names(orig.df) - c(
'num1.10'
,'num11.20'
,'lc1.10'
,'lc11.20'
,'uc1.10'
,'uc11.20'
)
# Illustration 1: contiguous columns at beginning of data frame
head(orig.df[,-c(1:3)])

# Illustration 2: non-contiguous columns
head(orig.df[,-c(1,3,5)])

# Illustration 3: contiguous columns at end of data frame
head(orig.df[,-c(4:6)]) ## as expected

# Illustrations 4-5: unary errors
head(orig.df[,-c(as.list('num1.10', 'lc1.10', 'uc1.10'))])
head(orig.df[,-c('num1.10', 'lc1.10', 'uc1.10')])


Mike

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


David Winsemius, MD
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] lme model specification problem (Error in MEEM...)

2012-01-06 Thread Ben Bolker
Pascal A. Niklaus pascal.niklaus at ieu.uzh.ch writes:

 In lme, models in which a factor is fully contained in another lead to 
 an error. This is not the case when using lm/aov.
 
 I understand that these factors are aliased, but believe that such 
 models make sense when the factors are fitted sequentially. For example, 
 I sometimes fit a factor first as linear term (continuous variable with 
 discrete levels, e.g. 1,2,4,6), and then as factor, with the latter then 
 accounting for the deviation from linearity.
 
 If x contains the values 1,2,4,6, the model formula then would be y ~ x 
 + as.factor(x)
 
 A complete example is here:
 
 library(nlme)
 
 d - data.frame(x=rep(c(1,2,4,6),each=2),subj=factor(rep(1:16,each=2)))
 d$y - rnorm(32) + rnorm(length(levels(d$subj)))[d$subj]
 
 anova(lme(y~x,random=~1|subj,data=d))   ## works
 anova(lme(y~as.factor(x),random=~1|subj,data=d))## works
 
 anova(lme(y~x+as.factor(x),random=~1|subj,data=d))  ## fails:
 # Error in MEEM(object, conLin, control$niterEM) :
 #  Singularity in backsolve at level 0, block 1
 
 summary(aov(y~x+as.factor(x)+Error(subj),data=d))   ## works:
 
 # Error: subj
 #  Df Sum Sq Mean Sq F value Pr(F)
 # x 1  8.434   8.434   4.780 0.0493 *
 # as.factor(x)  2 10.459   5.230   2.964 0.0900 .
 # Residuals12 21.176   1.765
 # ... rest of output removed ...
 
 I understand I can to some extent work around this limitation by 
 modifying the contrast encoding, but I then still don't get an overall 
 test for as.factor(x) (in the example above, a test for deviation from 
 linearity).
 
 d$xfac - factor(d$x)
 contrasts(d$xfac)-c(1,2,4,6)
 summary(lme(y~xfac,random=~1|subj,data=d))
 
 Is there a way to work around this limitation of lme? Or do I 
 mis-specify the model? Thanks for your advice.

  This question would probably be more appropriate for 
the r-sig-mixed-mod...@r-project.org mailing list.

  A short answer (if you re-post to r-sig-mixed-models I might
answer at greater length) would be that you should be able to quantify
the difference between

  y~x

 and

  y~factor(x)

by an anova comparison of the two *models*, i.e.

anova(m1,m2)

Another thing to consider would be setting using orthogonal
polynomial contrasts for factor(x), where summary() would
give you a result for the constant, linear, quadratic ...
terms

  Ben Bolker

__
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 use rgl to plot dynamic orbit

2012-01-06 Thread Duncan Murdoch

On 06/01/2012 9:13 AM, Phillip Von wrote:

Dear all,
I have a question about the plotting of the dynamical orbit by using rgl.
My code is as follows:
open3d()
par3d(cex=2)
bg3d(white)
for(i in 1:out.length){
ind-which
plot3d(x[1:i],y[1:i],out[,z][1:i],xlim=c(-10,10),ylim=c(-10,10),zlim=c(-10,10),col=red,cex=2)
Sys.sleep(0.0001)
}
,where x,y,out[,z] are the position of the object in different time. I
would like to show the orbit evoluting with time. However, I can just get
animation with flash windows. I don't know how to use play3d to realise
this dynamical orbit, are there anyone could help me for this?
Thanks a lot!


If you just want to add points to the plot, then I'd use points3d() to 
add them one at a time.  (Or if you want them joined,
use lines3d() or segments3d() to add a line from the previous point to 
the next one.)  For example,


plot3d(numeric(0), numeric(0), numeric(0), 
xlim=c(-10,10),ylim=c(-10,10),zlim=c(-10,10))


for(i in 1:out.length){
ind-which
points3d(x[i],y[i],out[i,z],col=red,cex=2)
Sys.sleep(0.0001)
}

__
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 fit my data with a distribution?

2012-01-06 Thread Andra Isan
Dear All, 


I have a bunch of data points as follows:

x  100
y  200
z  300
...
where 100, 200, 300 are the values. I would like to know the distribution of my 
data? how can I fit my data into a distribution?

Thanks a lot,
Andra

[[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] Dropping columns from data frame

2012-01-06 Thread Mike Harwood
Thank you, David.  I was merely using head to limit the code/
output.  My question remains, because a created data frame has the
same columns as was output from head:

 head(orig.df,3)
  num1.10 num11.20 lc1.10 lc11.20 uc1.10 uc11.20
1   1   11  a   k  A   K
2   2   12  b   l  B   L
3   3   13  c   m  C   M
 # Illustration 1: contiguous columns at beginning of data frame
 head(orig.df[,-c(1:3)],2)
  lc11.20 uc1.10 uc11.20
1   k  A   K
2   l  B   L
 new.df - orig.df[,-c(1:3)]
 head(new.df,2)
  lc11.20 uc1.10 uc11.20
1   k  A   K
2   l  B   L

 # Illustration 2: non-contiguous columns
 head(orig.df[,-c(1,3,5)],2)
  num11.20 lc11.20 uc11.20
1   11   k   K
2   12   l   L
 new.df - orig.df[,-c(1,3,5)]
 head(new.df,2)
  num11.20 lc11.20 uc11.20
1   11   k   K
2   12   l   L




On Jan 6, 9:49 am, David Winsemius dwinsem...@comcast.net wrote:
 On Jan 6, 2012, at 10:00 AM, Mike Harwood wrote:

  How does R do it, and should I ever be worried?  I always remove
  columns by index, and it works exactly as I would naively expect - but
  HOW?  The second illustration, which deletes non contiguous columns,
  represents what I do all the time and have some trepidation about
  because I don't know the mechanics (e.g. why doesn't the column
  formerly-known-as-4 become 3 after column 1 is dropped: doesn't vector
  removal from a df/list invoke a loop in C?).

 You are NOT removing columns. You are returning (to `head` and then
 to `print`) an extract from the dataframe, but that does not change
 the original dataframe. To effect a change you would need to assign
 the value back to the same name as the original daatframe.

 --
 David









   Can I delete a named
  list of columns, which are examples 4 and 5 and which generate the
  unary error' mesages, without resorting to orig.df$num1.10 - NULL?

  Thanks!

  orig.df - data.frame(cbind(
     1:10
     ,11:20
     ,letters[1:10]
     ,letters[11:20]
     ,LETTERS[1:10]
     ,LETTERS[11:20]
     ))
  names(orig.df) - c(
     'num1.10'
     ,'num11.20'
     ,'lc1.10'
     ,'lc11.20'
     ,'uc1.10'
     ,'uc11.20'
     )
  # Illustration 1: contiguous columns at beginning of data frame
  head(orig.df[,-c(1:3)])

  # Illustration 2: non-contiguous columns
  head(orig.df[,-c(1,3,5)])

  # Illustration 3: contiguous columns at end of data frame
  head(orig.df[,-c(4:6)])    ## as expected

  # Illustrations 4-5: unary errors
  head(orig.df[,-c(as.list('num1.10', 'lc1.10', 'uc1.10'))])
  head(orig.df[,-c('num1.10', 'lc1.10', 'uc1.10')])

  Mike

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

 David Winsemius, MD
 West Hartford, CT

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

__
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 using qda on the spambase training dataset

2012-01-06 Thread Ravi Kulkarni
Hello,
  I am trying to run the code for quadratic discriminant analysis with the
Spambase data set following the code example in the book R in a Nutshell
by Joseph Adler (page 443).
  The line of code: 
spam.qda - qda(formula=is_spam~.,
data=spambase.training)

  gives me an error:
 Error in qda.default(x, grouping, ...)
: rank deficiency in group 1

  (There really is a tilde after is_spam in the code, only on this
web-page it appears as a hyphen :)
  Can someone please tell me why it does not work with me but appears to do
so in the book? I am using R version 2.13.0.

  Thanks,
Ravi

--
View this message in context: 
http://r.789695.n4.nabble.com/Error-using-qda-on-the-spambase-training-dataset-tp4269941p4269941.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] What is wrong with this plotting?

2012-01-06 Thread Sarah Goslee
I think it's even simpler than that:

 plot(y~as.POSIXct(times, format=%d.%m. %H:%M), type=l, 
 data=na.omit(data.frame(y,times)))

This is using y from the data specification in the plot command (not the
y in the base environment, or you'd be getting the same error), and
data= is specifying the data with NAs omitted.

 whereas this plot command...

  plot(input[,2]~as.POSIXct(DateTime, format=%d.%m. %H:%M), type=l, 
 data=na.omit(data.frame(input[,2],DateTime)))

 ... produces the error:

 Error in model.frame.default(formula = input[, 2] ~ as.POSIXct(DateTime,  :
  variable lengths differ (found for 'as.POSIXct(DateTime, format = %d.%m. 
 %H:%M)')

This command is using input[,2] for its y varialble, which has *not* had the
NA values removed.

It's a matter of which data your plot() command is using, and it's not what
you seem to think it is.

Sarah

-- 
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] Dropping columns from data frame

2012-01-06 Thread Sarah Goslee
On Fri, Jan 6, 2012 at 10:00 AM, Mike Harwood harwood...@gmail.com wrote:
 How does R do it, and should I ever be worried?

You should be worried, but not about that.

  I always remove
 columns by index, and it works exactly as I would naively expect - but
 HOW?  The second illustration, which deletes non contiguous columns,
 represents what I do all the time and have some trepidation about
 because I don't know the mechanics (e.g. why doesn't the column
 formerly-known-as-4 become 3 after column 1 is dropped: doesn't vector
 removal from a df/list invoke a loop in C?).

The R programmers, and the S programmers before them, were smart
enough to make this a simultaneous rather than sequential operation.
If you really need the details, the source is out there.

 Can I delete a named
 list of columns, which are examples 4 and 5 and which generate the
 unary error' mesages, without resorting to orig.df$num1.10 - NULL?

head(orig.df[, !colnames(orig.df) %in% c('num1.10', 'lc1.10', 'uc1.10')])

Sarah

 Thanks!

 orig.df - data.frame(cbind(
        1:10
        ,11:20
        ,letters[1:10]
        ,letters[11:20]
        ,LETTERS[1:10]
        ,LETTERS[11:20]
        ))
 names(orig.df) - c(
        'num1.10'
        ,'num11.20'
        ,'lc1.10'
        ,'lc11.20'
        ,'uc1.10'
        ,'uc11.20'
        )
 # Illustration 1: contiguous columns at beginning of data frame
 head(orig.df[,-c(1:3)])

 # Illustration 2: non-contiguous columns
 head(orig.df[,-c(1,3,5)])

 # Illustration 3: contiguous columns at end of data frame
 head(orig.df[,-c(4:6)])         ## as expected

 # Illustrations 4-5: unary errors
 head(orig.df[,-c(as.list('num1.10', 'lc1.10', 'uc1.10'))])
 head(orig.df[,-c('num1.10', 'lc1.10', 'uc1.10')])


 Mike


-- 
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 to fit my data with a distribution?

2012-01-06 Thread R. Michael Weylandt michael.weyla...@gmail.com
MASS::fitdistr

Michael 

On Jan 6, 2012, at 10:47 AM, Andra Isan andra_i...@yahoo.com wrote:

 Dear All, 
 
 
 I have a bunch of data points as follows:
 
 x� 100
 y� 200
 z� 300
 ...
 where 100, 200, 300 are the values. I would like to know the distribution of 
 my data? how can I fit my data into a distribution?
 
 Thanks a lot,
 Andra
 
[[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] Dropping columns from data frame

2012-01-06 Thread David Winsemius


On Jan 6, 2012, at 11:43 AM, Mike Harwood wrote:


Thank you, David.  I was merely using head to limit the code/
output.  My question remains, because a created data frame has the
same columns as was output from head:


head(orig.df,3)

 num1.10 num11.20 lc1.10 lc11.20 uc1.10 uc11.20
1   1   11  a   k  A   K
2   2   12  b   l  B   L
3   3   13  c   m  C   M

# Illustration 1: contiguous columns at beginning of data frame
head(orig.df[,-c(1:3)],2)

 lc11.20 uc1.10 uc11.20
1   k  A   K
2   l  B   L

new.df - orig.df[,-c(1:3)]
head(new.df,2)

 lc11.20 uc1.10 uc11.20
1   k  A   K
2   l  B   L


# Illustration 2: non-contiguous columns
head(orig.df[,-c(1,3,5)],2)

 num11.20 lc11.20 uc11.20
1   11   k   K
2   12   l   L

new.df - orig.df[,-c(1,3,5)]
head(new.df,2)

 num11.20 lc11.20 uc11.20
1   11   k   K
2   12   l   L


I guess my short attention span got the better of me. (But calling  
them unary errors was somewhat cryptic and not a particularly  
helpful description of what you were actually seeing.)  Here are more  
constructive responses:


Negative indexing is not accepted for character vectors, so you need  
to convert to either numeric or logical and then negativize:


orig.df[ !names(orig.df) %in% c('num1.10', 'lc1.10', 'uc1.10')]

These are equivalent:

orig.df[ , !names(orig.df) %in% c('num1.10', 'lc1.10', 'uc1.10')]

orig.df[,-match( c(num1.10, lc1.10, uc1.10), names(orig.df))]

orig.df[ , -sapply(c('num1.10', 'lc1.10', 'uc1.10'), grep,  
x=names(orig.df)) ]



And when there is a pattern, such as with your not wanting any of the . 
10 names, then grep can be quite efficient:


orig.df[ , -grep(.10,  names(orig.df), fixed=TRUE)]


--
David






On Jan 6, 9:49 am, David Winsemius dwinsem...@comcast.net wrote:

On Jan 6, 2012, at 10:00 AM, Mike Harwood wrote:


How does R do it, and should I ever be worried?  I always remove
columns by index, and it works exactly as I would naively expect -  
but

HOW?  The second illustration, which deletes non contiguous columns,
represents what I do all the time and have some trepidation about
because I don't know the mechanics (e.g. why doesn't the column
formerly-known-as-4 become 3 after column 1 is dropped: doesn't  
vector

removal from a df/list invoke a loop in C?).


You are NOT removing columns. You are returning (to `head` and then
to `print`) an extract from the dataframe, but that does not change
the original dataframe. To effect a change you would need to assign
the value back to the same name as the original daatframe.

--
David


 Can I delete a named
list of columns, which are examples 4 and 5 and which generate the
unary error' mesages, without resorting to orig.df$num1.10 -  
NULL?



Thanks!



orig.df - data.frame(cbind(
   1:10
   ,11:20
   ,letters[1:10]
   ,letters[11:20]
   ,LETTERS[1:10]
   ,LETTERS[11:20]
   ))
names(orig.df) - c(
   'num1.10'
   ,'num11.20'
   ,'lc1.10'
   ,'lc11.20'
   ,'uc1.10'
   ,'uc11.20'
   )
# Illustration 1: contiguous columns at beginning of data frame
head(orig.df[,-c(1:3)])



# Illustration 2: non-contiguous columns
head(orig.df[,-c(1,3,5)])



# Illustration 3: contiguous columns at end of data frame
head(orig.df[,-c(4:6)])## as expected



# Illustrations 4-5: unary errors
head(orig.df[,-c(as.list('num1.10', 'lc1.10', 'uc1.10'))])
head(orig.df[,-c('num1.10', 'lc1.10', 'uc1.10')])



Mike



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


David Winsemius, MD
West Hartford, CT

__
r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/ 
listinfo/r-help

PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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


David Winsemius, MD
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] data.frame: temporal complexity

2012-01-06 Thread ikuzar
Ok, thanks, it works !

--
View this message in context: 
http://r.789695.n4.nabble.com/data-frame-temporal-complexity-tp4269585p4270073.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] add data to a file while doing a loop

2012-01-06 Thread MacQueen, Don
Look at the documentation for whatever function you are using to write
data to the file.
It should be pretty obvious (look for an append argument).

Otherwise you'll have to provide more information, such as a short simple
example of what you have tried.

-Don

-- 
Don MacQueen

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





On 1/6/12 3:49 AM, Joao Fadista joao.fadi...@med.lu.se wrote:

Hi,

I would like to know how can I keep adding data to a file while doing a
loop and without deleting the data of the previous iteration. Thanks.

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

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


[R] cbind alternate

2012-01-06 Thread Mary Kindall
I have two one dimensional list of elements and want to perform cbind and
then write into a file. The number of entries are more than a million in
both lists. R is taking a lot of time performing this operation.

Is there any alternate way to perform cbind?

x = table1[1:100,1]
y = table2[1:100,5]

z = cbind(x,y)   //hanging the machine

write.table(z,'out.txt)



-- 
-
Mary Kindall
Yorktown Heights, NY
USA

[[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] RODBC installation: error message

2012-01-06 Thread Marc Schwartz
Hi Gregory,

See below.

On Jan 5, 2012, at 4:20 PM, gregory benison wrote:

 As Duncan noted, the message is pretty clear in that the ODBC header files 
 are missing, which are required to compile RODBC from source. On RH based 
 Linuxen, this requires the installation of the unixODBC-devel RPM, much as 
 one would need to have other *-devel RPMs (eg. readline-devel) installed for 
 compiling many applications from source.
 
 
 Since a lot of R users may not be familiar with these header files, I
 think the configure script could go a step further in explaining why
 it was looking for these headers (to find an installed ODBC driver
 manager), and that it didn't find one.  To illustrate what I mean,
 here is the result of running R CMD INSTALL on a system lacking an
 installed dsm where I swapped the order of the tests in configure.ac
 (see patch below) such that the library tests come before the header
 tests:
 
 * installing *source* package 'RODBC' ...
 checking for library containing SQLTables... no
 configure: error: no ODBC driver manager found
 ERROR: configuration failed for package 'RODBC'
 
 To me, that is a more helpful error message, because it makes it clear
 that you need to install an ODBC driver manager.

snipped other content

To split hairs, there are two issues at play here, irrespective of the ordering 
of the tests:

1. If you do not have unixODBC installed, you will get an error message 
regarding a missing ODBC driver manager, if as you have done here, that test is 
first rather than second.

2. If you have unixODBC installed (so you pass the first test in your 
scenario), but do not have the 'devel' part, which is a separate install on 
most Linuxen with package managers (RHEL/CentOS, Fedora, Debian and derivatives 
like Ubuntu and Mint, etc.), you will still get the error message regarding the 
missing header files. That is an entirely different error than missing the 
actual ODBC driver manager.

So you can argue about the ordering of the tests, but the end result is the 
same. Only if you have some knowledge about compiling source code (on ANY 
operating system), will you understand the meaning of missing header files AND 
only if you have some lower level knowledge of development on Linuxen 
specifically, will you know that the header files are contained in a separate 
binary package that needs to be installed as well, the details of which will be 
specific to the Linux distribution that you have chosen to install.

On top of that, if as with most Linuxen today, you don't have the software 
development packages installed (you are a naive user of Linux and only did a 
default install of the distribution), you won't have compilers and other 
associated tools (eg. make, etc.) installed either. At some point, the user has 
to be responsible for obtaining the requisite knowledge of their operating 
system, independent of the use of R. Despite the protestations by some on the 
web that their grandmothers are running Linux, it is still largely a geek's 
platform (with a 1% to 1.5% marketshare on the desktop) and due to the 
marketplace fragmentation of the plethora of distributions and desktop 
environments, further requires distribution and even version specific knowledge 
as well.

As I noted earlier, if you are going to use Linux, you are generally going to 
be expected to have a more technical level of knowledge than somebody who is 
running Windows or OSX, where for the most part, one can install pre-compiled 
binary packages from CRAN, thanks in large measure to folks like Kurt, Uwe, 
Duncan, Simon and Prof. Ripley (I may be missing others) who have taken the 
time over the years to put the testing and build infrastructure in place to 
automate much of that process.

Since there are over 3,500 packages on CRAN and some proportion (I don't know 
the number) have C/C++ and/or FORTRAN code in them, which will require 
compilation when installing source packages using either install.packages() or 
R CMD INSTALL on Linuxen, addressing RODBC in isolation is ultimately not 
helpful, since like most CRAN packages, it has a finite audience of users (me 
being very thankful to Prof. Ripley to be one of them).

I cannot speak for Prof. Ripley here, but since you seem to have the requisite 
skills, he may be open to accepting a patch against his package that would 
narrowly address the issue that you raise.

However, that does not change the defacto behavior for all of the other CRAN 
packages that will have similar requirements when being installed from source 
and will, as is the case with Linux generally, output relatively terse error 
messages when faced with these kinds of issues.

Also as Duncan noted, perhaps there may be a better mechanism in gaining access 
to install time requirements for CRAN packages. In the case of RODBC, Prof. 
Ripley has taken the time to create a vignette which covers much of this 
material. That is directly available from the CRAN page for the package, 

Re: [R] Spatial data, rpoispp, using window with fixed radius?

2012-01-06 Thread MacQueen, Don
What's wrong with rpoispp in spatstat? It can simulate over a polygon,
which can of course be used to closely approximate a circle. There is also
spsample in the sp package.

I'd also suggest asking this question on r-sig-geo.

-- 
Don MacQueen

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





On 1/6/12 5:17 AM, herbert8...@gmx.de herbert8...@gmx.de wrote:

Dear All,

I was searching through the spatstat manual in order to find a function
to simulate a Poisson pattern only within a fixed radius (circular moving
window) around individual points. If points are distributed
heterogeneously over a large area this may help to only assess deviation
from CSR within the window and thus does not require additional
information on a covariate. I could not find such a function in spatstat.
Can please anyone help?

Thanks,

Herb

--

__
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] (Edited) cbind alternate for data frames

2012-01-06 Thread Mary Kindall

 I have two dataframes and want to perform cbind and then write into a
 file. The number of entries are more than a million in both frames. R is
 taking a lot of time performing this operation.

 Is there any alternate way to perform cbind?

 x = table1[1:100,1:4]
 y = table2[1:100,3:6]

 z = cbind(x,y)   //hanging the machine

 write.table(z,'out.txt)



 --
 -
 Mary Kindall
 Yorktown Heights, NY
 USA



[[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] Assign and cmpfun

2012-01-06 Thread Michael Pearmain
Hi All,

I've just recently discovered the cmpfun function, and was wanting to to
create a function to assign this to all the functions i have created, but
without explicitly naming them.

I've achieved this with:

foo - function(x) { print(x)}
bar - function(x) { print(x + 1)}

 foo - function(x) { print(x)}
 foo
function(x) { print(x)}
 cmpfun(foo)
function(x) { print(x)}
bytecode: 0x26e3d40


find.all.functions - ls.str(mode = 'function')
 for(i in seq_along(find.all.functions)) {
assign(find.all.functions[i], cmpfun(get(find.all.functions[i])))
  }

But remember told that using assign is generally a bad idea, and ideally i
want to functionalize this to say something like:

CreateCompiledFunctions - function() {
  find.all.functions - ls.str(mode = 'function')
  for(i in seq_along(find.all.functions)) {
assign(find.all.functions[i], cmpfun(get(find.all.functions[i])))
  }
}


Does anyone have a better solution?

Thanks in advance

Mike

[[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] data.frame: temporal complexity

2012-01-06 Thread MacQueen, Don
Something like this (not tested)?

  df$diffP - c(NA, NA, diff(df$P,2))

-Don

-- 
Don MacQueen

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





On 1/6/12 6:39 AM, ikuzar raz...@hotmail.fr wrote:

Hello,

I created a data.frame which contains two columns: df$P (Power) et
df$DateTime (time). I'd like to add a new column df$diffP (difference of
Power between T and T-2).

I made a loop :

for (i in 3:length(df$DateTime)){
df$diffP[i] = df$P[i] - df$P[i-2]
}
execution time result is unaceptable: 24s !!

Is there any way to reduce complexity about O(n) ? for example 2 or 3s
(10s
maxi)

Does anybody find better than ~24s ?

thanks for your help

--
View this message in context:
http://r.789695.n4.nabble.com/data-frame-temporal-complexity-tp4269585p426
9585.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] How to fit my data with a distribution?

2012-01-06 Thread Andra Isan
That MASS::fitdistr is used for the case when I have some sense about the 
distribution of my data. When I do not know anything about my data, is there 
any function that can I use to tell what distribution of my data is?

Thanks a lot,
Andra




 From: R. Michael Weylandt michael.weyla...@gmail.com 
michael.weyla...@gmail.com

Cc: r-help@r-project.org r-help@r-project.org 
Sent: Friday, January 6, 2012 11:18 AM
Subject: Re: [R] How to fit my data with a distribution?

MASS::fitdistr

Michael 



 Dear All, 
 
 
 I have a bunch of data points as follows:
 
 x� 100
 y� 200
 z� 300
 ...
 where 100, 200, 300 are the values. I would like to know the distribution of 
 my data? how can I fit my data into a distribution?
 
 Thanks a lot,
 Andra
 
    [[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.
[[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] (Edited) cbind alternate for data frames

2012-01-06 Thread MacQueen, Don
For me, this example runs in a fraction of a second:

 t1 - data.frame(matrix(rnorm(3e6),ncol=3))
 t2 - data.frame(matrix(rnorm(3e6),ncol=3))
 t3 - cbind(t1,t2)
 dim(t3)
[1] 100   6

Maybe it takes longer if your data frames have other classes of objects in
them.
If some of your data frame columns are factors, try converting to
character first.

-Don


-- 
Don MacQueen

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





On 1/6/12 9:56 AM, Mary Kindall mary.kind...@gmail.com wrote:


 I have two dataframes and want to perform cbind and then write into a
 file. The number of entries are more than a million in both frames. R is
 taking a lot of time performing this operation.

 Is there any alternate way to perform cbind?

 x = table1[1:100,1:4]
 y = table2[1:100,3:6]

 z = cbind(x,y)   //hanging the machine

 write.table(z,'out.txt)



 --
 -
 Mary Kindall
 Yorktown Heights, NY
 USA



   [[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] cbind alternate

2012-01-06 Thread Bos, Roger
You could break the data into chunks, so you cbind and save 50,000
observations at a time.  That should be less taxing on your machine and
memory.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Mary Kindall
Sent: Friday, January 06, 2012 12:43 PM
To: r-help@r-project.org
Subject: [R] cbind alternate

I have two one dimensional list of elements and want to perform cbind
and then write into a file. The number of entries are more than a
million in both lists. R is taking a lot of time performing this
operation.

Is there any alternate way to perform cbind?

x = table1[1:100,1]
y = table2[1:100,5]

z = cbind(x,y)   //hanging the machine

write.table(z,'out.txt)



--
-
Mary Kindall
Yorktown Heights, NY
USA

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

***
This message is for the named person's use only. It may\...{{dropped:11}}

__
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 fit my data with a distribution?

2012-01-06 Thread David Winsemius


On Jan 6, 2012, at 1:02 PM, Andra Isan wrote:

That MASS::fitdistr is used for the case when I have some sense  
about the distribution of my data. When I do not know anything about  
my data, is there any function that can I use to tell what  
distribution of my data is?


?density




From: R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com 



Cc: r-help@r-project.org r-help@r-project.org
Sent: Friday, January 6, 2012 11:18 AM
Subject: Re: [R] How to fit my data with a distribution?

MASS::fitdistr

Michael



I have a bunch of data points as follows:

x� 100
y� 200
z� 300
...
where 100, 200, 300 are the values. I would like to know the  
distribution of my data? how can I fit my data into a distribution?


Thanks a lot,
Andra


David Winsemius, MD
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] add data to a file while doing a loop

2012-01-06 Thread William Dunlap
Using append=TRUE in many functions will work, but
more slowly than opening a connection once, writing
to the connection many times, then closing it.
(Opening a file is a pretty expensive operation,
while writing to it is much cheaper.)  Some more
recently written functions do not have an append=
argument because you can achieve the same with connections.

E.g., I wrote functions that used
cat(file=fileName, append=TRUE) repeatedly
and the open/cat-repeatedly/close method:

  f0 - function (n, fileName) 
  {
  unlink(fileName)
  system.time(for (i in seq_len(n)) cat(Line, i, \n, file = fileName, 
  append = TRUE))
  }
  f1 - function (n, fileName) {
  unlink(fileName)
  system.time({
  fileConn - file(fileName, wt)
  on.exit(close(fileConn))
  for (i in seq_len(n)) cat(Line, i, \n, file = fileConn)
  })
  }

and recorded the time they took to write
1000, 2000, and 2 lines on my Window XP
laptop:

   tf0 - tempfile()
   f0(1*10^3, tf0)
 user  system elapsed 
 0.160.458.25 
   f0(2*10^3, tf0)
 user  system elapsed 
 0.360.98   17.86 
   f0(20*10^3, tf0)
 user  system elapsed 
 5.03   10.64  393.95 
   
   tf1 - tempfile()
   f1(1*10^3, tf1)
 user  system elapsed 
 0.050.090.15 
   f1(2*10^3, tf1)
 user  system elapsed 
 0.020.080.11 
   f1(20*10^3, tf1)
 user  system elapsed 
 0.300.700.98 
 
Note that they produced identical output files: 
   identical(readLines(tf0), readLines(tf1))
  [1] TRUE
and the connection-oriented version is still usable
for a million or two iterations:
   f1(1e6, tf1)
 user  system elapsed 
15.40   30.05   45.19
   f1(2e6, tf1)
 user  system elapsed 
31.95   60.29   91.42

Any of the standard functions with a file= (or con=)
argument will accept a connction object instead of
a file name.  If you use the connection object you
don't need to restrict yourself to functions with
an append= argument to append to a file.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of MacQueen, Don
 Sent: Friday, January 06, 2012 9:32 AM
 To: Joao Fadista; r-help@r-project.org
 Subject: Re: [R] add data to a file while doing a loop
 
 Look at the documentation for whatever function you are using to write
 data to the file.
 It should be pretty obvious (look for an append argument).
 
 Otherwise you'll have to provide more information, such as a short simple
 example of what you have tried.
 
 -Don
 
 --
 Don MacQueen
 
 Lawrence Livermore National Laboratory
 7000 East Ave., L-627
 Livermore, CA 94550
 925-423-1062
 
 
 
 
 
 On 1/6/12 3:49 AM, Joao Fadista joao.fadi...@med.lu.se wrote:
 
 Hi,
 
 I would like to know how can I keep adding data to a file while doing a
 loop and without deleting the data of the previous iteration. Thanks.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-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] add data to a file while doing a loop

2012-01-06 Thread Joao Fadista
Thank you all for your useful replies. I got it to work!

Best regards,
João Fadista, Ph.D.
Post Doc

Lund University Diabetes Centre
CRC, Malmö University Hospital
Entrance 72, building 60, level 13
SE-205 02 Malmö, Sweden
Tel: +46 (0)40 391237
e-mail: joao.fadi...@med.lu.se


-Original Message-
From: William Dunlap [mailto:wdun...@tibco.com] 
Sent: den 6 januari 2012 19:27
To: MacQueen, Don; Joao Fadista; r-help@r-project.org
Subject: RE: [R] add data to a file while doing a loop

Using append=TRUE in many functions will work, but more slowly than opening a 
connection once, writing to the connection many times, then closing it.
(Opening a file is a pretty expensive operation, while writing to it is much 
cheaper.)  Some more recently written functions do not have an append= argument 
because you can achieve the same with connections.

E.g., I wrote functions that used
cat(file=fileName, append=TRUE) repeatedly and the open/cat-repeatedly/close 
method:

  f0 - function (n, fileName)
  {
  unlink(fileName)
  system.time(for (i in seq_len(n)) cat(Line, i, \n, file = fileName, 
  append = TRUE))
  }
  f1 - function (n, fileName) {
  unlink(fileName)
  system.time({
  fileConn - file(fileName, wt)
  on.exit(close(fileConn))
  for (i in seq_len(n)) cat(Line, i, \n, file = fileConn)
  })
  }

and recorded the time they took to write 1000, 2000, and 2 lines on my 
Window XP
laptop:

   tf0 - tempfile()
   f0(1*10^3, tf0)
 user  system elapsed 
 0.160.458.25 
   f0(2*10^3, tf0)
 user  system elapsed 
 0.360.98   17.86 
   f0(20*10^3, tf0)
 user  system elapsed 
 5.03   10.64  393.95 
  
   tf1 - tempfile()
   f1(1*10^3, tf1)
 user  system elapsed 
 0.050.090.15 
   f1(2*10^3, tf1)
 user  system elapsed 
 0.020.080.11 
   f1(20*10^3, tf1)
 user  system elapsed 
 0.300.700.98 
 
Note that they produced identical output files: 
   identical(readLines(tf0), readLines(tf1))
  [1] TRUE
and the connection-oriented version is still usable for a million or two 
iterations:
   f1(1e6, tf1)
 user  system elapsed 
15.40   30.05   45.19
   f1(2e6, tf1)
 user  system elapsed 
31.95   60.29   91.42

Any of the standard functions with a file= (or con=) argument will accept a 
connction object instead of a file name.  If you use the connection object you 
don't need to restrict yourself to functions with an append= argument to append 
to a file.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of MacQueen, Don
 Sent: Friday, January 06, 2012 9:32 AM
 To: Joao Fadista; r-help@r-project.org
 Subject: Re: [R] add data to a file while doing a loop
 
 Look at the documentation for whatever function you are using to write 
 data to the file.
 It should be pretty obvious (look for an append argument).
 
 Otherwise you'll have to provide more information, such as a short 
 simple example of what you have tried.
 
 -Don
 
 --
 Don MacQueen
 
 Lawrence Livermore National Laboratory
 7000 East Ave., L-627
 Livermore, CA 94550
 925-423-1062
 
 
 
 
 
 On 1/6/12 3:49 AM, Joao Fadista joao.fadi...@med.lu.se wrote:
 
 Hi,
 
 I would like to know how can I keep adding data to a file while doing 
 a loop and without deleting the data of the previous iteration. Thanks.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-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] data.frame: temporal complexity

2012-01-06 Thread ikuzar
I did not test this way, I 'll do it later, I think  that df$diffP - c(NA,
NA, diff(df$P,2))  is the best way to compute the difference !! I 'll post
the result here

--
View this message in context: 
http://r.789695.n4.nabble.com/data-frame-temporal-complexity-tp4269585p4270256.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] cbind alternate

2012-01-06 Thread Marc Schwartz
On Jan 6, 2012, at 11:43 AM, Mary Kindall wrote:

 I have two one dimensional list of elements and want to perform cbind and
 then write into a file. The number of entries are more than a million in
 both lists. R is taking a lot of time performing this operation.
 
 Is there any alternate way to perform cbind?
 
 x = table1[1:100,1]
 y = table2[1:100,5]
 
 z = cbind(x,y)   //hanging the machine
 
 write.table(z,'out.txt)



The issue is not the use of cbind(), but that write.table() can be slow with 
data frames, where each column may be a different class (data type) and 
requires separate formatting for output. This is referenced in the Note section 
of ?write.table:

write.table can be slow for data frames with large numbers (hundreds or more) 
of columns: this is inevitable as each column could be of a different class and 
so must be handled separately. If they are all of the same class, consider 
using a matrix instead.


I suspect in this case, while you don't have a large number of columns, you do 
have a large number of rows, so that there is a tradeoff.

If all of the columns in your source tables are of the same type (eg. all 
numeric), coerce 'z' to a matrix and then try using write.table().

z - matrix(rnorm(100 * 6), ncol = 6)

 str(z)
 num [1:100, 1:6] -0.713 0.79 -0.538 0.945 1.621 ...

 system.time(write.table(z, file = test.txt))
   user  system elapsed 
 12.664   0.292  13.029 


The resultant file is about 118 Mb on my system.

HTH,

Marc Schwartz

__
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 fit my data with a distribution?

2012-01-06 Thread Bert Gunter
 except, of course, that the distributions of all finite sets of
data are the same: discrete.

I think Andra would do well to seek help from his/her local
statistician, as his/her query seems to indicate considerable
confusion about basic concepts.

Please excuse me if I have misjudged.

-- Bert

On Fri, Jan 6, 2012 at 10:13 AM, David Winsemius dwinsem...@comcast.net wrote:

 On Jan 6, 2012, at 1:02 PM, Andra Isan wrote:

 That MASS::fitdistr is used for the case when I have some sense about the
 distribution of my data. When I do not know anything about my data, is there
 any function that can I use to tell what distribution of my data is?


 ?density


 
 From: R. Michael Weylandt michael.weyla...@gmail.com
 michael.weyla...@gmail.com

 Cc: r-help@r-project.org r-help@r-project.org
 Sent: Friday, January 6, 2012 11:18 AM
 Subject: Re: [R] How to fit my data with a distribution?

 MASS::fitdistr

 Michael


 I have a bunch of data points as follows:

 x� 100
 y� 200
 z� 300
 ...
 where 100, 200, 300 are the values. I would like to know the distribution
 of my data? how can I fit my data into a distribution?

 Thanks a lot,
 Andra


 David Winsemius, MD
 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] Correlated count data technique advice

2012-01-06 Thread Lee Davis
Please excuse me for having posted a similar question on ecolog, but thus
far I have received few useful answers there.

I am looking for some advice concerning techniques in R that are
appropriate for correlated count data.

Specifically, I have some freezing days data, which is a count of the
number of days each spring that were below freezing. The counts were taken
at the same location over a period of years. The data set is highly zero
inflated and over-dispersed; glm with a quasipoisson error structure would
seem to be appropriate, except that there is a high degree of correlation
at lags of 1 making something like a corAR1 structure appropriate. My
difficulty is that glm() does not take an argument for correlation.

I could use  lmer() to fit a model like:

freezing days~years+(1|years), family=quasipoisson, correlation=corAR1

but lmer (and glmer) don't seem to be operating on quasi families anymore;
I've found plenty of old posts here where lmer seems to have accepted quasi
families in the past, but I get an error message that indicates lmer does
not in fact accept quasi families.

I should note that I have run the following model:

 freeze.glmmPQL3-glmmPQL(num.freeze.days~years, random= ~1|years,
   family=quasipoisson,correlation=corAR1())

My gut says this is not the correct approach and I am unconvinced by the
tiny p values that have been returned, especially as specification of
poisson vs quasipoisson and the specification of corAR1() seem to make no
difference to parameter estimation or p vals for said pars--it would seem
that the random term for varying intercept by year is dominant. Maybe this
is OK, but my above glm models return non-significant results and I
expected handling the correlation to increase my p vals rather than
decrease them. Perhaps an incorrect assumption.

Therefore I need some alternative to look at trends in this data over time
that allows for quasipoisson error and something along the lines of a
corAR1() structure (or a mixed model that handles temporal
pseudo-replication, but I am hesitant here).

Thank you in advance,
Lee

[[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] cbind alternate

2012-01-06 Thread David Winsemius


On Jan 6, 2012, at 12:43 PM, Mary Kindall wrote:

I have two one dimensional list of elements and want to perform  
cbind and
then write into a file. The number of entries are more than a  
million in

both lists. R is taking a lot of time performing this operation.

Is there any alternate way to perform cbind?

x =
y = table2[1:100,5]

z = cbind(x,y)   //hanging the machine


You should have been able to bypass the intermediate steps with just:

z = cbind( table1[1:100,1] table2[1:100,5])

Whether you will have sufficient contiguous memory for that object at  
the moment or even after rm(x), rm(y) is in doubt, but had you not  
created the unneeded x and y, you _might_ have succeeded in your  
limited environment. (Real answer: Buy more RAM.)


I speculate that you are on Windows and so refer your to the R-Win FAQ  
for further reading about memory limits.





write.table(z,'out.txt)


I do not know of a way to bypass the requirement of a named object to  
pass to write.table, but testing suggests that you could try:


write( t(cbind( table1[1:100,1] table2[1:100,5])).   
test.txt, 2)


write()  does not require a named object but is less inquisitive than  
write table and will give you a transposed matrix with 5 columns by  
default which will really mess up things, so you need to transpose and  
specify the number of columns. (And that may not save any space over  
creating a z object.)


So there is another thread today to which master R programmer Bill  
Dunlap has offered this strategy (with minor modifications to your  
situation by me):


###
f1 - function (n, fileName) {
 unlink(fileName)
 system.time({
 fileConn - file(fileName, wt)
 on.exit(close(fileConn))
 for (i in seq_len(n)) cat( table1[i, 1],  ,
table2[i, 5],
  \n, file = fileConn)
 })
 }

f1(100, 'out.txt')

#
--

David Winsemius, MD
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] cbind alternate

2012-01-06 Thread Marc Schwartz

On Jan 6, 2012, at 12:39 PM, Marc Schwartz wrote:

 On Jan 6, 2012, at 11:43 AM, Mary Kindall wrote:
 
 I have two one dimensional list of elements and want to perform cbind and
 then write into a file. The number of entries are more than a million in
 both lists. R is taking a lot of time performing this operation.
 
 Is there any alternate way to perform cbind?
 
 x = table1[1:100,1]
 y = table2[1:100,5]
 
 z = cbind(x,y)   //hanging the machine
 
 write.table(z,'out.txt)
 

Apologies, I mis-read where the hang up was. It is in the use of cbind() prior 
to calling write.table(), not in write.table() itself.

Not sure why that part is taking a long time, unless as already mentioned, you 
are short on memory available. This runs quickly for me:

x - matrix(rnorm(100 * 3), ncol = 3)
y - matrix(rnorm(100 * 3), ncol = 3)
 
 system.time(z - cbind(x, y))
   user  system elapsed 
  0.039   0.025   0.065 

 str(z)
 num [1:100, 1:6] -0.5102 1.8776 2.4635 0.2982 0.0901 ...


To give an example with two data frames containing differing data types, let's 
use the built-in 'iris' data set, which has 5 columns and 150 rows by default. 
Let's create a new version with over a million rows:

iris.new - iris[rep(seq(nrow(iris)), 7000), ]

 str(iris.new)
'data.frame':   105 obs. of  5 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 
1 ...


 system.time(iris.new2 - cbind(iris.new, iris.new))
   user  system elapsed 
  5.289   0.282   5.658 


 str(iris.new2)
'data.frame':   105 obs. of  10 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 
1 ...
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species : Factor w/ 3 levels setosa,versicolor,..: 1 1 1 1 1 1 1 1 1 
1 ...


You might verify the structures of your 'x' and 'y' to be sure that there is 
not something amiss with either one.

HTH,

Marc Schwartz

__
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 properly re-set a saved seed? I've got the answer, but no explanation

2012-01-06 Thread Paul Johnson
Hello, happy new year.

I've come back to a problem from last spring. I need to understand
what what is the technically correct method to save a seed and then
re-set it.  Although this example arises in the context of MT19937,
I'm needing to do this with other generators as well, including
L'Ecuyer streams.

The puzzle is this comment in ?Random: ‘set.seed’ is the recommended
way to specify seeds.

What I did not understand before, and can't make sense of now, is that
set.seed does not re-set a saved seed.  Here's my working example:


## Paul Johnson
## April 20, 2011

## If you've never dug into the R random number generator and its use of the
## default MT19937, this might be informative.  It will also help you
## avoid a time-consuming mistake that I've made recently.

## I've been developing a simulation and I want to save and restore random
## streams exactly. I got that idea from John Chambers Software for
## Data Analysis and I studied his functions to see how he did it.
## The problem, as we see below, is that set.seed() doesn't do what I expected,
## and I feel lucky to have noticed it now, rather than later.

## I wish set.seed did work the way I want, though, and that's why I'm
## writing here, to see if anybody else wishes the same.

## Here's a puzzle.  Try this:
set.seed(444)
s1 - .Random.seed
runif(1)
rnorm(1)

set.seed(444)
runif(1)
rnorm(1)
## Those matched. Good

## Re-insert the saved seed s1
set.seed(s1)
runif(1)
rnorm(1)

## Why don't the draws match? I put back the seed, didn't I?
## Hm. Try again
set.seed(s1)
runif(1)
rnorm(1)

## Why did those match? But neither matches cases 1 and 2.

## I was baffled  discouraged.

## The help page for random numbers says:
##  ‘set.seed’ is the recommended way to specify seeds.

## But, it doesn't say something like

# set.seed(s1)

## is supposed to work. Ah. My mistake.

 Here's the fix and the puzzle ###
## To re-set the generator to its position at s1, it is required
## to do what the help page seems to say we should not.

.Random.seed - s1

runif(1)
#

-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas

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


Re: [R] cbind alternate

2012-01-06 Thread Rui Barradas
Hello,

I believe this function can handle a problem of that size, or bigger.

It does NOT create the full matrix, just writes it to a file, a certain
number of lines at a time.


write.big.matrix - function(x, y, outfile, nmax=1000){

if(file.exists(outfile)) unlink(outfile)
testf - file(outfile, at)   # or wt - write text
on.exit(close(testf))

step - nmax # how many at a time
inx  - seq(1, length(x), by=step)   # index into 'x' and 'y'
mat  - matrix(0, nrow=step, ncol=2) # create a work matrix

# do it 'nmax' rows per iteration
for(i in inx){
mat - cbind(x[i:(i+step-1)], y[i:(i+step-1)])
write.table(mat, file=testf, quote=FALSE, row.names=FALSE,
col.names=FALSE)
}

# and now the remainder
mat - NULL
mat - cbind(x[(i+1):length(x)], y[(i+1):length(y)])
write.table(mat, file=testf, quote=FALSE, row.names=FALSE, 
col.names=FALSE)

# return the output filename
outfile
}

x - 1:1e6  # a numeric vector
y - sample(letters, 1e6, replace=TRUE) # and a character vector
length(x);length(y) # of the same length
fl - test.txt# output file

system.time(write.big.matrix(x, y, outfile=fl))


On my system it takes (sample output)

   user  system elapsed 
   1.590.041.65

and can handle different types of data. In the example, numeric and
character.

If you also need the matrix, try to use 'cbind' first, without writing to a
file.
If it's still slow, adapt the code above to keep inserting chunks in an
output matrix.

Rui Barradas




--
View this message in context: 
http://r.789695.n4.nabble.com/cbind-alternate-tp4270188p4270444.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] How to properly re-set a saved seed? I've got the answer, but no explanation

2012-01-06 Thread Sarah Goslee
Hi Paul,

Did you try looking at s1, or ?.Random.seed

s1 - 444
set.seed(s1)

will give you the same result as

set.seed(444)

but .Random.seed does not contain the seed (444), but the state of
the RNG, and is an integer vector.

You can save that state using

s1 - .Random.seed

and restore it using

.Random.seed - s1

but that's not the same thing that set.seed() does, or the information the
latter requires.

So you have two options:
1. save the integer seed and use set.seed() to assign it.
2. save the RNG state from .Random.seed and restore it later.

The latter, by the way, is entirely reasonable to do. What the help warns
you against is altering part of .Random.seed

Unless I've completely misinterpreted your question, always possible,
you're mixing two distinct but related types of information.

Sarah

On Fri, Jan 6, 2012 at 2:05 PM, Paul Johnson pauljoh...@gmail.com wrote:
 Hello, happy new year.

 I've come back to a problem from last spring. I need to understand
 what what is the technically correct method to save a seed and then
 re-set it.  Although this example arises in the context of MT19937,
 I'm needing to do this with other generators as well, including
 L'Ecuyer streams.

 The puzzle is this comment in ?Random: ‘set.seed’ is the recommended
 way to specify seeds.

 What I did not understand before, and can't make sense of now, is that
 set.seed does not re-set a saved seed.  Here's my working example:


 ## Paul Johnson
 ## April 20, 2011

 ## If you've never dug into the R random number generator and its use of the
 ## default MT19937, this might be informative.  It will also help you
 ## avoid a time-consuming mistake that I've made recently.

 ## I've been developing a simulation and I want to save and restore random
 ## streams exactly. I got that idea from John Chambers Software for
 ## Data Analysis and I studied his functions to see how he did it.
 ## The problem, as we see below, is that set.seed() doesn't do what I 
 expected,
 ## and I feel lucky to have noticed it now, rather than later.

 ## I wish set.seed did work the way I want, though, and that's why I'm
 ## writing here, to see if anybody else wishes the same.

 ## Here's a puzzle.  Try this:
 set.seed(444)
 s1 - .Random.seed
 runif(1)
 rnorm(1)

 set.seed(444)
 runif(1)
 rnorm(1)
 ## Those matched. Good

 ## Re-insert the saved seed s1
 set.seed(s1)
 runif(1)
 rnorm(1)

 ## Why don't the draws match? I put back the seed, didn't I?
 ## Hm. Try again
 set.seed(s1)
 runif(1)
 rnorm(1)

 ## Why did those match? But neither matches cases 1 and 2.

 ## I was baffled  discouraged.

 ## The help page for random numbers says:
 ##  ‘set.seed’ is the recommended way to specify seeds.

 ## But, it doesn't say something like

 # set.seed(s1)

 ## is supposed to work. Ah. My mistake.

  Here's the fix and the puzzle ###
 ## To re-set the generator to its position at s1, it is required
 ## to do what the help page seems to say we should not.

 .Random.seed - s1

 runif(1)
 #


-- 
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] Assign and cmpfun

2012-01-06 Thread Duncan Murdoch

On 12-01-06 12:18 PM, Michael Pearmain wrote:

Hi All,

I've just recently discovered the cmpfun function, and was wanting to to
create a function to assign this to all the functions i have created, but
without explicitly naming them.

I've achieved this with:

foo- function(x) { print(x)}
bar- function(x) { print(x + 1)}


foo- function(x) { print(x)}
foo

function(x) { print(x)}

cmpfun(foo)

function(x) { print(x)}
bytecode: 0x26e3d40




find.all.functions- ls.str(mode = 'function')
  for(i in seq_along(find.all.functions)) {
 assign(find.all.functions[i], cmpfun(get(find.all.functions[i])))
   }

But remember told that using assign is generally a bad idea, and ideally i
want to functionalize this to say something like:

CreateCompiledFunctions- function() {
   find.all.functions- ls.str(mode = 'function')
   for(i in seq_along(find.all.functions)) {
 assign(find.all.functions[i], cmpfun(get(find.all.functions[i])))
   }
}


Does anyone have a better solution?


Put your functions in a package, and install it with the --byte-compile 
option.  This is better in two ways:


1.  You have a package, which is *much* better than having a bunch of 
functions sitting around in an .Rdata file.


2.  You don't recompile functions that are already compiled.

Duncan Murdoch



Thanks in advance

Mike

[[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 properly re-set a saved seed? I've got the answer, but no explanation

2012-01-06 Thread William Dunlap
In S+ you can do
   orig - .Random.seed
   x - runif(10)
   set.seed(orig)
   identical(x, runif(10)) # return TRUE
because S+'s set.seed interprets a non-scalar
input as a copy of an old .Random.seed and assigns
it in the proper location.  (It throws an error
if it is not a valid value for .Random.seed.)

In R you use set.seed to set a proxy seed (an integer
that maps into the real seed) and, I think,
   .Random.seed - orig
to set the real seed.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Sarah Goslee
 Sent: Friday, January 06, 2012 11:21 AM
 To: Paul Johnson
 Cc: R-help
 Subject: Re: [R] How to properly re-set a saved seed? I've got the answer, 
 but no explanation
 
 Hi Paul,
 
 Did you try looking at s1, or ?.Random.seed
 
 s1 - 444
 set.seed(s1)
 
 will give you the same result as
 
 set.seed(444)
 
 but .Random.seed does not contain the seed (444), but the state of
 the RNG, and is an integer vector.
 
 You can save that state using
 
 s1 - .Random.seed
 
 and restore it using
 
 .Random.seed - s1
 
 but that's not the same thing that set.seed() does, or the information the
 latter requires.
 
 So you have two options:
 1. save the integer seed and use set.seed() to assign it.
 2. save the RNG state from .Random.seed and restore it later.
 
 The latter, by the way, is entirely reasonable to do. What the help warns
 you against is altering part of .Random.seed
 
 Unless I've completely misinterpreted your question, always possible,
 you're mixing two distinct but related types of information.
 
 Sarah
 
 On Fri, Jan 6, 2012 at 2:05 PM, Paul Johnson pauljoh...@gmail.com wrote:
  Hello, happy new year.
 
  I've come back to a problem from last spring. I need to understand
  what what is the technically correct method to save a seed and then
  re-set it.  Although this example arises in the context of MT19937,
  I'm needing to do this with other generators as well, including
  L'Ecuyer streams.
 
  The puzzle is this comment in ?Random: 'set.seed' is the recommended
  way to specify seeds.
 
  What I did not understand before, and can't make sense of now, is that
  set.seed does not re-set a saved seed.  Here's my working example:
 
 
  ## Paul Johnson
  ## April 20, 2011
 
  ## If you've never dug into the R random number generator and its use of the
  ## default MT19937, this might be informative.  It will also help you
  ## avoid a time-consuming mistake that I've made recently.
 
  ## I've been developing a simulation and I want to save and restore random
  ## streams exactly. I got that idea from John Chambers Software for
  ## Data Analysis and I studied his functions to see how he did it.
  ## The problem, as we see below, is that set.seed() doesn't do what I 
  expected,
  ## and I feel lucky to have noticed it now, rather than later.
 
  ## I wish set.seed did work the way I want, though, and that's why I'm
  ## writing here, to see if anybody else wishes the same.
 
  ## Here's a puzzle.  Try this:
  set.seed(444)
  s1 - .Random.seed
  runif(1)
  rnorm(1)
 
  set.seed(444)
  runif(1)
  rnorm(1)
  ## Those matched. Good
 
  ## Re-insert the saved seed s1
  set.seed(s1)
  runif(1)
  rnorm(1)
 
  ## Why don't the draws match? I put back the seed, didn't I?
  ## Hm. Try again
  set.seed(s1)
  runif(1)
  rnorm(1)
 
  ## Why did those match? But neither matches cases 1 and 2.
 
  ## I was baffled  discouraged.
 
  ## The help page for random numbers says:
  ##  'set.seed' is the recommended way to specify seeds.
 
  ## But, it doesn't say something like
 
  # set.seed(s1)
 
  ## is supposed to work. Ah. My mistake.
 
   Here's the fix and the puzzle ###
  ## To re-set the generator to its position at s1, it is required
  ## to do what the help page seems to say we should not.
 
  .Random.seed - s1
 
  runif(1)
  #
 
 
 --
 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.

__
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] Bootstrapping nlme models

2012-01-06 Thread lynnland
Hi, Let me start my saying that I am new to R hence my grasp of the
appropriate used of R coding is undoubtedly way behind many on this forum.

I am trying to use boostrapping to derive errors around my parameter
estimate for the fixed effects in the following model. It is simply
estimating the number of times an animal might cross a road based on the
road's distance from a stream. I have tried several different methods but
have been unsuccessful. I have tried both using the boot package and simply
developing a bit of code that resamples my data and drops the parameter
estimates into a new vector. I would be interested in running both a
parametric and non-parametric version.  

model2-nlme(nwfcross~a*exp(-b*nwfdist), 
fixed=a+b~1, 
random=a+b~1|nwfid,
start=c(a=300,b=0.016))

Any help would be greatly appreciated. If it is helpful I can add in some of
the code I have tried and the resulting error messages.

Lynn




--
View this message in context: 
http://r.789695.n4.nabble.com/Bootstrapping-nlme-models-tp4270557p4270557.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] cbind alternate

2012-01-06 Thread Rui Barradas
Sorry Mary,

My function would write the remainder twice, I had only tested it
with multiples of the chunk size.
(And without looking at the lenghty output correctly.)

Now checked:

write.big.matrix - function(x, y, outfile, nmax=1000){

if(file.exists(outfile)) unlink(outfile)
testf - file(outfile, at)   # or wt - write text
on.exit(close(testf))

step - nmax  # how many at a time
inx  - seq(1, length(x)-step, by=step)   # index into 'x' and 'y'

mat  - matrix(0, nrow=step, ncol=2) # create a work matrix

# do it 'nmax' rows per iteration
for(i in inx){
mat - cbind(x[i:(i+step-1)], y[i:(i+step-1)])
write.table(mat, file=testf, quote=FALSE, row.names=FALSE,
col.names=FALSE)
}

# and now the remainder
if(i+step  length(x)){
mat - NULL
mat - cbind(x[(i+step):length(x)], y[(i+step):length(y)])
write.table(mat, file=testf, quote=FALSE, row.names=FALSE,
col.names=FALSE)
}
# return the output filename
outfile
}

x - 1:(1e6 + 1234) # a numeric vector
y - sample(letters, 1e6 + 1234, replace=TRUE)  # and a character vector
length(x);length(y) # of the same length
fl - test.txt# output file

system.time(write.big.matrix(x, y, outfile=fl, nmax=100))

   user  system elapsed 
   3.040.063.09

system.time(write.big.matrix(x, y, outfile=fl))

   user  system elapsed 
   1.640.121.76

Rui Barradas


--
View this message in context: 
http://r.789695.n4.nabble.com/cbind-alternate-tp4270188p4270687.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] Please help!! How do I set graphical parameters for ploting ctree()

2012-01-06 Thread Chris Conner
I'm trying to understand how to set graphical parameters for trees created with 
the party package.  For example take the following code:
 
library(party)
    data(airquality)
    airq - subset(airquality, !is.na(Ozone))
    airct - ctree(Ozone ~ ., data = airq, 
   controls = ctree_control(maxsurrogate = 3))
    plot(airct)
 
My problem is, I've got a ctree that has 14 terminal nodes, and as a result of 
the default graphical paramters of plot(ctree), all of the text is completely 
undreadable (decison node text is too large and as a result, these 
nodes overlap one another, terminal node barplot text overlaps hideously).  
What I would like to do is learn how to customize the elements of these 
plots.  For the text, I have tried par(cex=.4, cex.main=.4, cex.axis=.2, 
cex.lab=.2)... to no avail.  As far as reducing the size of the node ovals, I'm 
completely lost there... 
 
Anyone have any suggestions?
 
Thanks in advance!
Chris
[[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] cbind alternate

2012-01-06 Thread jim holtman
What is it you want to do with the data after you save it?  Are you
just going to read it back into R?  If so, consider using save/load.

On Fri, Jan 6, 2012 at 12:43 PM, Mary Kindall mary.kind...@gmail.com wrote:
 I have two one dimensional list of elements and want to perform cbind and
 then write into a file. The number of entries are more than a million in
 both lists. R is taking a lot of time performing this operation.

 Is there any alternate way to perform cbind?

 x = table1[1:100,1]
 y = table2[1:100,5]

 z = cbind(x,y)   //hanging the machine

 write.table(z,'out.txt)



 --
 -
 Mary Kindall
 Yorktown Heights, NY
 USA

        [[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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] Sweave Chunks

2012-01-06 Thread Riccardo Romoli

Hi, is there a way to collapse/expand the Sweave chunks?

Best
Riccardo

__
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] Spatial data, rpoispp, using window with fixed radius?

2012-01-06 Thread Rolf Turner

On 07/01/12 02:17, herbert8...@gmx.de wrote:

Dear All,

I was searching through the spatstat manual in order to find a function to 
simulate a Poisson pattern only within a fixed radius (circular moving window) 
around individual points. If points are distributed heterogeneously over a 
large area this may help to only assess deviation from CSR within the window 
and thus does not require additional information on a covariate. I could not 
find such a function in spatstat. Can please anyone help?


It's not clear to me just what you want to do, but it *sounds* like you want
to simulate a cluster process with each cluster being a Poisson pattern
in a disk of fixed radius.  If so, the function rMatClust() does just 
what you

want.

It seems to me also possible that you want to pre-specify the cluster 
centres,
or parent points.  Such a capability is *not* currently built into 
spatstat but

would not be hard to code up.  Let me know if you indeed want to pre-specify
the cluster centres.

cheers,

Rolf Turner

__
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 installation: error message

2012-01-06 Thread gregory benison

 1. If you do not have unixODBC installed, you will get an error message 
 regarding a missing ODBC driver manager, if as you have done here, that test 
 is first rather than second.

If the test for the headers comes first, and no driver manager is
installed, configure exits with an error before the library test is
run (hence the error message regarding a missing driver manager is not
displayed).

 I cannot speak for Prof. Ripley here, but since you seem to have the 
 requisite skills, he may be open to accepting a patch against his package 
 that would narrowly address the issue that you raise.


OK, here's my shot at such a patch (below), together with the
resulting configure output in cases where the library or the headers
are missing.  I realize that there are matters of style preference
here, that this approach errs on the side of verbosity rather than
terseness, and that it's entirely up to the R package maintainers
which style to adopt.

Thanks for the replies!

Greg

 Case 1, no ODBC driver manager installed =

checking for stdint.h... yes
checking for unistd.h... yes
checking sql.h usability... no
checking sql.h presence... no
checking for sql.h... no
checking sqlext.h usability... no
checking sqlext.h presence... no
checking for sqlext.h... no
checking for library containing SQLTables... no
configure: error:
No ODBC driver manager found;
see section Installation in inst/doc/RODBC.pdf
(also at http://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf)
ERROR: configuration failed for package 'RODBC'

== Case 2, driver manager installed but no headers 

checking for unistd.h... yes
checking sql.h usability... no
checking sql.h presence... no
checking for sql.h... no
checking sqlext.h usability... no
checking sqlext.h presence... no
checking for sqlext.h... no
checking for library containing SQLTables... -lodbc
configure: error:
Found ODBC driver manager library (-lodbc),
but not required ODBC headers sql.h and sqlext.h.
(Need -devel version of ODBC driver manager?)

ERROR: configuration failed for package 'RODBC'

= patch follows 

diff --git a/configure.ac b/configure.ac
index 8f9fc6a..8661e8f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,10 +64,6 @@ CPPFLAGS=${CPPFLAGS} ${RODBC_CPPFLAGS}

 dnl Check the headers can be found
 AC_CHECK_HEADERS(sql.h sqlext.h)
-if test ${ac_cv_header_sql_h} = no ||
-   test ${ac_cv_header_sqlext_h} = no; then
-   AC_MSG_ERROR(ODBC headers sql.h and sqlext.h not found)
-fi

 dnl search for a library containing an ODBC function
 if test [ -n ${odbc_mgr} ] ; then
@@ -75,9 +71,23 @@ if test [ -n ${odbc_mgr} ] ; then
 AC_MSG_ERROR(ODBC driver manager '${odbc_mgr}' not found))
 else
   AC_SEARCH_LIBS(SQLTables, odbc odbc32 iodbc, ,
-AC_MSG_ERROR(no ODBC driver manager found))
+AC_MSG_ERROR([
+No ODBC driver manager found;
+see section Installation in inst/doc/RODBC.pdf
+(also at http://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf)]))
+fi
+
+dnl Exit with error if ODBC headers were not found
+if test ${ac_cv_header_sql_h} = no ||
+   test ${ac_cv_header_sqlext_h} = no; then
+   AC_MSG_ERROR([
+Found ODBC driver manager library ($ac_cv_search_SQLTables),
+but not required ODBC headers sql.h and sqlext.h.
+(Need -devel version of ODBC driver manager?)
+])
 fi

+
 dnl for 64-bit ODBC need SQL[U]LEN, and it is unclear where they are defined.
 AC_CHECK_TYPES([SQLLEN, SQLULEN], , , [# include sql.h])
 dnl for unixODBC header

__
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] Getting a list of unique gene names from a list with semi-colons

2012-01-06 Thread Kurinji Pandiyan
Hello,

I have one column in my dataframe that has gene names of interest.
Unfortunately, due to the fact that some probes lie between two genes or
two transcripts of a gene, it looks something like this -

  FAM81A  LOC283050;LOC283050;LOC283050;ZMIZ1  PINK1;PINK1  MRPL12;MRPL12
C1orf114  MMS19;UBTD1
I would like to know how to get a list with all the names with no
semi-colons and removing the replicates. I would like the end result to
look like -

FAM81A
LOC283050
ZMIZI
PINK1
MRPL12
C1orf114
MMS19
UBTD1

Thanks a lot for your help!
Kurinji

[[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] Getting a list of unique gene names from a list with semi-colons

2012-01-06 Thread R. Michael Weylandt michael.weyla...@gmail.com
I think you can do this with something like this (untested):

unique(unlist(strsplit(XXX, ,)))

Michael

On Jan 6, 2012, at 8:05 PM, Kurinji Pandiyan kurinji.pandi...@gmail.com wrote:

 Hello,
 
 I have one column in my dataframe that has gene names of interest.
 Unfortunately, due to the fact that some probes lie between two genes or
 two transcripts of a gene, it looks something like this -
 
  FAM81A  LOC283050;LOC283050;LOC283050;ZMIZ1  PINK1;PINK1  MRPL12;MRPL12
 C1orf114  MMS19;UBTD1
 I would like to know how to get a list with all the names with no
 semi-colons and removing the replicates. I would like the end result to
 look like -
 
 FAM81A
 LOC283050
 ZMIZI
 PINK1
 MRPL12
 C1orf114
 MMS19
 UBTD1
 
 Thanks a lot for your help!
 Kurinji
 
[[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] Getting a list of unique gene names from a list with semi-colons

2012-01-06 Thread Gabor Grothendieck
On Fri, Jan 6, 2012 at 9:05 PM, Kurinji Pandiyan
kurinji.pandi...@gmail.com wrote:
 Hello,

 I have one column in my dataframe that has gene names of interest.
 Unfortunately, due to the fact that some probes lie between two genes or
 two transcripts of a gene, it looks something like this -

  FAM81A  LOC283050;LOC283050;LOC283050;ZMIZ1  PINK1;PINK1  MRPL12;MRPL12
 C1orf114  MMS19;UBTD1
 I would like to know how to get a list with all the names with no
 semi-colons and removing the replicates. I would like the end result to
 look like -

 FAM81A
 LOC283050
 ZMIZI
 PINK1
 MRPL12
 C1orf114
 MMS19
 UBTD1

 Thanks a lot for your help!
 Kurinji


This uses strapply in gsubfn:

x - FAM81A  LOC283050;LOC283050;LOC283050;ZMIZ1  PINK1;PINK1
library(gsubfn)
unique(strapply(x, \\w+, c)[[1]])

If x is very long then there is a high speed version of strapply
specialized to using c called strapplyc in the development version of
gsubfn. For example, see this example of extracting 275,000 words from
a novel:

https://groups.google.com/group/corpling-with-r/msg/b85f7ff917cccb5d?dmode=sourceoutput=gplainnoredirectpli=1





-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] Getting a list of unique gene names from a list with semi-colons

2012-01-06 Thread R. Michael Weylandt michael.weyla...@gmail.com
Sorry. - that should be a semi-colon below. 

Michael Weylandt

On Jan 6, 2012, at 8:17 PM, R. Michael Weylandt michael.weyla...@gmail.com 
michael.weyla...@gmail.com wrote:

 I think you can do this with something like this (untested):
 
 unique(unlist(strsplit(XXX, ,)))
 
 Michael
 
 On Jan 6, 2012, at 8:05 PM, Kurinji Pandiyan kurinji.pandi...@gmail.com 
 wrote:
 
 Hello,
 
 I have one column in my dataframe that has gene names of interest.
 Unfortunately, due to the fact that some probes lie between two genes or
 two transcripts of a gene, it looks something like this -
 
 FAM81A  LOC283050;LOC283050;LOC283050;ZMIZ1  PINK1;PINK1  MRPL12;MRPL12
 C1orf114  MMS19;UBTD1
 I would like to know how to get a list with all the names with no
 semi-colons and removing the replicates. I would like the end result to
 look like -
 
 FAM81A
 LOC283050
 ZMIZI
 PINK1
 MRPL12
 C1orf114
 MMS19
 UBTD1
 
 Thanks a lot for your help!
 Kurinji
 
   [[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] Please help!! How do I set graphical parameters for ploting ctree()

2012-01-06 Thread David Winsemius


On Jan 6, 2012, at 6:09 PM, Chris Conner wrote:

I'm trying to understand how to set graphical parameters for trees  
created with the party package.  For example take the following code:


library(party)
data(airquality)
airq - subset(airquality, !is.na(Ozone))
airct - ctree(Ozone ~ ., data = airq,
   controls = ctree_control(maxsurrogate = 3))
plot(airct)

My problem is, I've got a ctree that has 14 terminal nodes, and as a  
result of the default graphical paramters of plot(ctree), all of the  
text is completely undreadable (decison node text is too large and  
as a result, these nodes overlap one another, terminal node barplot  
text overlaps hideously).  What I would like to do is learn how to  
customize the elements of these plots.  For the text, I have tried  
par(cex=.4, cex.main=.4, cex.axis=.2, cex.lab=.2)... to no avail.   
As far as reducing the size of the node ovals, I'm completely lost  
there...


After looking at:

party:::plot.BinaryTree and
party:::node_inner

... I've decided that you cannot. Neither of those function appear to  
accept parameters for shrinking the text. You could of course modify  
the code but if you couldn't find this answer on your own, then I have  
doubts that you possess the skills. So what are you to do? My  
suggestion would be to make a bigger plot on a vector graphics device  
(ps, pdf) and then shrink it.


--

David Winsemius, MD
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] Putting an index explicitly into function code --- a curiosity.

2012-01-06 Thread Rolf Turner


I want to create a list of functions in a for loop, with the index
of the loop appearing explicitly in the function code.

After quite a bit of thrashing around I figured out how to do it.

Here is a toy example:

junk - vector(list,4)
for(i in 1:4) {
itmp - i
junk[[i]] - eval(bquote(function(x){42 + .(itmp)*x}))
}

So I'm *basically* happy, but there's something I don't understand:
Why do I need itmp?

That is, if I do

junk - vector(list,4)
for(i in 1:4) {
junk[[i]] - eval(bquote(function(x){42 + .(i)*x}))
}

then every entry of junk is equal to

function (x)
{
42 + 4L * x
}

i.e. I seem to get the *last* value of the index always substituted, 
rather than
the current value.  Something (subtle?) is going on that I don't 
understand.

And than makes me feel not quite comfy.  Can anyone enlighten me?

Ta.

cheers,

Rolf Turner

P. S.  Also:  Is there a *better* way of accomplishing my objective than 
what I came up with?


R. T.

__
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] Putting an index explicitly into function code --- a curiosity.

2012-01-06 Thread R. Michael Weylandt michael.weyla...@gmail.com
I imagine the answer will involve lazy evaluation and require you use force() 
but I'm not quite qualified to pronounce and not at a computer to test. 

Michael

On Jan 6, 2012, at 8:43 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote:

 
 I want to create a list of functions in a for loop, with the index
 of the loop appearing explicitly in the function code.
 
 After quite a bit of thrashing around I figured out how to do it.
 
 Here is a toy example:
 
 junk - vector(list,4)
 for(i in 1:4) {
itmp - i
junk[[i]] - eval(bquote(function(x){42 + .(itmp)*x}))
 }
 
 So I'm *basically* happy, but there's something I don't understand:
 Why do I need itmp?
 
 That is, if I do
 
 junk - vector(list,4)
 for(i in 1:4) {
junk[[i]] - eval(bquote(function(x){42 + .(i)*x}))
 }
 
 then every entry of junk is equal to
 
 function (x)
 {
42 + 4L * x
 }
 
 i.e. I seem to get the *last* value of the index always substituted, rather 
 than
 the current value.  Something (subtle?) is going on that I don't understand.
 And than makes me feel not quite comfy.  Can anyone enlighten me?
 
 Ta.
 
cheers,
 
Rolf Turner
 
 P. S.  Also:  Is there a *better* way of accomplishing my objective than what 
 I came up with?
 
R. T.
 
 __
 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] Putting an index explicitly into function code --- a curiosity.

2012-01-06 Thread David Winsemius


On Jan 6, 2012, at 9:51 PM, R. Michael Weylandt michael.weyla...@gmail.com 
 wrote:


I imagine the answer will involve lazy evaluation and require you  
use force() but I'm not quite qualified to pronounce and not at a  
computer to test.


Your theory passes the experimental test:

for(i in 1:4) {force(i)
junk[[i]] - eval(bquote(function(x){42 + .(i)*x}))}
 junk


--
David.


Michael

On Jan 6, 2012, at 8:43 PM, Rolf Turner rolf.tur...@xtra.co.nz  
wrote:




I want to create a list of functions in a for loop, with the index
of the loop appearing explicitly in the function code.

After quite a bit of thrashing around I figured out how to do it.

Here is a toy example:

junk - vector(list,4)
for(i in 1:4) {
  itmp - i
  junk[[i]] - eval(bquote(function(x){42 + .(itmp)*x}))
}

So I'm *basically* happy, but there's something I don't understand:
Why do I need itmp?

That is, if I do

junk - vector(list,4)
for(i in 1:4) {
  junk[[i]] - eval(bquote(function(x){42 + .(i)*x}))
}

then every entry of junk is equal to

function (x)
{
  42 + 4L * x
}

i.e. I seem to get the *last* value of the index always  
substituted, rather than
the current value.  Something (subtle?) is going on that I don't  
understand.

And than makes me feel not quite comfy.  Can anyone enlighten me?

Ta.

  cheers,

  Rolf Turner

P. S.  Also:  Is there a *better* way of accomplishing my objective  
than what I came up with?


  R. T.

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


David Winsemius, MD
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] Putting an index explicitly into function code --- a curiosity.

2012-01-06 Thread Rolf Turner

On 07/01/12 15:51, R. Michael Weylandt michael.weyla...@gmail.com wrote:

I imagine the answer will involve lazy evaluation and require you use force() 
but I'm not quite qualified to pronounce and not at a computer to test.


I think you've got it;  I tried

junk - vector(list,4)
for(i in 1:4) {
   junk[[i]] - eval(bquote(function(x){42 + .(force(i))*x}))
}

and got the result that I wanted.  Still don't completely understand, but
it at least makes vague sense and makes me a bit more comfy.

Thanks.

cheers,

Rolf

__
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] Putting an index explicitly into function code --- a curiosity.

2012-01-06 Thread Gabor Grothendieck
On Fri, Jan 6, 2012 at 9:43 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote:

 I want to create a list of functions in a for loop, with the index
 of the loop appearing explicitly in the function code.

 After quite a bit of thrashing around I figured out how to do it.

 Here is a toy example:

 junk - vector(list,4)
 for(i in 1:4) {
    itmp - i
    junk[[i]] - eval(bquote(function(x){42 + .(itmp)*x}))
 }

 So I'm *basically* happy, but there's something I don't understand:
 Why do I need itmp?

 That is, if I do

 junk - vector(list,4)
 for(i in 1:4) {
    junk[[i]] - eval(bquote(function(x){42 + .(i)*x}))
 }

 then every entry of junk is equal to

 function (x)
 {
    42 + 4L * x
 }

 i.e. I seem to get the *last* value of the index always substituted, rather
 than
 the current value.  Something (subtle?) is going on that I don't
 understand.
 And than makes me feel not quite comfy.  Can anyone enlighten me?

This seems quite strange.  For example, if we replace the for with a
while then we don't need to force i:

junk - vector(list,4)
i - 1
while(i = 4) {
   junk[[i]] - eval(bquote(function(x){42 + .(i)*x}))
   i - i + 1
}
junk

I am using:
 R.version.string
[1] R version 2.14.1 Patched (2011-12-26 r58001)
 win.version()
[1] Windows Vista (build 6002) Service Pack 2


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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] Putting an index explicitly into function code --- a curiosity.

2012-01-06 Thread R. Michael Weylandt
Presumably because the i = 4 has to be re-evaluated at the start of
each iteration of the while-loop which implicitly force()s it?

Though, I don't know if it might not be a bad idea to put an implicit
force() in the internal code for `for` to prevent these sorts of
things. I can't immediately think of a scenario where this sort of
behavior would be useful. It might also simplify the internals to pass
a value rather than what I presume is actually a promise (but I
haven't looked yet and I'm still not in a position to verify)

Are there scenarios where this sort of behavior is preferable for a
loop (I understand the pros of lazy evaluation in general)

Michael

On Fri, Jan 6, 2012 at 9:46 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 On Fri, Jan 6, 2012 at 9:43 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote:

 I want to create a list of functions in a for loop, with the index
 of the loop appearing explicitly in the function code.

 After quite a bit of thrashing around I figured out how to do it.

 Here is a toy example:

 junk - vector(list,4)
 for(i in 1:4) {
    itmp - i
    junk[[i]] - eval(bquote(function(x){42 + .(itmp)*x}))
 }

 So I'm *basically* happy, but there's something I don't understand:
 Why do I need itmp?

 That is, if I do

 junk - vector(list,4)
 for(i in 1:4) {
    junk[[i]] - eval(bquote(function(x){42 + .(i)*x}))
 }

 then every entry of junk is equal to

 function (x)
 {
    42 + 4L * x
 }

 i.e. I seem to get the *last* value of the index always substituted, rather
 than
 the current value.  Something (subtle?) is going on that I don't
 understand.
 And than makes me feel not quite comfy.  Can anyone enlighten me?

 This seems quite strange.  For example, if we replace the for with a
 while then we don't need to force i:

 junk - vector(list,4)
 i - 1
 while(i = 4) {
   junk[[i]] - eval(bquote(function(x){42 + .(i)*x}))
   i - i + 1
 }
 junk

 I am using:
 R.version.string
 [1] R version 2.14.1 Patched (2011-12-26 r58001)
 win.version()
 [1] Windows Vista (build 6002) Service Pack 2


 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at 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] Putting an index explicitly into function code --- a curiosity.

2012-01-06 Thread Gabor Grothendieck
On Fri, Jan 6, 2012 at 11:13 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 Presumably because the i = 4 has to be re-evaluated at the start of
 each iteration of the while-loop which implicitly force()s it?

 Though, I don't know if it might not be a bad idea to put an implicit
 force() in the internal code for `for` to prevent these sorts of
 things. I can't immediately think of a scenario where this sort of
 behavior would be useful. It might also simplify the internals to pass
 a value rather than what I presume is actually a promise (but I
 haven't looked yet and I'm still not in a position to verify)

It does not appear to be a promise.  Using a C routine that returns
TRUE for a promise and FALSE otherwise:

 # test ispromise

 # is a promise
 delayedAssign(a, x+1)
 .Call(ispromise, a, .GlobalEnv)
[1] TRUE

 # not a promise
 xx - 3
 .Call(ispromise, xx, .GlobalEnv)
[1] FALSE

 # seems index of for is not a promise
 #
 for(i in 1:3) print(.Call(ispromise, i, .GlobalEnv))
[1] FALSE
[1] FALSE
[1] FALSE


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at 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.