Re: [R] read.csv.sql() to select from a large csv file

2012-12-01 Thread Gabor Grothendieck
On Fri, Nov 23, 2012 at 5:05 PM, Juliane Struve
juliane_str...@yahoo.co.uk wrote:
 Rui, Anthony, and Gabor,

 I got this to work in the end:

 for(i in length(Names_EastCoast){
 name - Names_EastCoast[i]
 sql - paste(select * from file where ID =
 ',name,',sep = )
 Data - read.csv.sql(filename,sql = sql)
 }

 loops through all individuals in the csv file.

That sets i to the length of Names_EastCoast and then runs the query only once.

I think you want:

for(nam in Names_EastCoast) {
   Data - fn$read.csv.sql(filename,
   sql = 'select * from file where ID = $nam ')
   # ... process Data ...
}


-- 
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] qbinom

2012-12-01 Thread peter dalgaard

On Dec 1, 2012, at 01:00 , David Winsemius wrote:

 
 On Nov 30, 2012, at 1:05 PM, jaybell wrote:
 
 sorry, I repost the question again  
 
 Why? This was already answered.
 
 
 a=c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9) 
 b=c(0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1) 
 cor(a,b)= -1 
 
 pa=qbinom(a, 1, 0.5) 
 pb=qbinom(b, 1, 0.5) 
 cor(pa,pb)=-0.8
 
 but when  
 pa=qbinom(a,10,0.5)
 pb=qbinom(b,10,0.5)
 
 cor(pa,pb) becomes -1 again
 
 What part of plot the values was difficult to understand?

(Actually, list the values might be more informative in this case:

 pa
[1] 0 0 0 0 0 1 1 1 1
 pb
[1] 1 1 1 1 0 0 0 0 0

Notice that pb != 1-pa when size=1.)

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


Re: [R] segfault debugging

2012-12-01 Thread Donatella Quagli
Thank you so far. Here is an excerpt from the gdb session after a crash:
  Program received signal SIGSEGV, Segmentation fault.

  0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
  (gdb) backtrace
  #0  0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
  #1  0xb744b64c in ?? () from /usr/lib/R/lib/libR.so
  #2  0xb74c58bf in ?? () from /usr/lib/R/lib/libR.so
  #3  0xb74c9c62 in Rf_eval () from /usr/lib/R/lib/libR.so
  #4  0xb74ce60f in Rf_applyClosure () from /usr/lib/R/lib/libR.so
  #5  0xb74c9f29 in Rf_eval () from /usr/lib/R/lib/libR.so
  #6  0xb7503002 in Rf_ReplIteration () from /usr/lib/R/lib/libR.so
  #7  0xb7503298 in ?? () from /usr/lib/R/lib/libR.so
  #8  0xb7503812 in run_Rmainloop () from /usr/lib/R/lib/libR.so
  #9  0xb7503839 in Rf_mainloop () from /usr/lib/R/lib/libR.so
  #10 0x08048768 in main ()
  #11 0xb728de46 in __libc_start_main (main=0x8048730 main, argc=8, 
ubp_av=0xbfdb7824, init=0x80488a0 __libc_csu_init, 
      fini=0x8048890 __libc_csu_fini, rtld_fini=0xb7784590, 
stack_end=0xbfdb781c) at libc-start.c:228
  #12 0x08048791 in _start ()

It seems to me that the error is in frame #0. Does it mean that there is a bug 
in libR.so?  What can I do next?

Greetings
Donatella

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 all possible contingency tables

2012-12-01 Thread Christofer Bogaso

Hello all,

Let say I have 2-way contingency table:

Tab - matrix(c(8, 10, 12, 6), nr = 2)

and the Chi-squared test could not reject the independence:

 chisq.test(Tab)

Pearson's Chi-squared test with Yates' continuity correction

data:  Tab
X-squared = 1.0125, df = 1, p-value = 0.3143


However I want to get all possible contingency tables under this 
independence scenario (one of them would obviously be the given table 
as, we could not reject the independence), and for each such table I 
want to calculate the Ch-sq statistic.


Can somebody help me how to generate all such tables?

Thanks and regards,

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] segfault debugging

2012-12-01 Thread Duncan Murdoch

On 12-12-01 6:56 AM, Donatella Quagli wrote:

Thank you so far. Here is an excerpt from the gdb session after a crash:
   Program received signal SIGSEGV, Segmentation fault.

   0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
   (gdb) backtrace
   #0  0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
   #1  0xb744b64c in ?? () from /usr/lib/R/lib/libR.so
   #2  0xb74c58bf in ?? () from /usr/lib/R/lib/libR.so
   #3  0xb74c9c62 in Rf_eval () from /usr/lib/R/lib/libR.so
   #4  0xb74ce60f in Rf_applyClosure () from /usr/lib/R/lib/libR.so
   #5  0xb74c9f29 in Rf_eval () from /usr/lib/R/lib/libR.so
   #6  0xb7503002 in Rf_ReplIteration () from /usr/lib/R/lib/libR.so
   #7  0xb7503298 in ?? () from /usr/lib/R/lib/libR.so
   #8  0xb7503812 in run_Rmainloop () from /usr/lib/R/lib/libR.so
   #9  0xb7503839 in Rf_mainloop () from /usr/lib/R/lib/libR.so
   #10 0x08048768 in main ()
   #11 0xb728de46 in __libc_start_main (main=0x8048730 main, argc=8, 
ubp_av=0xbfdb7824, init=0x80488a0 __libc_csu_init,
   fini=0x8048890 __libc_csu_fini, rtld_fini=0xb7784590, 
stack_end=0xbfdb781c) at libc-start.c:228
   #12 0x08048791 in _start ()

It seems to me that the error is in frame #0. Does it mean that there is a bug 
in libR.so?  What can I do next?


It means that the error was detected when trying to do a memory 
allocation.  That could be a bug in R, but more likely something else 
has damaged the memory management system structures, e.g. a function 
writing to memory that it doesn't own.


Bugs like this are hard to track down, because the damage could have 
occurred a long time before it showed up, and small changes to your 
script could affect it.


I would try to narrow it down to a single statement in your script.  You 
might be able to deduce that from the last line printed before the 
crash.  If you don't have any printing, you could try adding some, but 
as I mentioned above, that might make the bug behave differently.


Another approach is to cut off statements at the end of your script. 
That probably won't affect the bug until you cut off the statement that 
actually triggered it (but it might, which is why this kind of bug is so 
frustrating to track down).


If you find the bad statement, then look at calls to external code in 
it, or recently executed before it.  See if any of them look like they 
contain errors.  Common errors are to write to an array without 
allocating it, or to write beyond the bounds of an array, or (in .Call() 
code) to allocate something and then fail to protect it from garbage 
collection.


You could also figure out what the problem is that caused the seg fault 
in frame 0.  It might be because some particular variable contains a 
garbage value.  Then in a new run, you can ask gdb to break when that 
memory location takes on the garbage value.  This is usually effective 
if you really can identify the bad value, but doing that can be hard, 
especially when you aren't familiar with how things normally work.


Good luck!

Duncan Murdoch

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


Re: [R] Getting all possible contingency tables

2012-12-01 Thread John Kane
Are you basically asking for all possible permutations of the table?  If so see 
?permn in the combinat package.

John Kane
Kingston ON Canada


 -Original Message-
 From: bogaso.christo...@gmail.com
 Sent: Sat, 01 Dec 2012 18:10:15 +0545
 To: r-help@r-project.org
 Subject: [R] Getting all possible contingency tables
 
 Hello all,
 
 Let say I have 2-way contingency table:
 
 Tab - matrix(c(8, 10, 12, 6), nr = 2)
 
 and the Chi-squared test could not reject the independence:
 
   chisq.test(Tab)
 
  Pearson's Chi-squared test with Yates' continuity correction
 
 data:  Tab
 X-squared = 1.0125, df = 1, p-value = 0.3143
 
 
 However I want to get all possible contingency tables under this
 independence scenario (one of them would obviously be the given table
 as, we could not reject the independence), and for each such table I
 want to calculate the Ch-sq statistic.
 
 Can somebody help me how to generate all such tables?
 
 Thanks and regards,
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cubic spline

2012-12-01 Thread Steve Stephenson
Hallo,
I'm facing a problem and I would really appreciate your support.
I have to translate some Matalb code in R that I don't know very well but I
would like to.
I have to interpolate 5 point with a cubic spline function and then I expect
my function returns the Y value as output a specific X value inside the
evaluation range.  Let's suppose that:
  1-  *X = [-10, -5, 0, 5, 10]* 
  2 - *Y = [12, 10, 8, 7, 6]*
  3 - *I have to interpolate with a cubic spline assuming x=11*

In Matlab I used this function:

*y = interp1(X, Y, x, cubic); *

How can I do the same in R? 
Many thanks in advance for your reply and support!
Kindly

Steve




--
View this message in context: 
http://r.789695.n4.nabble.com/cubic-spline-tp4651537.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] How to built a pivot table of value

2012-12-01 Thread CE.KA
Hi R users

Imagine the table base:
p=c(d,d,b,b,a,a)
q=c(v1,v2,v1,v2,v1,v2)
r=c(5,2,4,8,9,7)
base=data.frame(p,q,r)
base

 p   q r
1  d   v1   5
2  d   v2   2
3  b   v1  4
4  b   v2   8
5  a   v1   9
6  a   v2   7

How programming R to get this result:

 v1   v2
a  97
b 48
d 52

I tried the function table but the result is divided in several matrix:
table(base$p,base$q,base$r)
, ,  = 2

   
v1 v2
  a  0  0
  b  0  0
  d  0  1

, ,  = 4

   
v1 v2
  a  0  0
  b  1  0
  d  0  0

, ,  = 5

   
v1 v2
  a  0  0
  b  0  0
  d  1  0

, ,  = 7

   
v1 v2
  a  0  1
  b  0  0
  d  0  0

, ,  = 8

   
v1 v2
  a  0  0
  b  0  1
  d  0  0

, ,  = 9

   
v1 v2
  a  1  0
  b  0  0
  d  0  0

SIncerely yours



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-built-a-pivot-table-of-value-tp4651539.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] cubic spline

2012-12-01 Thread Jorge I Velez
Hi Steve,

Check the splint function in the fields package.

HTH,
Jorge.-


On Sat, Dec 1, 2012 at 11:09 PM, Steve Stephenson  wrote:

 Hallo,
 I'm facing a problem and I would really appreciate your support.
 I have to translate some Matalb code in R that I don't know very well but I
 would like to.
 I have to interpolate 5 point with a cubic spline function and then I
 expect
 my function returns the Y value as output a specific X value inside the
 evaluation range.  Let's suppose that:
   1-  *X = [-10, -5, 0, 5, 10]*
   2 - *Y = [12, 10, 8, 7, 6]*
   3 - *I have to interpolate with a cubic spline assuming x=11*

 In Matlab I used this function:

 *y = interp1(X, Y, x, cubic); *

 How can I do the same in R?
 Many thanks in advance for your reply and support!
 Kindly

 Steve




 --
 View this message in context:
 http://r.789695.n4.nabble.com/cubic-spline-tp4651537.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] How to built a pivot table of value

2012-12-01 Thread Jorge I Velez
Hi,

One way could be

with(base, tapply(r, list(p, q), sum))

HTH,
Jorge.-


On Sat, Dec 1, 2012 at 11:37 PM, CE.KA  wrote:

 Hi R users

 Imagine the table base:
 p=c(d,d,b,b,a,a)
 q=c(v1,v2,v1,v2,v1,v2)
 r=c(5,2,4,8,9,7)
 base=data.frame(p,q,r)
 base

  p   q r
 1  d   v1   5
 2  d   v2   2
 3  b   v1  4
 4  b   v2   8
 5  a   v1   9
 6  a   v2   7

 How programming R to get this result:

  v1   v2
 a  97
 b 48
 d 52

 I tried the function table but the result is divided in several matrix:
 table(base$p,base$q,base$r)
 , ,  = 2


 v1 v2
   a  0  0
   b  0  0
   d  0  1

 , ,  = 4


 v1 v2
   a  0  0
   b  1  0
   d  0  0

 , ,  = 5


 v1 v2
   a  0  0
   b  0  0
   d  1  0

 , ,  = 7


 v1 v2
   a  0  1
   b  0  0
   d  0  0

 , ,  = 8


 v1 v2
   a  0  0
   b  0  1
   d  0  0

 , ,  = 9


 v1 v2
   a  1  0
   b  0  0
   d  0  0

 SIncerely yours



 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-built-a-pivot-table-of-value-tp4651539.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] Getting all possible contingency tables

2012-12-01 Thread Christofer Bogaso

Thanks John for your reply. However still not clear how I should proceed.

My goal is to generate all possible contingency tables. Basically I want 
to see the distribution of Chi-squared Statistic under independence (NULL).


So I was thinking if I can generate all possible permutation of integer 
numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is there any R 
function to do that?


Thanks and regards,


On 01-12-2012 18:39, John Kane wrote:

Are you basically asking for all possible permutations of the table?  If so see 
?permn in the combinat package.

John Kane
Kingston ON Canada



-Original Message-
From: bogaso.christo...@gmail.com
Sent: Sat, 01 Dec 2012 18:10:15 +0545
To: r-help@r-project.org
Subject: [R] Getting all possible contingency tables

Hello all,

Let say I have 2-way contingency table:

Tab - matrix(c(8, 10, 12, 6), nr = 2)

and the Chi-squared test could not reject the independence:

   chisq.test(Tab)

  Pearson's Chi-squared test with Yates' continuity correction

data:  Tab
X-squared = 1.0125, df = 1, p-value = 0.3143


However I want to get all possible contingency tables under this
independence scenario (one of them would obviously be the given table
as, we could not reject the independence), and for each such table I
want to calculate the Ch-sq statistic.

Can somebody help me how to generate all such tables?

Thanks and regards,

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


FREE ONLINE PHOTOSHARING - Share your photos online with your friends and 
family!
Visit http://www.inbox.com/photosharing to find out more!





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 built a pivot table of value

2012-12-01 Thread Berend Hasselman

On 01-12-2012, at 13:37, CE.KA wrote:

 Hi R users
 
 Imagine the table base:
 p=c(d,d,b,b,a,a)
 q=c(v1,v2,v1,v2,v1,v2)
 r=c(5,2,4,8,9,7)
 base=data.frame(p,q,r)
 base
 
 p   q r
 1  d   v1   5
 2  d   v2   2
 3  b   v1  4
 4  b   v2   8
 5  a   v1   9
 6  a   v2   7
 
 How programming R to get this result:
 
 v1   v2
 a  97
 b 48
 d 52
 

xtabs(r~p+q,data=base)

Output
-
   q
p   v1 v2
  a  9  7
  b  4  8
  d  5  2

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 built a pivot table of value

2012-12-01 Thread John Kane
One way, using the plyr package would be:

  library(plyr)
  dcast(base, p ~  q)

John Kane
Kingston ON Canada


 -Original Message-
 From: ce.kay...@yahoo.fr
 Sent: Sat, 1 Dec 2012 04:37:02 -0800 (PST)
 To: r-help@r-project.org
 Subject: [R] How to built a pivot table of value
 
 Hi R users
 
 Imagine the table base:
 p=c(d,d,b,b,a,a)
 q=c(v1,v2,v1,v2,v1,v2)
 r=c(5,2,4,8,9,7)
 base=data.frame(p,q,r)
 base
 
  p   q r
 1  d   v1   5
 2  d   v2   2
 3  b   v1  4
 4  b   v2   8
 5  a   v1   9
 6  a   v2   7
 
 How programming R to get this result:
 
  v1   v2
 a  97
 b 48
 d 52
 
 I tried the function table but the result is divided in several matrix:
 table(base$p,base$q,base$r)
 , ,  = 2
 
 
 v1 v2
   a  0  0
   b  0  0
   d  0  1
 
 , ,  = 4
 
 
 v1 v2
   a  0  0
   b  1  0
   d  0  0
 
 , ,  = 5
 
 
 v1 v2
   a  0  0
   b  0  0
   d  1  0
 
 , ,  = 7
 
 
 v1 v2
   a  0  1
   b  0  0
   d  0  0
 
 , ,  = 8
 
 
 v1 v2
   a  0  0
   b  0  1
   d  0  0
 
 , ,  = 9
 
 
 v1 v2
   a  1  0
   b  0  0
   d  0  0
 
 SIncerely yours
 
 
 
 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-built-a-pivot-table-of-value-tp4651539.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.


GET FREE SMILEYS FOR YOUR IM  EMAIL - Learn more at 
http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most 
webmails

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 all possible contingency tables

2012-12-01 Thread John Kane
R can usually do almost anything but if the function exists I am not aware of 
it.  Sorry. I did misunderstand what you were doing.

John Kane
Kingston ON Canada


 -Original Message-
 From: bogaso.christo...@gmail.com
 Sent: Sat, 01 Dec 2012 19:33:09 +0545
 To: jrkrid...@inbox.com
 Subject: Re: [R] Getting all possible contingency tables
 
 Thanks John for your reply. However still not clear how I should proceed.
 
 My goal is to generate all possible contingency tables. Basically I want
 to see the distribution of Chi-squared Statistic under independence
 (NULL).
 
 So I was thinking if I can generate all possible permutation of integer
 numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is there any R
 function to do that?
 
 Thanks and regards,
 
 
 On 01-12-2012 18:39, John Kane wrote:
 Are you basically asking for all possible permutations of the table?  If
 so see ?permn in the combinat package.
 
 John Kane
 Kingston ON Canada
 
 
 -Original Message-
 From: bogaso.christo...@gmail.com
 Sent: Sat, 01 Dec 2012 18:10:15 +0545
 To: r-help@r-project.org
 Subject: [R] Getting all possible contingency tables
 
 Hello all,
 
 Let say I have 2-way contingency table:
 
 Tab - matrix(c(8, 10, 12, 6), nr = 2)
 
 and the Chi-squared test could not reject the independence:
 
chisq.test(Tab)
 
   Pearson's Chi-squared test with Yates' continuity correction
 
 data:  Tab
 X-squared = 1.0125, df = 1, p-value = 0.3143
 
 
 However I want to get all possible contingency tables under this
 independence scenario (one of them would obviously be the given table
 as, we could not reject the independence), and for each such table I
 want to calculate the Ch-sq statistic.
 
 Can somebody help me how to generate all such tables?
 
 Thanks and regards,
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 FREE ONLINE PHOTOSHARING - Share your photos online with your friends
 and family!
 Visit http://www.inbox.com/photosharing to find out more!
 
 



FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 all possible contingency tables

2012-12-01 Thread Bert Gunter
Christopher:

Don't do this!

 If I understand you correctly, you want FIsher's exact test. This is
already available in R, using far smarter algorithms then you would. See:

?fisher.test

-- Bert

On Sat, Dec 1, 2012 at 5:48 AM, Christofer Bogaso 
bogaso.christo...@gmail.com wrote:

 Thanks John for your reply. However still not clear how I should proceed.

 My goal is to generate all possible contingency tables. Basically I want
 to see the distribution of Chi-squared Statistic under independence (NULL).

 So I was thinking if I can generate all possible permutation of integer
 numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is there any R function
 to do that?

 Thanks and regards,


 On 01-12-2012 18:39, John Kane wrote:

 Are you basically asking for all possible permutations of the table?  If
 so see ?permn in the combinat package.

 John Kane
 Kingston ON Canada


  -Original Message-
 From: bogaso.christo...@gmail.com
 Sent: Sat, 01 Dec 2012 18:10:15 +0545
 To: r-help@r-project.org
 Subject: [R] Getting all possible contingency tables

 Hello all,

 Let say I have 2-way contingency table:

 Tab - matrix(c(8, 10, 12, 6), nr = 2)

 and the Chi-squared test could not reject the independence:

chisq.test(Tab)

   Pearson's Chi-squared test with Yates' continuity correction

 data:  Tab
 X-squared = 1.0125, df = 1, p-value = 0.3143


 However I want to get all possible contingency tables under this
 independence scenario (one of them would obviously be the given table
 as, we could not reject the independence), and for each such table I
 want to calculate the Ch-sq statistic.

 Can somebody help me how to generate all such tables?

 Thanks and regards,

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

 __**__
 FREE ONLINE PHOTOSHARING - Share your photos online with your friends and
 family!
 Visit 
 http://www.inbox.com/**photosharinghttp://www.inbox.com/photosharingto 
 find out more!




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




-- 

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

[[alternative HTML version deleted]]

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


Re: [R] How to built a pivot table of value

2012-12-01 Thread Berend Hasselman

On 01-12-2012, at 14:56, John Kane wrote:

 One way, using the plyr package would be:
 
 library(plyr)
 dcast(base, p ~  q)
 

Shouldn't that be library(reshape2) ?

Berend

 John Kane
 Kingston ON Canada
 
 
 -Original Message-
 From: ce.kay...@yahoo.fr
 Sent: Sat, 1 Dec 2012 04:37:02 -0800 (PST)
 To: r-help@r-project.org
 Subject: [R] How to built a pivot table of value
 
 Hi R users
 
 Imagine the table base:
 p=c(d,d,b,b,a,a)
 q=c(v1,v2,v1,v2,v1,v2)
 r=c(5,2,4,8,9,7)
 base=data.frame(p,q,r)
 base
 
p   q r
 1  d   v1   5
 2  d   v2   2
 3  b   v1  4
 4  b   v2   8
 5  a   v1   9
 6  a   v2   7
 
 How programming R to get this result:
 
v1   v2
 a  97
 b 48
 d 52
 
 I tried the function table but the result is divided in several matrix:
 table(base$p,base$q,base$r)
 , ,  = 2
 
 
   v1 v2
 a  0  0
 b  0  0
 d  0  1
 
 , ,  = 4
 
 
   v1 v2
 a  0  0
 b  1  0
 d  0  0
 
 , ,  = 5
 
 
   v1 v2
 a  0  0
 b  0  0
 d  1  0
 
 , ,  = 7
 
 
   v1 v2
 a  0  1
 b  0  0
 d  0  0
 
 , ,  = 8
 
 
   v1 v2
 a  0  0
 b  0  1
 d  0  0
 
 , ,  = 9
 
 
   v1 v2
 a  1  0
 b  0  0
 d  0  0
 
 SIncerely yours
 
 
 
 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-built-a-pivot-table-of-value-tp4651539.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.
 
 
 GET FREE SMILEYS FOR YOUR IM  EMAIL - Learn more at 
 http://www.inbox.com/smileys
 Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and 
 most webmails
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 all possible contingency tables

2012-12-01 Thread Christofer Bogaso

Thanks Bert for your reply.

I am trying to understand/visualize the Sample Chi-Squared Statistic's 
Null distribution. Therefore I need all possible Contingency tables 
under Independence case.


What could be better way to visualize that?

Thanks and regards,

On 01 December 2012 20:03:00, Bert Gunter wrote:

Christopher:

Don't do this!

 If I understand you correctly, you want FIsher's exact test. This is
already available in R, using far smarter algorithms then you would. See:

?fisher.test

-- Bert

On Sat, Dec 1, 2012 at 5:48 AM, Christofer Bogaso
bogaso.christo...@gmail.com mailto:bogaso.christo...@gmail.com wrote:

Thanks John for your reply. However still not clear how I should
proceed.

My goal is to generate all possible contingency tables. Basically
I want to see the distribution of Chi-squared Statistic under
independence (NULL).

So I was thinking if I can generate all possible permutation of
integer numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is
there any R function to do that?

Thanks and regards,


On 01-12-2012 18:39, John Kane wrote:

Are you basically asking for all possible permutations of the
table?  If so see ?permn in the combinat package.

John Kane
Kingston ON Canada


-Original Message-
From: bogaso.christo...@gmail.com
mailto:bogaso.christo...@gmail.com
Sent: Sat, 01 Dec 2012 18:10:15 +0545
To: r-help@r-project.org mailto:r-help@r-project.org
Subject: [R] Getting all possible contingency tables

Hello all,

Let say I have 2-way contingency table:

Tab - matrix(c(8, 10, 12, 6), nr = 2)

and the Chi-squared test could not reject the independence:

   chisq.test(Tab)

  Pearson's Chi-squared test with Yates'
continuity correction

data:  Tab
X-squared = 1.0125, df = 1, p-value = 0.3143


However I want to get all possible contingency tables
under this
independence scenario (one of them would obviously be the
given table
as, we could not reject the independence), and for each
such table I
want to calculate the Ch-sq statistic.

Can somebody help me how to generate all such tables?

Thanks and regards,


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

__
FREE ONLINE PHOTOSHARING - Share your photos online with your
friends and family!
Visit http://www.inbox.com/__photosharing
http://www.inbox.com/photosharing to find out more!





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




--

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] segfault debugging

2012-12-01 Thread Martin Morgan

On 12/01/2012 04:51 AM, Duncan Murdoch wrote:

On 12-12-01 6:56 AM, Donatella Quagli wrote:

Thank you so far. Here is an excerpt from the gdb session after a crash:
   Program received signal SIGSEGV, Segmentation fault.

   0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
   (gdb) backtrace
   #0  0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
   #1  0xb744b64c in ?? () from /usr/lib/R/lib/libR.so
   #2  0xb74c58bf in ?? () from /usr/lib/R/lib/libR.so
   #3  0xb74c9c62 in Rf_eval () from /usr/lib/R/lib/libR.so
   #4  0xb74ce60f in Rf_applyClosure () from /usr/lib/R/lib/libR.so
   #5  0xb74c9f29 in Rf_eval () from /usr/lib/R/lib/libR.so
   #6  0xb7503002 in Rf_ReplIteration () from /usr/lib/R/lib/libR.so
   #7  0xb7503298 in ?? () from /usr/lib/R/lib/libR.so
   #8  0xb7503812 in run_Rmainloop () from /usr/lib/R/lib/libR.so
   #9  0xb7503839 in Rf_mainloop () from /usr/lib/R/lib/libR.so
   #10 0x08048768 in main ()
   #11 0xb728de46 in __libc_start_main (main=0x8048730 main, argc=8,
ubp_av=0xbfdb7824, init=0x80488a0 __libc_csu_init,
   fini=0x8048890 __libc_csu_fini, rtld_fini=0xb7784590,
stack_end=0xbfdb781c) at libc-start.c:228
   #12 0x08048791 in _start ()

It seems to me that the error is in frame #0. Does it mean that there is a bug
in libR.so?  What can I do next?


It means that the error was detected when trying to do a memory allocation.
That could be a bug in R, but more likely something else has damaged the memory
management system structures, e.g. a function writing to memory that it doesn't
own.

Bugs like this are hard to track down, because the damage could have occurred a
long time before it showed up, and small changes to your script could affect it.

I would try to narrow it down to a single statement in your script.  You might
be able to deduce that from the last line printed before the crash.  If you
don't have any printing, you could try adding some, but as I mentioned above,
that might make the bug behave differently.

Another approach is to cut off statements at the end of your script. That
probably won't affect the bug until you cut off the statement that actually
triggered it (but it might, which is why this kind of bug is so frustrating to
track down).

If you find the bad statement, then look at calls to external code in it, or
recently executed before it.  See if any of them look like they contain errors.
Common errors are to write to an array without allocating it, or to write beyond
the bounds of an array, or (in .Call() code) to allocate something and then fail
to protect it from garbage collection.

You could also figure out what the problem is that caused the seg fault in frame
0.  It might be because some particular variable contains a garbage value.  Then
in a new run, you can ask gdb to break when that memory location takes on the
garbage value.  This is usually effective if you really can identify the bad
value, but doing that can be hard, especially when you aren't familiar with how
things normally work.


valgrind is usually effective for this

  R -d valgrind -f myscript.R

but it requires an operating system where it is available (e.g., linux) and a 
quick (say less than 10's of seconds) way of reproducing the bug (because 
valgrind slows evaluation alot). So the first step is really to narrow down your 
large script to something that is easier to re-run., e.g., saving the important 
R objects to a file shortly before the problem section of your script, then 
reproducing the problem by loading those and evaluating a few steps of the code. 
The bug can still be intermittent; valgrind will likely spot the problem.


Martin



Good luck!

Duncan Murdoch

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



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

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

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


Re: [R] How to built a pivot table of value

2012-12-01 Thread John Kane
Blast, you're right. I tend to load both at the same time and confused the two. 
 It should be reshape2

John Kane
Kingston ON Canada


 -Original Message-
 From: b...@xs4all.nl
 Sent: Sat, 1 Dec 2012 15:20:13 +0100
 To: jrkrid...@inbox.com
 Subject: Re: [R] How to built a pivot table of value
 
 
 On 01-12-2012, at 14:56, John Kane wrote:
 
 One way, using the plyr package would be:
 
 library(plyr)
 dcast(base, p ~  q)
 
 
 Shouldn't that be library(reshape2) ?
 
 Berend
 
 John Kane
 Kingston ON Canada
 
 
 -Original Message-
 From: ce.kay...@yahoo.fr
 Sent: Sat, 1 Dec 2012 04:37:02 -0800 (PST)
 To: r-help@r-project.org
 Subject: [R] How to built a pivot table of value
 
 Hi R users
 
 Imagine the table base:
 p=c(d,d,b,b,a,a)
 q=c(v1,v2,v1,v2,v1,v2)
 r=c(5,2,4,8,9,7)
 base=data.frame(p,q,r)
 base
 
p   q r
 1  d   v1   5
 2  d   v2   2
 3  b   v1  4
 4  b   v2   8
 5  a   v1   9
 6  a   v2   7
 
 How programming R to get this result:
 
v1   v2
 a  97
 b 48
 d 52
 
 I tried the function table but the result is divided in several matrix:
 table(base$p,base$q,base$r)
 , ,  = 2
 
 
   v1 v2
 a  0  0
 b  0  0
 d  0  1
 
 , ,  = 4
 
 
   v1 v2
 a  0  0
 b  1  0
 d  0  0
 
 , ,  = 5
 
 
   v1 v2
 a  0  0
 b  0  0
 d  1  0
 
 , ,  = 7
 
 
   v1 v2
 a  0  1
 b  0  0
 d  0  0
 
 , ,  = 8
 
 
   v1 v2
 a  0  0
 b  0  1
 d  0  0
 
 , ,  = 9
 
 
   v1 v2
 a  1  0
 b  0  0
 d  0  0
 
 SIncerely yours
 
 
 
 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-built-a-pivot-table-of-value-tp4651539.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.
 
 
 GET FREE SMILEYS FOR YOUR IM  EMAIL - Learn more at
 http://www.inbox.com/smileys
 Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™
 and most webmails
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


GET FREE SMILEYS FOR YOUR IM  EMAIL - Learn more at 
http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most 
webmails

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cubic spline

2012-12-01 Thread Steve Stephenson
Hi Jorge,

many thanks for your suggestion!
I tried the function you mentioned and it looks working!!
Now I have just to check that splint (R) and interp1 (Matlab) functions
provide me the same results.
Kind regards!

Steve

 



--
View this message in context: 
http://r.789695.n4.nabble.com/cubic-spline-tp4651537p4651555.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] Getting all possible contingency tables

2012-12-01 Thread Ted Harding
You will need to be clear about whether you are conditioning on
the marginal totals as well as on the overall total. As stated,
you are only asking for the overall total (36) to be fixed.

In that case, one possible (and by no means unique) approach
would be to:

[A]: Choose any four random integers a,b,c,d that add up to 36
(even there, you still have to make a choice about what distribution
to adopt for the random integers).
[B]: Place the results into the 2x2 matrix; then evaluate chi-squared.
[C]: Repeat until you have enough cases.

Example (using equiprobable multinomial to generate 4 random integers)

  Tab - matrix(rmultinom(1,36,c(1,1,1,1)/4), nrow=2)

A more specific choice would be to fix the row and column probablilties
(but not the sample row and column totals), e.g.:

  P.row1 - 0.25 ; P.row2 - 1 - P.row1
  P.col1 - 0.50 ; P.col2 - 1 - P.col1

Then, adopting the hypothesis of independence between rows and columns:

  P11 - P.row1*P.col1
  P21 - P.row2*P.col1
  P12 - P.row1*P.col2
  P22 - P.row2*P.col2

  Tab - matrix(rmultinom(1,36,c(P11,P21,P12,P22)), nrow=2)

On the other hand, if you want to also fix the sample row margins
and column margins, then your sampled table needs to be generated
using a hypergeometric distribution, (which is the basis of the
fisher.test mentioned by Bert Gunter). Since explaining how to
do this is a bit mjore complicated than the above, please first
confirm what constraints (e.g. only total count; row-margins
only; col-margins only; both row-  col-margins) you wich to impose.

Hoping this helps,
Ted.

On 01-Dec-2012 14:28:24 Christofer Bogaso wrote:
 Thanks Bert for your reply.
 
 I am trying to understand/visualize the Sample Chi-Squared Statistic's 
 Null distribution. Therefore I need all possible Contingency tables 
 under Independence case.
 
 What could be better way to visualize that?
 
 Thanks and regards,
 
 On 01 December 2012 20:03:00, Bert Gunter wrote:
 Christopher:

 Don't do this!

  If I understand you correctly, you want FIsher's exact test. This is
 already available in R, using far smarter algorithms then you would. See:

 ?fisher.test

 -- Bert

 On Sat, Dec 1, 2012 at 5:48 AM, Christofer Bogaso
 bogaso.christo...@gmail.com mailto:bogaso.christo...@gmail.com wrote:

 Thanks John for your reply. However still not clear how I should
 proceed.

 My goal is to generate all possible contingency tables. Basically
 I want to see the distribution of Chi-squared Statistic under
 independence (NULL).

 So I was thinking if I can generate all possible permutation of
 integer numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is
 there any R function to do that?

 Thanks and regards,


 On 01-12-2012 18:39, John Kane wrote:

 Are you basically asking for all possible permutations of the
 table?  If so see ?permn in the combinat package.

 John Kane
 Kingston ON Canada


 -Original Message-
 From: bogaso.christo...@gmail.com
 mailto:bogaso.christo...@gmail.com
 Sent: Sat, 01 Dec 2012 18:10:15 +0545
 To: r-help@r-project.org mailto:r-help@r-project.org
 Subject: [R] Getting all possible contingency tables

 Hello all,

 Let say I have 2-way contingency table:

 Tab - matrix(c(8, 10, 12, 6), nr = 2)

 and the Chi-squared test could not reject the independence:

chisq.test(Tab)

   Pearson's Chi-squared test with Yates'
 continuity correction

 data:  Tab
 X-squared = 1.0125, df = 1, p-value = 0.3143


 However I want to get all possible contingency tables
 under this
 independence scenario (one of them would obviously be the
 given table
 as, we could not reject the independence), and for each
 such table I
 want to calculate the Ch-sq statistic.

 Can somebody help me how to generate all such tables?

 Thanks and regards,

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 01-Dec-2012  Time: 16:00:16
This message was sent by XFMail

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] segfault debugging

2012-12-01 Thread William Dunlap
 valgrind is usually effective for this

   R -d valgrind -f myscript.R

And adding the R command
gctorture(TRUE)
to the top of your script lets valgrind do a better job of
find memory misuse.

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 Martin Morgan
 Sent: Saturday, December 01, 2012 6:54 AM
 To: Duncan Murdoch
 Cc: r-help@r-project.org; Donatella Quagli
 Subject: Re: [R] segfault debugging
 
 On 12/01/2012 04:51 AM, Duncan Murdoch wrote:
  On 12-12-01 6:56 AM, Donatella Quagli wrote:
  Thank you so far. Here is an excerpt from the gdb session after a crash:
 Program received signal SIGSEGV, Segmentation fault.
 
 0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
 (gdb) backtrace
 #0  0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
 #1  0xb744b64c in ?? () from /usr/lib/R/lib/libR.so
 #2  0xb74c58bf in ?? () from /usr/lib/R/lib/libR.so
 #3  0xb74c9c62 in Rf_eval () from /usr/lib/R/lib/libR.so
 #4  0xb74ce60f in Rf_applyClosure () from /usr/lib/R/lib/libR.so
 #5  0xb74c9f29 in Rf_eval () from /usr/lib/R/lib/libR.so
 #6  0xb7503002 in Rf_ReplIteration () from /usr/lib/R/lib/libR.so
 #7  0xb7503298 in ?? () from /usr/lib/R/lib/libR.so
 #8  0xb7503812 in run_Rmainloop () from /usr/lib/R/lib/libR.so
 #9  0xb7503839 in Rf_mainloop () from /usr/lib/R/lib/libR.so
 #10 0x08048768 in main ()
 #11 0xb728de46 in __libc_start_main (main=0x8048730 main, argc=8,
  ubp_av=0xbfdb7824, init=0x80488a0 __libc_csu_init,
 fini=0x8048890 __libc_csu_fini, rtld_fini=0xb7784590,
  stack_end=0xbfdb781c) at libc-start.c:228
 #12 0x08048791 in _start ()
 
  It seems to me that the error is in frame #0. Does it mean that there is a 
  bug
  in libR.so?  What can I do next?
 
  It means that the error was detected when trying to do a memory allocation.
  That could be a bug in R, but more likely something else has damaged the 
  memory
  management system structures, e.g. a function writing to memory that it 
  doesn't
  own.
 
  Bugs like this are hard to track down, because the damage could have 
  occurred a
  long time before it showed up, and small changes to your script could 
  affect it.
 
  I would try to narrow it down to a single statement in your script.  You 
  might
  be able to deduce that from the last line printed before the crash.  If you
  don't have any printing, you could try adding some, but as I mentioned 
  above,
  that might make the bug behave differently.
 
  Another approach is to cut off statements at the end of your script. That
  probably won't affect the bug until you cut off the statement that actually
  triggered it (but it might, which is why this kind of bug is so frustrating 
  to
  track down).
 
  If you find the bad statement, then look at calls to external code in it, or
  recently executed before it.  See if any of them look like they contain 
  errors.
  Common errors are to write to an array without allocating it, or to write 
  beyond
  the bounds of an array, or (in .Call() code) to allocate something and then 
  fail
  to protect it from garbage collection.
 
  You could also figure out what the problem is that caused the seg fault in 
  frame
  0.  It might be because some particular variable contains a garbage value.  
  Then
  in a new run, you can ask gdb to break when that memory location takes on 
  the
  garbage value.  This is usually effective if you really can identify the bad
  value, but doing that can be hard, especially when you aren't familiar with 
  how
  things normally work.
 
 valgrind is usually effective for this
 
R -d valgrind -f myscript.R
 
 but it requires an operating system where it is available (e.g., linux) and a
 quick (say less than 10's of seconds) way of reproducing the bug (because
 valgrind slows evaluation alot). So the first step is really to narrow down 
 your
 large script to something that is easier to re-run., e.g., saving the 
 important
 R objects to a file shortly before the problem section of your script, then
 reproducing the problem by loading those and evaluating a few steps of the 
 code.
 The bug can still be intermittent; valgrind will likely spot the problem.
 
 Martin
 
 
  Good luck!
 
  Duncan Murdoch
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 --
 Computational Biology / Fred Hutchinson Cancer Research Center
 1100 Fairview Ave. N.
 PO Box 19024 Seattle, WA 98109
 
 Location: Arnold Building M1 B861
 Phone: (206) 667-2793
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do 

Re: [R] Getting all possible contingency tables

2012-12-01 Thread Ben Bolker
  
  My goal is to generate all possible contingency tables. Basically I want
  to see the distribution of Chi-squared Statistic under independence
  (NULL).
  
  So I was thinking if I can generate all possible permutation of integer
  numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is there any R
  function to do that?

  I think R *can* do this (thanks to Robin Hankin):

  library(partitions)
  str(parts(36))
 'partition' int [1:36, 1:17977] 36 0 0 0 0 0 0 0 0 0 ...

I'm not quite clear on how you're going to take these results
and turn them into possible tables, but I guess you do ...
You might also be interested in the simulate.p.value option to
chisq.test and the randomizer (which preserves row and column
totals): from the code of chisq.test,

   tmp - .Call(C_chisq_sim, sr, sc, B, E)


  -Original Message-
  From: bogaso.christofer at gmail.com

  Let say I have 2-way contingency table:
  
  Tab - matrix(c(8, 10, 12, 6), nr = 2)
  
  and the Chi-squared test could not reject the independence:
  
 chisq.test(Tab)
  
Pearson's Chi-squared test with Yates' continuity correction
  
  data:  Tab
  X-squared = 1.0125, df = 1, p-value = 0.3143
  
  
  However I want to get all possible contingency tables under this
  independence scenario (one of them would obviously be the given table
  as, we could not reject the independence), and for each such table I
  want to calculate the Ch-sq statistic.
  
  Can somebody help me how to generate all such tables?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cubic spline

2012-12-01 Thread David Winsemius


On Dec 1, 2012, at 5:09 AM, Steve Stephenson wrote:


Hallo,
I'm facing a problem and I would really appreciate your support.
I have to translate some Matalb code in R that I don't know very  
well but I

would like to.
I have to interpolate 5 point with a cubic spline function and then  
I expect
my function returns the Y value as output a specific X value inside  
the

evaluation range.  Let's suppose that:
 1-  *X = [-10, -5, 0, 5, 10]*
 2 - *Y = [12, 10, 8, 7, 6]*
 3 - *I have to interpolate with a cubic spline assuming x=11*

In Matlab I used this function:

*y = interp1(X, Y, x, cubic); *

How can I do the same in R?
Many thanks in advance for your reply and support!


splinefun( x = c(-10, -5, 0, 5, 10),
   y = c(12, 10, 8, 7, 6),
 method=natural)(11)
[1] 5.785714

--
David Winsemius, MD
Alameda, CA, USA

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


Re: [R] Getting all possible contingency tables

2012-12-01 Thread David Winsemius


On Dec 1, 2012, at 7:28 AM, Christofer Bogaso wrote:


Thanks Bert for your reply.

I am trying to understand/visualize the Sample Chi-Squared  
Statistic's Null distribution. Therefore I need all possible  
Contingency tables under Independence case.


What could be better way to visualize that?


In your quest for enlightenment, consider looking at the example in:

?r2dtable

--
David.


Thanks and regards,

On 01 December 2012 20:03:00, Bert Gunter wrote:

Christopher:

Don't do this!

If I understand you correctly, you want FIsher's exact test. This is
already available in R, using far smarter algorithms then you  
would. See:


?fisher.test

-- Bert

On Sat, Dec 1, 2012 at 5:48 AM, Christofer Bogaso
bogaso.christo...@gmail.com mailto:bogaso.christo...@gmail.com  
wrote:


   Thanks John for your reply. However still not clear how I should
   proceed.

   My goal is to generate all possible contingency tables. Basically
   I want to see the distribution of Chi-squared Statistic under
   independence (NULL).

   So I was thinking if I can generate all possible permutation of
   integer numbers having sum equal to (8 + 10 + 12 + 6) = 36. Is
   there any R function to do that?

   Thanks and regards,


   On 01-12-2012 18:39, John Kane wrote:

   Are you basically asking for all possible permutations of the
   table?  If so see ?permn in the combinat package.

   John Kane
   Kingston ON Canada


   -Original Message-
   From: bogaso.christo...@gmail.com
   mailto:bogaso.christo...@gmail.com
   Sent: Sat, 01 Dec 2012 18:10:15 +0545
   To: r-help@r-project.org mailto:r-help@r-project.org
   Subject: [R] Getting all possible contingency tables

   Hello all,

   Let say I have 2-way contingency table:

   Tab - matrix(c(8, 10, 12, 6), nr = 2)

   and the Chi-squared test could not reject the  
independence:


  chisq.test(Tab)

 Pearson's Chi-squared test with Yates'
   continuity correction

   data:  Tab
   X-squared = 1.0125, df = 1, p-value = 0.3143


   However I want to get all possible contingency tables
   under this
   independence scenario (one of them would obviously be the
   given table
   as, we could not reject the independence), and for each
   such table I
   want to calculate the Ch-sq statistic.

   Can somebody help me how to generate all such tables?

   Thanks and regards,




David Winsemius, MD
Alameda, CA, USA

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


Re: [R] segfault debugging

2012-12-01 Thread Brian Ripley


On 1 Dec 2012, at 16:09, William Dunlap wdun...@tibco.com wrote:

 valgrind is usually effective for this
 
  R -d valgrind -f myscript.R
 
 And adding the R command
gctorture(TRUE)
 to the top of your script lets valgrind do a better job of
 find memory misuse.

That makes things even slower: it really only helps when PROTECT is used 
incorrectly (including not used): this error looks more like a memory over-run.

Note that valgrind is really only effective for under/over-run errors involving 
memory allocated by R if the build of R is instrumented (see 'Writing R 
Extensions').

 
 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 Martin Morgan
 Sent: Saturday, December 01, 2012 6:54 AM
 To: Duncan Murdoch
 Cc: r-help@r-project.org; Donatella Quagli
 Subject: Re: [R] segfault debugging
 
 On 12/01/2012 04:51 AM, Duncan Murdoch wrote:
 On 12-12-01 6:56 AM, Donatella Quagli wrote:
 Thank you so far. Here is an excerpt from the gdb session after a crash:
   Program received signal SIGSEGV, Segmentation fault.
 
   0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
   (gdb) backtrace
   #0  0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
   #1  0xb744b64c in ?? () from /usr/lib/R/lib/libR.so
   #2  0xb74c58bf in ?? () from /usr/lib/R/lib/libR.so
   #3  0xb74c9c62 in Rf_eval () from /usr/lib/R/lib/libR.so
   #4  0xb74ce60f in Rf_applyClosure () from /usr/lib/R/lib/libR.so
   #5  0xb74c9f29 in Rf_eval () from /usr/lib/R/lib/libR.so
   #6  0xb7503002 in Rf_ReplIteration () from /usr/lib/R/lib/libR.so
   #7  0xb7503298 in ?? () from /usr/lib/R/lib/libR.so
   #8  0xb7503812 in run_Rmainloop () from /usr/lib/R/lib/libR.so
   #9  0xb7503839 in Rf_mainloop () from /usr/lib/R/lib/libR.so
   #10 0x08048768 in main ()
   #11 0xb728de46 in __libc_start_main (main=0x8048730 main, argc=8,
 ubp_av=0xbfdb7824, init=0x80488a0 __libc_csu_init,
   fini=0x8048890 __libc_csu_fini, rtld_fini=0xb7784590,
 stack_end=0xbfdb781c) at libc-start.c:228
   #12 0x08048791 in _start ()
 
 It seems to me that the error is in frame #0. Does it mean that there is a 
 bug
 in libR.so?  What can I do next?
 
 It means that the error was detected when trying to do a memory allocation.
 That could be a bug in R, but more likely something else has damaged the 
 memory
 management system structures, e.g. a function writing to memory that it 
 doesn't
 own.
 
 Bugs like this are hard to track down, because the damage could have 
 occurred a
 long time before it showed up, and small changes to your script could 
 affect it.
 
 I would try to narrow it down to a single statement in your script.  You 
 might
 be able to deduce that from the last line printed before the crash.  If you
 don't have any printing, you could try adding some, but as I mentioned 
 above,
 that might make the bug behave differently.
 
 Another approach is to cut off statements at the end of your script. That
 probably won't affect the bug until you cut off the statement that actually
 triggered it (but it might, which is why this kind of bug is so frustrating 
 to
 track down).
 
 If you find the bad statement, then look at calls to external code in it, or
 recently executed before it.  See if any of them look like they contain 
 errors.
 Common errors are to write to an array without allocating it, or to write 
 beyond
 the bounds of an array, or (in .Call() code) to allocate something and then 
 fail
 to protect it from garbage collection.
 
 You could also figure out what the problem is that caused the seg fault in 
 frame
 0.  It might be because some particular variable contains a garbage value.  
 Then
 in a new run, you can ask gdb to break when that memory location takes on 
 the
 garbage value.  This is usually effective if you really can identify the bad
 value, but doing that can be hard, especially when you aren't familiar with 
 how
 things normally work.
 
 valgrind is usually effective for this
 
   R -d valgrind -f myscript.R
 
 but it requires an operating system where it is available (e.g., linux) and a
 quick (say less than 10's of seconds) way of reproducing the bug (because
 valgrind slows evaluation alot). So the first step is really to narrow down 
 your
 large script to something that is easier to re-run., e.g., saving the 
 important
 R objects to a file shortly before the problem section of your script, then
 reproducing the problem by loading those and evaluating a few steps of the 
 code.
 The bug can still be intermittent; valgrind will likely spot the problem.
 
 Martin
 
 
 Good luck!
 
 Duncan Murdoch
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 --
 

[R] screen if a value is within range

2012-12-01 Thread Andras Farkas
Dear all,
 
could you please give me some pointers on how I could make R screen for a value 
if it falls within a certain range?
I looked at the subset function, but is not doing it, perhaps because I only 
have 1 value to screen?
 
aptreciate the input
 
ex:
a -16.5
I would like to screen to see if a is within the range of 15 to 20, (which it 
is:-)), and I would like the code to return a value of 1 if a is within the 
specified range or 0 if it is not.
 
Apreciate the insights,
 
Andras
[[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] screen if a value is within range

2012-12-01 Thread R. Michael Weylandt
15  a  a  20

Wrap it in a function if you like:

in_interval - function(x, interval){
   stopifnot(length(interval) == 2L)
   interval[1]  x  x  interval[2]
}

in_interval(a, c(15, 20))

Cheers,
Michael

On Sat, Dec 1, 2012 at 4:50 PM, Andras Farkas motyoc...@yahoo.com wrote:

 could you please give me some pointers on how I could make R screen for a 
 value if it falls within a certain range?
 I looked at the subset function, but is not doing it, perhaps because I only 
 have 1 value to screen?

 aptreciate the input

 ex:
 a -16.5
 I would like to screen to see if a is within the range of 15 to 20, (which it 
 is:-)), and I would like the code to return a value of 1 if a is within the 
 specified range or 0 if it is not.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] segfault debugging

2012-12-01 Thread David Winsemius


On Nov 30, 2012, at 10:02 AM, Donatella Quagli wrote:


Hello everybody,

I have written a script with two inline cfunctions. The script  
crashes from time to time with:

   *** caught segfault ***
  address 0x10, cause 'memory not mapped'

The crashs happen within R code after the cfunctions were executed.  
Nevertheless I think

that the pointers in my cfunctions are not used correctly.

I tried to find some examples for debugging tools. I found something  
like R -d gdb. But I
could not find an example how to use it with #!/usr/bin/Rscript. And  
I cannot source the script

within a running R session because I must run it with some args.

Can anybody tell me as a non nerd step by step what I can do to  
locate the problem? Can

you recommend tools? If so how are they used with Rscript?


I think you may have difficulty defending your non-nerd claim if you  
are writing cfunctions in R. That said, you may want to look at a very  
recent SO answer by Hadley Wickham on StackOverflow:


http://stackoverflow.com/questions/13661065/r-superimpose-histogram-fits-in-one-plot

(I'm less nerdy than you, but it does appear that Hadley's code  
demonstrates efforts at checking for available memory and you may  
benefit from a worked example in Rcpp.)


--

David Winsemius, MD
Alameda, CA, USA

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


Re: [R] screen if a value is within range

2012-12-01 Thread Robert Baer

On 12/1/2012 10:50 AM, Andras Farkas wrote:

Dear all,
  
could you please give me some pointers on how I could make R screen for a value if it falls within a certain range?

I looked at the subset function, but is not doing it, perhaps because I only 
have 1 value to screen?
  
aptreciate the input
  
ex:

a -16.5
I would like to screen to see if a is within the range of 15 to 20, (which it 
is:-)), and I would like the code to return a value of 1 if a is within the 
specified range or 0 if it is not.
  
Apreciate the insights,
  
Andras

[[alternative HTML version deleted]]

a = 16.5
ans = (a = 15  a = 20)
ans
[1] TRUE

Rob

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] screen if a value is within range

2012-12-01 Thread David Winsemius


On Dec 1, 2012, at 9:55 AM, R. Michael Weylandt wrote:


15  a  a  20

Wrap it in a function if you like:

in_interval - function(x, interval){
  stopifnot(length(interval) == 2L)
  interval[1]  x  x  interval[2]
}

in_interval(a, c(15, 20))



Could just use the findInterval function:

findInterval(x, c(15,20) ) == 1

findInterval returns a numeric vector indicating which bin(s) the  
argument vector element(s) fall(s) into. Items below the lower bound  
get a zero which means if the result is used as an index the there  
will be no item chosen for that value. Items above the maximal  
boundary get a value of n+1 where n is the number of bins. (Very  
useful function.)


--
David.

Cheers,
Michael

On Sat, Dec 1, 2012 at 4:50 PM, Andras Farkas motyoc...@yahoo.com  
wrote:


could you please give me some pointers on how I could make R screen  
for a value if it falls within a certain range?
I looked at the subset function, but is not doing it, perhaps  
because I only have 1 value to screen?


aptreciate the input

ex:
a -16.5
I would like to screen to see if a is within the range of 15 to 20,  
(which it is:-)), and I would like the code to return a value of 1  
if a is within the specified range or 0 if it is not.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
Alameda, CA, USA

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


Re: [R] protentially serious R error

2012-12-01 Thread David L Carlson
Congratulations, you've reached the First Circle of the R Inferno. Only 8
more to go

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Ben Bolker
 Sent: Friday, November 30, 2012 7:19 PM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] protentially serious R error
 
 Cutting and pasting from the R posting guide -- I think this advice
 has special force when responding to FAQ 7.31 questions (I've seen
 several within the last few days, and at least two were answered by
 three different people:
 
 When responding to a very simple question, use the following algorithm:
 
 compose your response
 type 4*runif(1) at the R prompt, and wait this many hours
 check for new posts to R-help; if no similar suggestion, post your
 response
 
 (This is partly in jest, but if you know immediately why it is
 suggested, you
 probably should use it! Also, it's a nice idea to replace 4 by the
 number of
 years you have been using R or S-plus.)
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Reading .gsheet within R

2012-12-01 Thread Luca Meyer
Thank you Henrik  the others that have commented. Accessing the actual online 
data is what I would need, but apparently this is not yet feasible…
Luca


Il giorno 01/dic/2012, alle ore 04:53, Henrik Bengtsson h...@biostat.ucsf.edu 
ha scritto:

 On Fri, Nov 30, 2012 at 9:43 AM, Luca Meyer lucam1...@gmail.com wrote:
 Hello R-experts,
 
 I would like to know if there is a solution to read files with extension 
 .gsheet directly into R - see http://www.fileinfo.com/extension/gsheet for 
 more info on this file format.
 
 AFAIK, those files (*.gsheet, *.gdoc, *.gslides) are just tiny JSON
 files containing references to the online/cloud resource (specifying
 the url and the resource_id).  There are several packages on CRAN
 for parsing JSON files.  Accessing the actual online data is a
 different story...
 
 My $0.02
 
 /Henrik
 
 
 Thank you,
 Luca
 
 Mr. Luca Meyer
 www.lucameyer.com
 R 2.15.1
 Mac OS X 10.8.2
 
 
 
 
 
 
 
[[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] segfault debugging

2012-12-01 Thread William Dunlap
While it is true that valgrind is most effective when R is built with special
flags, it can be useful without the special build.  Also, gctorture(TRUE)
does make it run very slowly, but I have seen it show things that only
sporadically show up otherwise.  E.g., with an optimized 64-bit Linux
build of R-2.15.2 we get:

% R --debugger=valgrind --quiet
==19559== Memcheck, a memory error detector
==19559== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==19559== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==19559== Command: /opt/sw/R/R-2.15.2.atlas1/lib/R/bin/exec/R --quiet
...
 gctorture(TRUE)
 library(gam)
Loading required package: splines
Loaded gam 1.06.2

 g - gam(mpg~lo(hp,span=.4,degree=2)+gear, data=mtcars)
==19559== Conditional jump or move depends on uninitialised value(s)
==19559==at 0x4F4CA5D: R_gc_internal (memory.c:1510)
==19559==by 0x4F4EDDD: Rf_allocVector (memory.c:2355)
==19559==by 0x4FC94D0: do_lazyLoadDBfetch (serialize.c:2517)
==19559==by 0x4F12E8E: Rf_eval (eval.c:497)
...
==19559== Use of uninitialised value of size 8
==19559==at 0x4F4CA5F: R_gc_internal (memory.c:1510)
==19559==by 0x4F4EDDD: Rf_allocVector (memory.c:2355)
==19559==by 0x4FC94D0: do_lazyLoadDBfetch (serialize.c:2517)
==19559==by 0x4F12E8E: Rf_eval (eval.c:497)
...
==19559== Invalid read of size 1
==19559==at 0x4F4CA5F: R_gc_internal (memory.c:1510)
==19559==by 0x4F4EDDD: Rf_allocVector (memory.c:2355)
==19559==by 0x4FC94D0: do_lazyLoadDBfetch (serialize.c:2517)
==19559==by 0x4F12E8E: Rf_eval (eval.c:497)
...
*** caught segfault ***
address 0x3010, cause 'memory not mapped'
==19559== Conditional jump or move depends on uninitialised value(s)
==19559==at 0x4F4CA5D: R_gc_internal (memory.c:1510)
==19559==by 0x4F4EB19: Rf_cons (memory.c:2076)
==19559==by 0x4F4ECEE: Rf_allocList (memory.c:2481)
==19559==by 0x4EFD094: R_GetTraceback (errors.c:1307)
...

Without the gctorture(TRUE) there is no complaint from valgrind,
although I've seen evidence of memory corruption later.  (Without
valgrind but with gctorture(TRUE) there is no complaint on the first
call to gam() but R dies on a repeated call.)

Perhaps if I used a valgrind-enabled build of R it would localize
the problem to C or Fortran code behind lo(degree=2).


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: Brian Ripley [mailto:rip...@stats.ox.ac.uk]
 Sent: Saturday, December 01, 2012 8:45 AM
 To: William Dunlap
 Cc: Martin Morgan; Duncan Murdoch; r-help@r-project.org; Donatella Quagli
 Subject: Re: [R] segfault debugging
 
 
 
 On 1 Dec 2012, at 16:09, William Dunlap wdun...@tibco.com wrote:
 
  valgrind is usually effective for this
 
   R -d valgrind -f myscript.R
 
  And adding the R command
 gctorture(TRUE)
  to the top of your script lets valgrind do a better job of
  find memory misuse.
 
 That makes things even slower: it really only helps when PROTECT is used 
 incorrectly
 (including not used): this error looks more like a memory over-run.
 
 Note that valgrind is really only effective for under/over-run errors 
 involving memory
 allocated by R if the build of R is instrumented (see 'Writing R Extensions').
 
 
  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 Martin Morgan
  Sent: Saturday, December 01, 2012 6:54 AM
  To: Duncan Murdoch
  Cc: r-help@r-project.org; Donatella Quagli
  Subject: Re: [R] segfault debugging
 
  On 12/01/2012 04:51 AM, Duncan Murdoch wrote:
  On 12-12-01 6:56 AM, Donatella Quagli wrote:
  Thank you so far. Here is an excerpt from the gdb session after a crash:
Program received signal SIGSEGV, Segmentation fault.
 
0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
(gdb) backtrace
#0  0xb7509a6b in Rf_allocVector () from /usr/lib/R/lib/libR.so
#1  0xb744b64c in ?? () from /usr/lib/R/lib/libR.so
#2  0xb74c58bf in ?? () from /usr/lib/R/lib/libR.so
#3  0xb74c9c62 in Rf_eval () from /usr/lib/R/lib/libR.so
#4  0xb74ce60f in Rf_applyClosure () from /usr/lib/R/lib/libR.so
#5  0xb74c9f29 in Rf_eval () from /usr/lib/R/lib/libR.so
#6  0xb7503002 in Rf_ReplIteration () from /usr/lib/R/lib/libR.so
#7  0xb7503298 in ?? () from /usr/lib/R/lib/libR.so
#8  0xb7503812 in run_Rmainloop () from /usr/lib/R/lib/libR.so
#9  0xb7503839 in Rf_mainloop () from /usr/lib/R/lib/libR.so
#10 0x08048768 in main ()
#11 0xb728de46 in __libc_start_main (main=0x8048730 main, argc=8,
  ubp_av=0xbfdb7824, init=0x80488a0 __libc_csu_init,
fini=0x8048890 __libc_csu_fini, rtld_fini=0xb7784590,
  stack_end=0xbfdb781c) at libc-start.c:228
#12 0x08048791 in _start ()
 
  It seems to me that the error is in frame #0. Does it mean that there is 
  a bug
  in libR.so?  What can I do next?
 
  It means that the error 

Re: [R] Fw: quantreg installation and conflicts with R 2.15.2

2012-12-01 Thread Uwe Ligges



On 30.11.2012 22:10, Brian S Cade wrote:

Just noticed that I get a similar error about object 'kronecker' in
Matrix package when trying to load lme4.   So this is a more pervasive
problem.


Probably you have a mixture of packages for various versions of R around.

So after checking if all required packages are really installed, please run

update.packages(checkBuilt=TRUE)

Uwe Ligges





Brian

Brian S. Cade, PhD

U. S. Geological Survey
Fort Collins Science Center
2150 Centre Ave., Bldg. C
Fort Collins, CO  80526-8818

email:  brian_c...@usgs.gov
tel:  970 226-9326
- Forwarded by Brian S Cade/BRD/USGS/DOI on 11/30/2012 02:07 PM -

From:
Brian S Cade/BRD/USGS/DOI
To:
R-help@r-project.org
Date:
11/30/2012 01:16 PM
Subject:
quantreg installation and conflicts with R 2.15.2


I recently lost the partitions on my hard drive (second time in 6 months)
so I had to have our IT folks image all my files over to a new drive.  I
completely reinstalled R (now 2.15.2) and all my libraries to my computer
(Dell Latitude running Windows 7).  A few of my previous workspaces
(created with R 2.14.1) can't be restored, reporting an error similar to
the one I get when I try to load quantreg package which requires
SparseM (see below).   So, not only will quantreg not load but some of
my workspaces can't be restored when being loaded (see below).  Not sure
about what this is about.   I asked Roger Koenker, the package maintainer,
but he is on travel and won't have chance to seriously investigate this
for awhile.  So I thought I would put it out to the R community and see if
anyone has any suggestions about why this conflict might be occurring.


library(quantreg)

Loading required package: SparseM
Error : object ?kronecker? is not exported by 'namespace:methods'
Error: package ?SparseM? could not be loaded

or

Error: object ?kronecker? is not exported by 'namespace:methods'
During startup - Warning message:
unable to restore saved data in C:\CADESTUFF\DATA\BarryNoon\.RData




Brian

Brian S. Cade, PhD

U. S. Geological Survey
Fort Collins Science Center
2150 Centre Ave., Bldg. C
Fort Collins, CO  80526-8818

email:  brian_c...@usgs.gov
tel:  970 226-9326

[[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] SVM using R

2012-12-01 Thread Uwe Ligges



On 30.11.2012 05:08, vivek kumar singh wrote:

HI All,

I am very new to R tool. Can some one please suggest me some tutorial
links for understanding SVM using R.


After reading some textbook about the SVM, go ahead and look for ?svm in 
package e1071.


Best,
Uwe Ligges



Regards,
Vivek

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 repeat replication

2012-12-01 Thread Uwe Ligges



On 30.11.2012 08:23, Kamontip Srihaset wrote:



Dear all,

I generate data under IRT mdel. I conducted 1000 replications. When I run, some 
replication was not fit with my model. So, replications were fit model were 
less than 1000 replication. If I want its run until 1000 replicaions. How 
shouldI write functin.


Show us your (reduced but reproducible) code and we may be able to help. 
Please read the positng guide.


Uwe Ligges



Thank you,
Kamontip



[[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] [R-pkgs] New package: gRain - gRAphical Independence Networks

2012-12-01 Thread Uwe Ligges



On 29.11.2012 20:46, fkh wrote:

I am trying to use your package gRain using your book on graphical models in
R to do predictions, I have 38 columns of vectors all factors and built a
bayesian network using iamb() function, then I used the following command to
make a grpahNEL (However, I have 38 nodes and 106 edges) using
BN-iamb(data1)
BN.gr-as(amat(BN),graphNEL)
Then when I am using the following command to make a grain object I got the
following errors, any thoughts? Thanks a lot for your help in advance.

BN.grain-grain(BN.gr,data=data1)

Error in function (classes, fdef, mtable)  :
   unable to find an inherited method for function nodes, for signature
graphNEL, missing




Are you aware you posted to the mailing list rather than to the package 
maintainer?


Uwe Ligges




--
View this message in context: 
http://r.789695.n4.nabble.com/R-pkgs-New-package-gRain-gRAphical-Independence-Networks-tp846943p4651338.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] deleting data of a given date range.

2012-12-01 Thread Uwe Ligges



On 29.11.2012 17:37, arun wrote:

Hi,

You haven't given any example dataset.  So,not sure about the format of the 
date column.
set.seed(5)
dat1-data.frame(Date1=c(10/25/2009,11/25/2009,12/25/2009,5/10/2010,8/10/2010,9/25/2011,11/28/2011,5/3/2012),col2=sample(1:15,8,replace=TRUE))
dat1$Date1-as.Date(dat1$Date1,format=%m/%d/%Y) #change your date column 
format if it is not matching to this example.
dat2-dat1[format(dat1$Date1,%Y)!=2009,]
dat2
#   Date1 col2
#4 2010-05-105
#5 2010-08-102
#6 2011-09-25   11
#7 2011-11-288
#8 2012-05-03   13
A.K.



Or just use comparison operators on Date objects,
so it is also possible to specify arbitrary ranges.

Uwe Ligges








- Original Message -

From: siddanth911 siddanth.srivast...@mu-sigma.com
To: r-help@r-project.org
Cc:
Sent: Thursday, November 29, 2012 6:10 AM
Subject: [R] deleting data of a given date range.

hey,

I have a huge dataset with over 30 rows which contains data about
something from 2009-2012. does anyone know how i can delete all the rows
which contain data from 2009 and only have data from 2010-2012???
is there a particular function i can use on the date column so that all data
from 2009 can be deleted???



--
View this message in context: 
http://r.789695.n4.nabble.com/deleting-data-of-a-given-date-range-tp4651272.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.



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


Re: [R] NA return to NLM routine

2012-12-01 Thread Uwe Ligges



On 30.11.2012 23:55, Mac Gaulin wrote:

Hello,

I am trying to understand a small quirk I came across in R. The
following code results in an error:

k - c(2, 1, 1, 5, 5)
f - c(1, 1, 1, 3, 2)
loglikelihood - function(theta,k,f){
 if( theta1  theta0 )
 return(-1*sum(log(choose(k,f))+f*log(theta)+(k-f)*log(1-theta)))
 return(NA)
}
nlm(loglikelihood ,0.5, k, f )

Running this code results in:
Error in nlm(logliklihood, 0.5, k, f) :
   invalid function value in 'nlm' optimizer

However if the line return(NA) is changed to return(-NA) or even
return(1*NA) or return(1/0), the code works. Is this expected
behavior? The nlm help file says not NA or not NaN are acceptable
values but I don't understand what that means.


Your function must return finite numbers, that means infinite numbers, 
NA nor NaN are not allowed and you experienced what happens if you do that.


Please see ?constrOptim or other appropriate functions for constrained 
optimization problems.


Uwe Ligges



Thank you for your time,
Mac Gaulin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] CreateThread failure since R 2.15.2 (32-bit)

2012-12-01 Thread Uwe Ligges



On 30.11.2012 12:27, Martin Studer wrote:

Dear R users  developers,

I coming across the following issue since R 2.15.2 32-bit (running on
Windows XP 32.bit; some output left out for conciseness):



Works for me. Which Java version are you using is this?
Perhaps Java changes the environment so that your version of ls fails. 
Is it the one from Rtools?


Uwe Ligges




setInternet2(TRUE)
require(rJava)
.jinit()
getCRANmirrors()
system(ls , intern = TRUE)

Error in system(ls, intern = TRUE) : CreateThread failed

My details are as follows:


sessionInfo()

R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=German_Switzerland.1252
LC_CTYPE=German_Switzerland.1252
LC_MONETARY=German_Switzerland.1252
[4] LC_NUMERIC=CLC_TIME=German_Switzerland.1252

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

other attached packages:
[1] rJava_0.9-3


The failure appears since R 2.15.2, i.e. also with R 2.15.2patched and
with R-Devel. It does, however, not appear with e.g. R 2.15.1 or R
2.14.2. Also, I don't get the issue with R 2.15.2 64-bit (running on
Windows 7 Professional 64-bit).

Also note that the issue seems related to rJava in that running the
same without the rJava part (and therefore without initializing a JVM
instance) runs fine:


setInternet2(TRUE)
getCRANmirrors()
system(ls , intern = TRUE)


Any ideas on what the issue might be?

Thanks  Best regards,
Martin

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] protentially serious R error

2012-12-01 Thread Ted Harding
That applies to the OP (Xiaofeng, aka liuxf), of course.
Ben himself is a guardian of all Circles (loc.cit.).

With regard to Ben's quote from the Posting Guide, it occurs
to me that the more years one has been using R, the more
rapdily one should (or should be able to) answer a question.
The implication of the Posting Guide is that the time it should
take one to respond to a question is inversely proportional
to one's experience of using R. This is turn could imply that
some users, with the longest experience, may never respond
(since, by the time their response is due, adequate responses
have probably already been furnished by others, somewhat less
experienced). There may be some empirical evidence for this. :)

Best wishes to all,
Ted.

On 01-Dec-2012 17:54:50 David L Carlson wrote:
 Congratulations, you've reached the First Circle of the R Inferno.
 Only 8 more to go
 
 http://www.burns-stat.com/pages/Tutor/R_inferno.pdf
 
 --
 David L Carlson
 Associate Professor of Anthropology
 Texas AM University
 College Station, TX 77843-4352
 
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Ben Bolker
 Sent: Friday, November 30, 2012 7:19 PM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] protentially serious R error
 
 Cutting and pasting from the R posting guide -- I think this advice
 has special force when responding to FAQ 7.31 questions (I've seen
 several within the last few days, and at least two were answered by
 three different people:
 
 When responding to a very simple question, use the following algorithm:
 
 compose your response
 type 4*runif(1) at the R prompt, and wait this many hours
 check for new posts to R-help; if no similar suggestion, post your
 response
 
 (This is partly in jest, but if you know immediately why it is
 suggested, you
 probably should use it! Also, it's a nice idea to replace 4 by the
 number of
 years you have been using R or S-plus.)
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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.

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 01-Dec-2012  Time: 19:30:19
This message was sent by XFMail

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cubic spline

2012-12-01 Thread Martin Maechler
 David Winsemius dwinsem...@comcast.net
 on Sat, 1 Dec 2012 09:25:42 -0700 writes:

 On Dec 1, 2012, at 5:09 AM, Steve Stephenson wrote:

 Hallo, I'm facing a problem and I would really appreciate
 your support.  I have to translate some Matalb code in R
 that I don't know very well but I would like to.  I have
 to interpolate 5 point with a cubic spline function and
 then I expect my function returns the Y value as output a
 specific X value inside the evaluation range.  Let's
 suppose that: 1- *X = [-10, -5, 0, 5, 10]* 2 - *Y = [12,
 10, 8, 7, 6]* 3 - *I have to interpolate with a cubic
 spline assuming x=11*
 
 In Matlab I used this function:
 
 *y = interp1(X, Y, x, cubic); *
 
 How can I do the same in R?  Many thanks in advance for
 your reply and support!

 splinefun( x = c(-10, -5, 0, 5, 10), y = c(12, 10, 8, 7, 6), 
method=natural)(11) [1] 5.785714

Yes, indeed, or simple  spline()

but definitely *no* need to use a function from an extra CRAN
package .. as someone else ``erronously'' suggested.

Note that
  spline() and splinefun()
together with
  approx() and approxfun()
are among the several hundred functions that were already
part of pre-alpha R, i.e., before R had a version number or *any* packages ...
and yes, the README then started with the two lines

| R Source Code (Tue Jun 20 14:33:47 NZST 1995)
| Copyright 1993, 1994, 1995 by Robert Gentleman and Ross Ihaka

and it would be *really* *really* great
if people did not add stuff to their packages that has
been part of R for longer than they have even heard of R.

Martin Maechler, ETH Zurich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] reading json tables

2012-12-01 Thread Michael Friendly
I'm trying to read two data sets in json format from a single .js file. 
I've tried fromJSON()

in both RJSONIOIO and RJSON packages, but they require that the lines be
pre-parsed somehow in ways I don't understand.  Can someone help?

 wheat - readLines(http://mbostock.github.com/protovis/ex/wheat.js;)
 str(wheat)
 chr [1:70] var wheat = [   { year: 1565, wheat: 41, wages: 5 }, ...


The wheat.js file looks like this and defines two tables:  wheat and 
monarch:


var wheat = [
  { year: 1565, wheat: 41, wages: 5 },
  { year: 1570, wheat: 45, wages: 5.05 },
  { year: 1575, wheat: 42, wages: 5.08 },
  { year: 1580, wheat: 49, wages: 5.12 },
  { year: 1585, wheat: 41.5, wages: 5.15 },
  { year: 1590, wheat: 47, wages: 5.25 },
  { year: 1595, wheat: 64, wages: 5.54 },
  { year: 1600, wheat: 27, wages: 5.61 },
  { year: 1605, wheat: 33, wages: 5.69 },
  { year: 1610, wheat: 32, wages: 5.78 },
  { year: 1615, wheat: 33, wages: 5.94 },
  { year: 1620, wheat: 35, wages: 6.01 },
...
  { year: 1800, wheat: 79, wages: 28.5 },
  { year: 1805, wheat: 81, wages: 29.5 },
  { year: 1810, wheat: 99, wages: 30 },
  { year: 1815, wheat: 78 }, // TODO
  { year: 1820, wheat: 54 },
  { year: 1821, wheat: 54 }
];

var monarch = [
  { name: Elizabeth, start: 1565, end: 1603 },
  { name: James I, start: 1603, end: 1625 },
  { name: Charles I, start: 1625, end: 1649 },
  { name: Cromwell, start: 1649, end: 1660, commonwealth: true },
  { name: Charles II, start: 1660, end: 1685 },
  { name: James II, start: 1685, end: 1689 },
  { name: WM, start: 1689, end: 1702 },
  { name: Anne, start: 1702, end: 1714 },
  { name: George I, start: 1714, end: 1727 },
  { name: George II, start: 1727, end: 1760 },
  { name: George III, start: 1760, end: 1820 },
  { name: George IV, start: 1820, end: 1821 }
];

--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.  Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] reading json tables

2012-12-01 Thread Duncan Temple Lang

Hi Michael

  The problem is that the content of the .js file is not JSON,
but actual JavaScript code.

You could use something like the following

tt = readLines(http://mbostock.github.com/protovis/ex/wheat.js;)

txt = c([, gsub(;, ,, gsub(var [a-zA-Z]+ = , , tt)), ])
tmp = paste(txt, collapse = \n)
tmp = gsub(([a-zA-Z]+):, '\\1:', tmp)
o = fromJSON(tmp)
data = structure(o[1:2], names = c(wheat, monarch))

Basically, this
removes the 'var variable name =' part
replaces the ; with a , to separate elements
quotes the names of the fields, e.g. year, wheat, wages
puts the two global data objects into a top-level array ([]) container

This isn't ideal (as the regular expressions are not sufficiently specific
and could modify the actual values incorrectly). However, it does the job
for this particular file.

On 12/1/12 12:47 PM, Michael Friendly wrote:
 I'm trying to read two data sets in json format from a single .js file. I've 
 tried fromJSON()
 in both RJSONIOIO and RJSON packages, but they require that the lines be
 pre-parsed somehow in ways I don't understand.  Can someone help?
 
 wheat - readLines(http://mbostock.github.com/protovis/ex/wheat.js;)
 str(wheat)
  chr [1:70] var wheat = [   { year: 1565, wheat: 41, wages: 5 }, ...

 
 The wheat.js file looks like this and defines two tables:  wheat and monarch:
 
 var wheat = [
   { year: 1565, wheat: 41, wages: 5 },
   { year: 1570, wheat: 45, wages: 5.05 },
   { year: 1575, wheat: 42, wages: 5.08 },
   { year: 1580, wheat: 49, wages: 5.12 },
   { year: 1585, wheat: 41.5, wages: 5.15 },
   { year: 1590, wheat: 47, wages: 5.25 },
   { year: 1595, wheat: 64, wages: 5.54 },
   { year: 1600, wheat: 27, wages: 5.61 },
   { year: 1605, wheat: 33, wages: 5.69 },
   { year: 1610, wheat: 32, wages: 5.78 },
   { year: 1615, wheat: 33, wages: 5.94 },
   { year: 1620, wheat: 35, wages: 6.01 },
 ...
   { year: 1800, wheat: 79, wages: 28.5 },
   { year: 1805, wheat: 81, wages: 29.5 },
   { year: 1810, wheat: 99, wages: 30 },
   { year: 1815, wheat: 78 }, // TODO
   { year: 1820, wheat: 54 },
   { year: 1821, wheat: 54 }
 ];
 
 var monarch = [
   { name: Elizabeth, start: 1565, end: 1603 },
   { name: James I, start: 1603, end: 1625 },
   { name: Charles I, start: 1625, end: 1649 },
   { name: Cromwell, start: 1649, end: 1660, commonwealth: true },
   { name: Charles II, start: 1660, end: 1685 },
   { name: James II, start: 1685, end: 1689 },
   { name: WM, start: 1689, end: 1702 },
   { name: Anne, start: 1702, end: 1714 },
   { name: George I, start: 1714, end: 1727 },
   { name: George II, start: 1727, end: 1760 },
   { name: George III, start: 1760, end: 1820 },
   { name: George IV, start: 1820, end: 1821 }
 ];


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


Re: [R] NA return to NLM routine

2012-12-01 Thread Berend Hasselman

On 30-11-2012, at 23:55, Mac Gaulin wrote:

 Hello,
 
 I am trying to understand a small quirk I came across in R. The
 following code results in an error:
 
 k - c(2, 1, 1, 5, 5)
 f - c(1, 1, 1, 3, 2)
 loglikelihood - function(theta,k,f){
if( theta1  theta0 )
return(-1*sum(log(choose(k,f))+f*log(theta)+(k-f)*log(1-theta)))
return(NA)
 }
 nlm(loglikelihood ,0.5, k, f )
 
 Running this code results in:
 Error in nlm(logliklihood, 0.5, k, f) :
  invalid function value in 'nlm' optimizer
 

if you do 

a - NA
str(a)

you'll see that a is a logical. And that is an invalid value for the function 
to return.
When you do things such as NA+0 or -NA you get a numeric value NA and that is a 
non-finite value which is why you get the warning..

Instead of NA you could return something like .Machine$double.xmax .
Or use constrOptim as advised.

Berend


 However if the line return(NA) is changed to return(-NA) or even
 return(1*NA) or return(1/0), the code works. Is this expected
 behavior? The nlm help file says not NA or not NaN are acceptable
 values but I don't understand what that means.
 
 Thank you for your time,
 Mac Gaulin
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 all possible contingency tables

2012-12-01 Thread Richard M. Heiberger
I believe you are looking for a detailed construction of Fisher's Exact
Test.  I have an example
with code in my book and R package.

The book discussion is Section 15.2 of
Heiberger, Richard M., and Burt Holland (2004). Statistical Analysis and
Data
Display: An Intermediate Course with Examples in S-Plus, R, and SAS.
Springer--Verlag, New York.
http://springer.com/0-387-40270-5

Table 15.2 shows the full set of tables for the example.

The package is HH
install.packages(HH)
The code to construct Table 15.2 is in file
library/HH/scripts/Ch15-twtb.r
Search for the line:
## study the construction of the Fisher Exact test
and read through to the end of the glasses example.

Rich



On Sat, Dec 1, 2012 at 7:25 AM, Christofer Bogaso 
bogaso.christo...@gmail.com wrote:

 Hello all,

 Let say I have 2-way contingency table:

 Tab - matrix(c(8, 10, 12, 6), nr = 2)

 and the Chi-squared test could not reject the independence:

  chisq.test(Tab)

 Pearson's Chi-squared test with Yates' continuity correction

 data:  Tab
 X-squared = 1.0125, df = 1, p-value = 0.3143


 However I want to get all possible contingency tables under this
 independence scenario (one of them would obviously be the given table as,
 we could not reject the independence), and for each such table I want to
 calculate the Ch-sq statistic.

 Can somebody help me how to generate all such tables?

 Thanks and regards,

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


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cubic spline

2012-12-01 Thread Ben Bolker
Martin Maechler maechler at stat.math.ethz.ch writes:

 [snip]

 but definitely *no* need to use a function from an extra CRAN
 package .. as someone else ``erronously'' suggested.
 
 Note that
   spline() and splinefun()
 together with
   approx() and approxfun()
 are among the several hundred functions that were already
 part of pre-alpha R, i.e., before R had a version number or *any* 
 packages ...
 and yes, the README then started with the two lines
 
 | R Source Code (Tue Jun 20 14:33:47 NZST 1995)
 | Copyright 1993, 1994, 1995 by Robert Gentleman and Ross Ihaka
 
 and it would be *really* *really* great
 if people did not add stuff to their packages that has
 been part of R for longer than they have even heard of R.
 
 Martin Maechler, ETH Zurich

  To be fair, the 'fields' package has a pretty long history too --
I think it may have been ported from an S-PLUS 'package' (or whatever
the correct terminology is) that existed quite a while ago.

 I think it was the FUNFITS module. From http://lib.stat.cmu.edu/S/:

funfits

FUNFITS is a comprehensive S-Plus module for fitting functions and
nonlinear time series, including multivariate splines, Kriging and
neural networks.  Contributed by Doug Nychka
(nyc...@ucar.edu). [25/Apr/96] [24/Mar/97][24/Sep/99] (3 kbytes). The
actual compressed tar file is available as funfits23.tar.gz in the S
collection. Access this file via FTP, or the WWW, but not
e-mail. (596k).  Older version avaulable at funfits.tar.Z

  A quick look at funfits.tar.Z suggests that 'splint' existed in that
version, in 1996 -- so respectably old.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] x axis labels

2012-12-01 Thread apprentice
Hi,

I have a problem with plotting my data as a histogram using barplot2. I am
plotting the x axis using axis(). I want to label only every fifth bar and
not all of them as they get too busy but I don't know how to do it. I was
trying to set the labels for the axis using at=seq(min value, max value,
by=5) but that leads to labels not being under the right bars but just sort
of spread around.
Does anyone know how to do it properly?

Thanks in advance,
Barbara



--
View this message in context: 
http://r.789695.n4.nabble.com/x-axis-labels-tp4651589.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 built a pivot table of value

2012-12-01 Thread arun
HI,
You can also also ?reshape()
res-reshape(base,v.names=r,idvar=p,timevar=q,direction=wide)
 res[order(res$p),]
A.K.



- Original Message -
From: CE.KA ce.kay...@yahoo.fr
To: r-help@r-project.org
Cc: 
Sent: Saturday, December 1, 2012 7:37 AM
Subject: [R] How to built a pivot table of value

Hi R users

Imagine the table base:
p=c(d,d,b,b,a,a)
q=c(v1,v2,v1,v2,v1,v2)
r=c(5,2,4,8,9,7)
base=data.frame(p,q,r)
base

     p   q     r
1  d   v1   5
2  d   v2   2
3  b   v1  4
4  b   v2   8
5  a   v1   9
6  a   v2   7

How programming R to get this result:

             v1   v2
a          9        7
b         4        8
d         5        2

I tried the function table but the result is divided in several matrix:
table(base$p,base$q,base$r)
, ,  = 2

  
    v1 v2
  a  0  0
  b  0  0
  d  0  1

, ,  = 4

  
    v1 v2
  a  0  0
  b  1  0
  d  0  0

, ,  = 5

  
    v1 v2
  a  0  0
  b  0  0
  d  1  0

, ,  = 7

  
    v1 v2
  a  0  1
  b  0  0
  d  0  0

, ,  = 8

  
    v1 v2
  a  0  0
  b  0  1
  d  0  0

, ,  = 9

  
    v1 v2
  a  1  0
  b  0  0
  d  0  0

SIncerely yours



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-built-a-pivot-table-of-value-tp4651539.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.


[R] Daily Time Series, patterns.

2012-12-01 Thread mekbatub
Hi.

I would like to ask You for help:

I am new in R and i use R for forecasting, i have problem. I am trying to
build daily time series:

My data looks like this:

Date|   quantity

...
2012-11-01 | 142
2012-11-02 | 156
2012-11-05 | 151
2012-11-06 | 121
2012-11-07 | 118
2012-11-08 | 119
2012-11-11 | 160
...

My goal in general is to build time series, and to find 7-day patterns,
decompose data and forecast.

I dont know how tu use dates to build daily time series (to convert that
dates, that would be good for time series functions), notice that there is
missing data on certain days (like weekends, or days when warehouse was
closed, so there was no releases) so I cant just use rep function to build
replacement for dates like 1-5, start from...

How would You do this?

Sorry for my english, if there is something more to explain, just tell me.





--
View this message in context: 
http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569.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] Daily Time Series, patterns.

2012-12-01 Thread mekbatub
Hi Arun, thx for Your reply.

thats interesting, but its not what I mean.

I know that there is some patterns in data, example:

the highest value of the sale is on Monday, and the smallest on Wednesday
and so on, there might be trend also

I am trying to build forecasting model that will include patterns like that,
for example forecast to next 5 days. So i think I can say that is weekly
sesonality, i believe the metod to make correct model is to decompose time
series like there.

http://otexts.com/fppfigs/elecequip_stl.png
http://otexts.com/fppfigs/elecequip_stl.png  

Do You think I am right? In any case, I have big problem to do this in R. 



--
View this message in context: 
http://r.789695.n4.nabble.com/Daily-Time-Series-patterns-tp4651569p4651591.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] Simulation in R

2012-12-01 Thread mboricgs
Hello!

How can I do 100 simulations of length 17 from bivariate  bivariate normal
distribution, if I know all 5 parameters?



--
View this message in context: 
http://r.789695.n4.nabble.com/Simulation-in-R-tp4651578.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] How to re-combine values based on an index?

2012-12-01 Thread Brian Feeny
I am able to split my df into two like so:

dataset - trainset
index - 1:nrow(dataset)
testindex - sample(index, trunc(length(index)*30/100))
trainset - dataset[-testindex,]
testset - dataset[testindex,-1]

So I have the index information, how could I re-combine the data using that 
back into a single df?

I tried what I thought might work, but failed with:

newdataset[testindex] = testset[testindex]
  object 'dataset' not found
newdataset[-testindex] = trainset[-testindex]
  object 'dataset' not found

Brian

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Simulation in R

2012-12-01 Thread Greg Snow
look at functions replicate and mvrnorm functions (the later in the MASS
package).


On Sat, Dec 1, 2012 at 12:02 PM, mboricgs mbori...@hotmail.com wrote:

 Hello!

 How can I do 100 simulations of length 17 from bivariate  bivariate normal
 distribution, if I know all 5 parameters?



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Simulation-in-R-tp4651578.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.




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] How to re-combine values based on an index?

2012-12-01 Thread William Dunlap
 newdataset[testindex] = testset[testindex]
   object 'dataset' not found

Is that really what R printed?  I get
   newdataset[testindex] = testset[testindex]
  Error in newdataset[testindex] = testset[testindex] : 
object 'newdataset' not found
but perhaps you have a different problem.  Copy and paste
(and read) the error message you got.

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 Brian Feeny
 Sent: Saturday, December 01, 2012 8:04 PM
 To: r-help@r-project.org
 Subject: [R] How to re-combine values based on an index?
 
 I am able to split my df into two like so:
 
 dataset - trainset
 index - 1:nrow(dataset)
 testindex - sample(index, trunc(length(index)*30/100))
 trainset - dataset[-testindex,]
 testset - dataset[testindex,-1]
 
 So I have the index information, how could I re-combine the data using that 
 back into a
 single df?
 
 I tried what I thought might work, but failed with:
 
 newdataset[testindex] = testset[testindex]
   object 'dataset' not found
 newdataset[-testindex] = trainset[-testindex]
   object 'dataset' not found
 
 Brian
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 re-combine values based on an index?

2012-12-01 Thread Brian Feeny
Thank you for your response,  here is a better example of what I am trying to 
do:

data(iris)
index_setosa - which(iris$Species == setosa)
iris_setosa - data.frame()
iris_setosa[index_setosa,] -iris[index_setosa,]
iris_others - data.frame()
iris_others[-index_setosa,] - iris[-index_setosa,]

So the idea would be that iris_setosa is a dataframe of size 150, with 50 
observations of setosa,
using their original same indices, and 100 observations of NA.  Likewise 
iris_others would be
100 observations of species besides setosa, using their original indices, and 
there would be 50 NA's.

The above doesn't work.  When I execute it, I am left with iris_setosa having 0 
columns, I wish it to have all 
the original columns of iris.

That said, once I get past the above (being able to split them out and keep 
original indices), I wish to be able to combine
iris_setosa and iris_others so that iris_combined is a data frame with no NA's 
and all the original data.

Does this make sense?  So I am basically taking a dataframe, splitting it based 
on some criteria, and working on the two
split dataframes separately, and then I wish to recombine.

Brian


So at this point, I have iris_setosa a dataframe of size 
On Dec 1, 2012, at 11:34 PM, William Dunlap wrote:

 newdataset[testindex] = testset[testindex]
  object 'dataset' not found
 
 Is that really what R printed?  I get
 newdataset[testindex] = testset[testindex]
  Error in newdataset[testindex] = testset[testindex] : 
object 'newdataset' not found
 but perhaps you have a different problem.  Copy and paste
 (and read) the error message you got.
 
 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 Brian Feeny
 Sent: Saturday, December 01, 2012 8:04 PM
 To: r-help@r-project.org
 Subject: [R] How to re-combine values based on an index?
 
 I am able to split my df into two like so:
 
 dataset - trainset
 index - 1:nrow(dataset)
 testindex - sample(index, trunc(length(index)*30/100))
 trainset - dataset[-testindex,]
 testset - dataset[testindex,-1]
 
 So I have the index information, how could I re-combine the data using that 
 back into a
 single df?
 
 I tried what I thought might work, but failed with:
 
 newdataset[testindex] = testset[testindex]
  object 'dataset' not found
 newdataset[-testindex] = trainset[-testindex]
  object 'dataset' not found
 
 Brian
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 re-combine values based on an index?

2012-12-01 Thread arun
Hi,
?merge(), ?rbind(), or ?join() from library(plyr)
set.seed(5)
trainset-data.frame(ID=1:10,col2=runif(10,0,1))
 dataset - trainset
 trainset-dataset[-testindex,]
testset-dataset[testindex,]
merge(testset,trainset,by=c(ID,col2),all=TRUE)
#   ID  col2
#1   1 0.2002145
#2   2 0.6852186
#3   3 0.9168758
#4   4 0.2843995
#5   5 0.1046501
#6   6 0.7010575
#7   7 0.5279600
#8   8 0.8079352
#9   9 0.9565001
#10 10 0.1104530

You can also do this as:
 newdataset-data.frame(ID=rep(NA,nrow(dataset)),col2=rep(NA,nrow(dataset)))
 newdataset[testindex,]-testset
newdataset[-testindex,]-trainset
 head(newdataset)
#  ID  col2
#1  1 0.2002145
#2  2 0.6852186
#3  3 0.9168758
#4  4 0.2843995
#5  5 0.1046501
#6  6 0.7010575

A.K.




- Original Message -
From: Brian Feeny bfe...@mac.com
To: r-help@r-project.org
Cc: 
Sent: Saturday, December 1, 2012 11:04 PM
Subject: [R] How to re-combine values based on an index?

I am able to split my df into two like so:

dataset - trainset
index - 1:nrow(dataset)
testindex - sample(index, trunc(length(index)*30/100))
trainset - dataset[-testindex,]
testset - dataset[testindex,-1]

So I have the index information, how could I re-combine the data using that 
back into a single df?

I tried what I thought might work, but failed with:

newdataset[testindex] = testset[testindex]
  object 'dataset' not found
newdataset[-testindex] = trainset[-testindex]
  object 'dataset' not found

Brian

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 re-combine values based on an index?

2012-12-01 Thread Berend Hasselman

On 02-12-2012, at 06:06, Brian Feeny wrote:

 Thank you for your response,  here is a better example of what I am trying to 
 do:
 
 data(iris)
 index_setosa - which(iris$Species == setosa)
 iris_setosa - data.frame()
 iris_setosa[index_setosa,] -iris[index_setosa,]
 iris_others - data.frame()
 iris_others[-index_setosa,] - iris[-index_setosa,]
 

Change you example to make it actually do something

data(iris)
index_setosa - which(iris$Species == setosa)
iris_setosa -iris[index_setosa,]
head(iris_setosa)

# iris_others - data.frame()
# iris_others[-index_setosa,] - iris[-index_setosa,]
iris_others - iris[-index_setosa,]
head(iris_others)
tail(iris_others)

The head() and tail() calls are for checking.
Combine the two like this

z - rbind(iris_setosa,iris_others)
head(z)
tail(z)

Berend

 So the idea would be that iris_setosa is a dataframe of size 150, with 50 
 observations of setosa,
 using their original same indices, and 100 observations of NA.  Likewise 
 iris_others would be
 100 observations of species besides setosa, using their original indices, and 
 there would be 50 NA's.
 
 The above doesn't work.  When I execute it, I am left with iris_setosa having 
 0 columns, I wish it to have all 
 the original columns of iris.
 
 That said, once I get past the above (being able to split them out and keep 
 original indices), I wish to be able to combine
 iris_setosa and iris_others so that iris_combined is a data frame with no 
 NA's and all the original data.
 
 Does this make sense?  So I am basically taking a dataframe, splitting it 
 based on some criteria, and working on the two
 split dataframes separately, and then I wish to recombine.
 
 Brian
 
 
 So at this point, I have iris_setosa a dataframe of size 
 On Dec 1, 2012, at 11:34 PM, William Dunlap wrote:
 
 newdataset[testindex] = testset[testindex]
 object 'dataset' not found
 
 Is that really what R printed?  I get
 newdataset[testindex] = testset[testindex]
 Error in newdataset[testindex] = testset[testindex] : 
   object 'newdataset' not found
 but perhaps you have a different problem.  Copy and paste
 (and read) the error message you got.
 
 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 Brian Feeny
 Sent: Saturday, December 01, 2012 8:04 PM
 To: r-help@r-project.org
 Subject: [R] How to re-combine values based on an index?
 
 I am able to split my df into two like so:
 
 dataset - trainset
 index - 1:nrow(dataset)
 testindex - sample(index, trunc(length(index)*30/100))
 trainset - dataset[-testindex,]
 testset - dataset[testindex,-1]
 
 So I have the index information, how could I re-combine the data using that 
 back into a
 single df?
 
 I tried what I thought might work, but failed with:
 
 newdataset[testindex] = testset[testindex]
 object 'dataset' not found
 newdataset[-testindex] = trainset[-testindex]
 object 'dataset' not found
 
 Brian
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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.