[R] RODBC Excel sqlQuery insert into

2007-03-13 Thread toby_marks
I have searched the archives for using insert into to update spreadsheets 
using RODBC and have come up short. So, first off, is it possible?

I have put together a dummy xls table (c:\foo.xls)for exploring 
possibilities of RODBC.  Ultimately, I am interested in replacing much of 
our previous use of vba macros with R ( I'd prefer elimination, but will 
take what I can get ).  In order to achieve this, I will still have a need 
to update spreadsheets directly through R scripts. 

Simple queries seem to work fantastic!  But, I am missing something when 
it comes to writing.

sqlQuery( myChan,insert into [my customers$] ( CUST_ID, NAME, SOCIAL ) 
VALUES( 5,'robin',5678 )  )
[1] [RODBC] ERROR: Could not SQLExecDirect  S1000 -3035 
[Microsoft][ODBC Excel Driver] Operation must use an updateable query.


myChan = odbcConnectExcel(c:\\foo.xls)
myChan
RODB Connection 13
Details:
  case=nochange
  DBQ=c:\foo.xls
  DefaultDir=c:\
  Driver={Microsoft Excel Driver (*.xls)}
  DriverId=790
  MaxBufferSize=2048
  PageTimeout=5

sqlTables(myChan)
  TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS
1   c:\\fooNA 'my customers orders$'  TABLENA
2   c:\\fooNA'my customers$'  TABLENA
3   c:\\fooNA 'my products$'  TABLENA
4   c:\\fooNA  'poor table$'  TABLENA

sqlQuery(myChan,select * from [my customers$] )
  CUST_IDNAME SOCIALDOB
1   1superman   1234 1940-12-31
2   2  batman   2345 1960-01-01
3   3 wonderwoman   3456 1942-05-15
4   4   spiderman   4567 1982-09-30

sqlQuery(myChan,select * from [my customers orders$] )
  ORDER_ID CUST_ID   DATE PRODUCT_ID QUANTITY
11   3 1997-08-13  1   12
22   3 1998-07-23  7   24
33   1 1994-01-08  6   11
44   4 2001-11-13  5   32
55   2 1997-03-09  79

sqlQuery(myChan,select * from [my products$] )
  PRODUCT_ID PRODUCT_NAME
1  1 cape
2  2 mask
3  3   tights
4  4boots
5  5  goggles
6  6   gloves
7  7  aspirin
sqlQuery(myChan,select * from [poor table$] )
  a bunch of stuff F2  F3  F4   F5F6
1   NA NA  NANA NANA
2   NA NA  NANA NANA
3   NA NA  NA data_i_like more data I likeNA
4   NA NA 100blue  hot  94.16857
5   NA NA 200 red warm  35.85302
6   NA NA 300   green cold 232.09150
7   NA NA 400blue cold  45.40191

sqlQuery(myChan,select * from [my customers$] A, [my customers orders$] B 
where A.CUST_ID = B.CUST_ID AND A.SOCIAL  3000, as.is=TRUE) 
  CUST_IDNAME SOCIAL DOB ORDER_ID CUST_ID  DATE 
PRODUCT_ID QUANTITY
1   3 wonderwoman   3456 1942-05-15 00:00:002   3 
1998-07-23 00:00:00  7   24
2   3 wonderwoman   3456 1942-05-15 00:00:001   3 
1997-08-13 00:00:00  1   12
3   4   spiderman   4567 1982-09-30 00:00:004   4 
2001-11-13 00:00:00  5   32
$

f = sqlQuery( myChan,insert into [my customers$] ( CUST_ID, NAME, SOCIAL 
) VALUES( 5,'robin',5678 )  )

[1] [RODBC] ERROR: Could not SQLExecDirect   S1000 -3035 
[Microsoft][ODBC Excel Driver] Operation must use an updateable query.

Additional reference: 
http://www.microsoft.com/technet/scriptcenter/resources/officetips/jun05/tips0607.mspx


CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

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


Re: [R] RODBC Excel sqlQuery insert into

2007-03-13 Thread toby_marks
I do recall seeing posts on RDOM flying around from time to time and today 
have stumbled across as well through my RODBC  searches.  I have also been 
reminded from another reply of RCOM being a potential solution.  I had 
hoped to stick to more of a pure sql based process, but certainly R makes 
it easy to change course when necessary.  I shall do some digging into 
each of these packages now as well.  Thanks for the response!

--Cheers.





James W. MacDonald [EMAIL PROTECTED] 
03/13/2007 02:05 PM





To
[EMAIL PROTECTED]
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] RODBC Excel sqlQuery  insert into






Hi Toby,

[EMAIL PROTECTED] wrote:
 I have searched the archives for using insert into to update 
spreadsheets 
 using RODBC and have come up short. So, first off, is it possible?

I don't think so. Writing to an Excel spreadsheet is probably easier 
done using the RDCOMClient package. There are some good examples of how 
to do things that come with the package. Searching the R-help archives 
should also come up with some good examples.

Best,

Jim




-- 
James W. MacDonald, M.S.
Biostatistician
Affymetrix and cDNA Microarray Core
University of Michigan Cancer Center
1500 E. Medical Center Drive
7410 CCGC
Ann Arbor MI 48109
734-647-5623


**
Electronic Mail is not secure, may not be read every day, and should not 
be used for urgent or sensitive issues.



CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Matrix multiplication using apply() or lappy() ?

2006-09-06 Thread toby_marks
I am trying to divide the columns of a matrix by the first row in the 
matrix.

I have tried to get this using apply and I seem to be missing a concept 
regarding the apply w/o calling a function but rather command args %*% / 
etc.  Would using apply be more efficient than this approach? 

I have observed examples in the archives using this type of approach. Does 
anybody have a snippet of a call to apply() that would accomplish this as 
well?

Thanks!


seed=50
$a = array(rnorm(20),dim=c(4,5))
$b = matrix(a[1,],dim(a)[1],dim(a)[2],byrow=T)
$a
   [,1]   [,2]   [,3][,4]   [,5]
[1,] -1.3682810 -0.4314462 1.57572752  0.67928882 -0.3672346
[2,]  0.4328180  0.6556479 0.64289931  0.08983289  0.1852306
[3,] -0.8113932  0.3219253 0.08976065 -2.99309008  0.5818237
[4,]  1.4441013 -0.7838389 0.27655075  0.28488295  1.3997368

$a/b
   [,1]   [,2]   [,3]   [,4]  [,5]
[1,]  1.000  1.000 1.  1.000  1.00
[2,] -0.3163225 -1.5196515 0.40800157  0.1322455 -0.504393
[3,]  0.5930018 -0.7461539 0.05696457 -4.4062113 -1.584338
[4,] -1.0554128  1.8167710 0.17550671  0.4193841 -3.811560




CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] Matrix multiplication using apply() or lappy() ?

2006-09-06 Thread toby_marks
The apply was exactly what I was after.  And, I will check out the others 
as well.  great tips!




Gabor Grothendieck [EMAIL PROTECTED] 
09/06/2006 11:11 AM





To
[EMAIL PROTECTED] [EMAIL PROTECTED]
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] Matrix multiplication using apply() or lappy() ?






This last one could also be written slightly shorter as:

t(apply(a, 1, /, a[1,]))

On 9/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote:
 And here is one more:

 t(apply(a, 1, function(x) x/a[1,]))

 On 9/6/06, Gabor Grothendieck [EMAIL PROTECTED] wrote:
  Here are a few possibilities:
 
  a - matrix(1:24, 4) # test data
 
  a / rep(a[1,], each = 4)
 
  a / outer(rep(1, nrow(a)), a[1,])
 
  a %*% diag(1/a[1,])
 
  sweep(a, 2, a[1,], /)
 
 
  On 9/6/06, [EMAIL PROTECTED]
  [EMAIL PROTECTED] wrote:
   I am trying to divide the columns of a matrix by the first row in 
the
   matrix.
  
   I have tried to get this using apply and I seem to be missing a 
concept
   regarding the apply w/o calling a function but rather command args 
%*% /
   etc.  Would using apply be more efficient than this approach?
  
   I have observed examples in the archives using this type of 
approach. Does
   anybody have a snippet of a call to apply() that would accomplish 
this as
   well?
  
   Thanks!
  
  
   seed=50
   $a = array(rnorm(20),dim=c(4,5))
   $b = matrix(a[1,],dim(a)[1],dim(a)[2],byrow=T)
   $a
 [,1]   [,2]   [,3][,4]   [,5]
   [1,] -1.3682810 -0.4314462 1.57572752  0.67928882 -0.3672346
   [2,]  0.4328180  0.6556479 0.64289931  0.08983289  0.1852306
   [3,] -0.8113932  0.3219253 0.08976065 -2.99309008  0.5818237
   [4,]  1.4441013 -0.7838389 0.27655075  0.28488295  1.3997368
  
   $a/b
 [,1]   [,2]   [,3]   [,4]  [,5]
   [1,]  1.000  1.000 1.  1.000  1.00
   [2,] -0.3163225 -1.5196515 0.40800157  0.1322455 -0.504393
   [3,]  0.5930018 -0.7461539 0.05696457 -4.4062113 -1.584338
   [4,] -1.0554128  1.8167710 0.17550671  0.4193841 -3.811560
  
  
  
   
   CONFIDENTIALITY NOTICE: This electronic mail transmission 
(i...{{dropped}}
  
   __
   R-help@stat.math.ethz.ch mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
 




CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] cumulative growth rates indexed to a common starting point over n series of observations

2006-09-01 Thread toby_marks
Perfect, the apply was exactly what I was after,  just wasn't clicking 
with me, and I overlooked the cumprod ...  sweet !

Thanks to all for pushing me down the right path!





Dirk Eddelbuettel [EMAIL PROTECTED] 
08/31/2006 05:03 PM





To
[EMAIL PROTECTED]
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] cumulative growth rates indexed to a common starting point over n 
series of observations







On 31 August 2006 at 15:22, [EMAIL PROTECTED] wrote:
| What is the R way of computing cumulative growth rates given a series of 

| discrete values indexed .
| 
| For instance, given a matrix of 20 observations for each of 5 series 
(zz), 
| what is the most straight forward technique in R for computing 
cumulative 
| growth (zzcum) ?
| It seems for the solution I'm after might be imbedding the following cum 

| growth rate calc as a function into a function call to apply, mapply, 
...? 
| 
| 
| 
| zz = rnorm(100)
| dim(zz) = c(20,5)
| zz
| zzcum=matrix(nrow=20,ncol=5)
| zzcum
| zzcum[1,]=100*(1+zz[1,]/100)
| zzcum
| for(i in 2:20){zzcum[i,] = zzcum[i-1,]*(1+zz[i,]/100)}
| zzcum

How about cumprod() inside apply() ?

 zzcum - matrix(rnorm(100), ncol=5)
 apply(zzcum/100 + 1, 2, cumprod)

Hth, Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
  -- Thomas A. Edison



CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] cumulative growth rates indexed to a common starting point over n series of observations

2006-09-01 Thread toby_marks
The apply with the cumprod was exactly what I was after.  The apply just 
wasn't clicking with me, and I had overlooked the cumprod.  Thanks to all 
for pushing me down the right path!

Actually, what I am ultimately after is a way to link this series, without 
having to use a for loop ( the only way I can think of ... ).  But, would 
like to see if it can be linked  using mapply or apply against the rows 
and to compute the linked results. 

zz = matrix(rnorm(20), ncol=2)
zzcum = apply(zz/100 + 1, 2, cumprod)
zzlinkcum = 100*zzcum
for(i in 2:length(zz[,1])){ zzlinkcum[i,]=zzlinkcum[i-1,]*zzcum[i,]}  ### 
Is there a better way here ?

zz
[,1]   [,2]
 [1,]  0.8563323 -0.3895789
 [2,]  0.8311070 -0.7483010
 [3,]  0.3526344 -1.1702419
 [4,]  1.1105516  0.5238831
 [5,]  0.6471324 -0.1419063
 [6,] -0.9821008  0.8378471
 [7,]  1.6799099  1.7025973
 [8,] -0.1904968 -2.9203921
 [9,]  0.4218418  0.4799355
[10,] -0.5989616 -1.2121375

zzcum

 [,1] [,2]
 [1,] 1.007118 1.001036
 [2,] 1.011022 1.011093
 [3,] 1.007719 1.023287
 [4,] 1.026238 1.030673
 [5,] 1.031242 1.023557
 [6,] 1.029199 1.021431
 [7,] 1.044428 1.017244
 [8,] 1.034568 1.026164
 [9,] 1.032941 1.024926
[10,] 1.032490 1.026172

zzlinkcum
  [,1] [,2]
 [1,] 100.7118 100.1036
 [2,] 101.8219 101.2140
 [3,] 102.6078 103.5711
 [4,] 105.3000 106.7479
 [5,] 108.5898 109.2626
 [6,] 111.7605 111.6042
 [7,] 116.7259 113.5287
 [8,] 120.7608 116.4990
 [9,] 124.7388 119.4028
[10,] 128.7916 122.5278










Dirk Eddelbuettel [EMAIL PROTECTED] 
08/31/2006 05:03 PM





To
[EMAIL PROTECTED]
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] cumulative growth rates indexed to a common starting point over n 
series of observations







On 31 August 2006 at 15:22, [EMAIL PROTECTED] wrote:
| What is the R way of computing cumulative growth rates given a series of 

| discrete values indexed .
| 
| For instance, given a matrix of 20 observations for each of 5 series 
(zz), 
| what is the most straight forward technique in R for computing 
cumulative 
| growth (zzcum) ?
| It seems for the solution I'm after might be imbedding the following cum 

| growth rate calc as a function into a function call to apply, mapply, 
...? 
| 
| 
| 
| zz = rnorm(100)
| dim(zz) = c(20,5)
| zz
| zzcum=matrix(nrow=20,ncol=5)
| zzcum
| zzcum[1,]=100*(1+zz[1,]/100)
| zzcum
| for(i in 2:20){zzcum[i,] = zzcum[i-1,]*(1+zz[i,]/100)}
| zzcum

How about cumprod() inside apply() ?

 zzcum - matrix(rnorm(100), ncol=5)
 apply(zzcum/100 + 1, 2, cumprod)

Hth, Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
  -- Thomas A. Edison



CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] cumulative growth rates indexed to a common starting point over n series of observations

2006-09-01 Thread toby_marks
That is choice !I'm starting to love this language. Thank-you !





Dirk Eddelbuettel [EMAIL PROTECTED] 
09/01/2006 02:59 PM





To
[EMAIL PROTECTED]
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] cumulative growth rates indexed to a common starting point over n 
series of observations







On 1 September 2006 at 14:30, [EMAIL PROTECTED] wrote:
| The apply with the cumprod was exactly what I was after.  The apply just 

| wasn't clicking with me, and I had overlooked the cumprod.  Thanks to 
all 
| for pushing me down the right path!
| 
| Actually, what I am ultimately after is a way to link this series, 
without 
| having to use a for loop ( the only way I can think of ... ).  But, 
would 
| like to see if it can be linked  using mapply or apply against the rows 
| and to compute the linked results. 
| 
| zz = matrix(rnorm(20), ncol=2)
| zzcum = apply(zz/100 + 1, 2, cumprod)
| zzlinkcum = 100*zzcum
| for(i in 2:length(zz[,1])){ zzlinkcum[i,]=zzlinkcum[i-1,]*zzcum[i,]} ### 

| Is there a better way here ?

Sure, why not call apply again?

 set.seed(42); zz - matrix(rnorm(20), ncol=2)
 zzcum - apply(1+zz/100, 2, cumprod)
 apply(rbind(c(1,1), zzcum), 2, cumprod)*100
  [,1] [,2]
 [1,] 100. 100.
 [2,] 101.3710 101.3049
 [3,] 102.1804 104.9735
 [4,] 103.3704 107.2642
 [5,] 105.2360 109.2994
 [6,] 107.5684 111.2246
 [7,] 109.8358 113.9036
 [8,] 113.8461 116.3156
 [9,] 117.8912 115.6233
[10,] 124.5442 112.1301
[11,] 131.4900 110.1781
 

Hth, Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
  -- Thomas A. Edison



CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] cumulative growth rates indexed to a common starting point over n series of observations

2006-09-01 Thread toby_marks
Yes I do.   I was still scratching my head still trying to figure out why 
I couldn't get my actual #s to match the example from the random series. 
This now matches my brute force calcs.


btw:
Also had a former colleague and good friend suggest this could be done 
using ranges.  Which opened my eyes as well, although I haven't tested 
yet.   But I do think the apply approach is more elegant.
from my original post...

zz = matrix(rnorm(20), ncol=2)
zzcum = apply(zz/100 + 1, 2, cumprod) 
zzlinkcum = 100*zzcum 
zzlinkcum[2:length(zz[,1]),] - 
zzlinkcum[1:(length(zz[,1])-1),]*zzcum[2:length(zz[,1]),]

Thanks so much for al the help ! 







Dirk Eddelbuettel [EMAIL PROTECTED] 
09/01/2006 02:59 PM





To
[EMAIL PROTECTED]
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] cumulative growth rates indexed to a common starting point over n 
series of observations







On 1 September 2006 at 14:30, [EMAIL PROTECTED] wrote:
| The apply with the cumprod was exactly what I was after.  The apply just 

| wasn't clicking with me, and I had overlooked the cumprod.  Thanks to 
all 
| for pushing me down the right path!
| 
| Actually, what I am ultimately after is a way to link this series, 
without 
| having to use a for loop ( the only way I can think of ... ).  But, 
would 
| like to see if it can be linked  using mapply or apply against the rows 
| and to compute the linked results. 
| 
| zz = matrix(rnorm(20), ncol=2)
| zzcum = apply(zz/100 + 1, 2, cumprod)
| zzlinkcum = 100*zzcum
| for(i in 2:length(zz[,1])){ zzlinkcum[i,]=zzlinkcum[i-1,]*zzcum[i,]} ### 

| Is there a better way here ?

Sure, why not call apply again?

 set.seed(42); zz - matrix(rnorm(20), ncol=2)
 zzcum - apply(1+zz/100, 2, cumprod)
 apply(rbind(c(1,1), zzcum), 2, cumprod)*100
  [,1] [,2]
 [1,] 100. 100.
 [2,] 101.3710 101.3049
 [3,] 102.1804 104.9735
 [4,] 103.3704 107.2642
 [5,] 105.2360 109.2994
 [6,] 107.5684 111.2246
 [7,] 109.8358 113.9036
 [8,] 113.8461 116.3156
 [9,] 117.8912 115.6233
[10,] 124.5442 112.1301
[11,] 131.4900 110.1781
 

Hth, Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
  -- Thomas A. Edison



CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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] cumulative growth rates indexed to a common starting point over n series of observations

2006-08-31 Thread toby_marks
What is the R way of computing cumulative growth rates given a series of 
discrete values indexed .

For instance, given a matrix of 20 observations for each of 5 series (zz), 
what is the most straight forward technique in R for computing cumulative 
growth (zzcum) ?
It seems for the solution I'm after might be imbedding the following cum 
growth rate calc as a function into a function call to apply, mapply, ...? 



zz = rnorm(100)
dim(zz) = c(20,5)
zz
zzcum=matrix(nrow=20,ncol=5)
zzcum
zzcum[1,]=100*(1+zz[1,]/100)
zzcum
for(i in 2:20){zzcum[i,] = zzcum[i-1,]*(1+zz[i,]/100)}
zzcum






CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/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 needed understanding eval,quote,expression

2006-06-29 Thread toby_marks
I am trying to build up a quoted or character expression representing a 
component in a list  in order to reference it indirectly. 
For instance, I have a list that has data I want to pull, and another list 
that has character vectors and/or lists of characters containing the names 
of the components in the first list.


It seems that the way to do this is as evaluating expressions, but I seem 
to be missing something.  The concept should be similar to the snippet 
below:


For instance:

$x = list(y=list(y1=hello,y2=world),z=list(z1=foo,z2=bar))
$y = quote(x$y$y1)
$eval(y)
[1] hello


but, I'm trying to accomplish this by building up y as a character and 
then evaluating it, and having no success. 

$y1=paste(x$y$,y1,sep=)
$y1
[1] x$y$y1


How can I evaluate y1 as I did with y previously?  or can I? 


Much Thanks !









CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Help needed understanding eval,quote,expression

2006-06-29 Thread toby_marks
Great help,  thanks to both of you.  I actually think I get it. 

I think I was locked into eval(expression  ... ) as the solution.  I did 
search the archives for this question, but it must not have clicked with 
me.The  Thomas Lumley R-help (February 2005) was on the money.  I was 
missing the power  flexibility of the [[ operation.  It is certainly more 
direct.

I do believe this pattern will satisfy my original problem.

 x = list(y=list(y1=hello,y2=world),z=list(z1=foo,z2=bar))
 ids = list( zIds=c(z1,z2),yIds=c(y1,y2))
 str=y1
 x$y[[str]]
[1] hello


btw:  I set my prompt to $, so the first post, the $ at the beginning of 
the line was the prompt.  apologies for the confusion.


cheers.





Prof Brian Ripley [EMAIL PROTECTED] 
06/29/2006 04:06 AM





To
Joerg van den Hoff [EMAIL PROTECTED]
cc
[EMAIL PROTECTED], r-help@stat.math.ethz.ch
Subject
Re: [R] Help needed understanding eval,quote,expression






On Thu, 29 Jun 2006, Joerg van den Hoff wrote:

 Prof Brian Ripley wrote:
 You are missing eval(parse(text=)). E.g.
 
 x - list(y=list(y1=hello,y2=world),z=list(z1=foo,z2=bar))
 (what do you mean by the $ at the start of these lines?)
 eval(parse(text=x$y$y1))
 [1] hello
 
 However, bear in mind
 
 fortune(parse)
 
 If the answer is parse() you should usually rethink the question.
 -- Thomas Lumley
R-help (February 2005)
 
 In your indicated example you could probably use substitute() as 
 effectively.
 
 
 On Wed, 28 Jun 2006, [EMAIL PROTECTED] wrote:
 
 I am trying to build up a quoted or character expression representing 
a
 component in a list  in order to reference it indirectly.
 For instance, I have a list that has data I want to pull, and another 
list
 that has character vectors and/or lists of characters containing the 
names
 of the components in the first list.
 
 It seems that the way to do this is as evaluating expressions, but I 
seem
 to be missing something.  The concept should be similar to the snippet
 below:
 
 
 For instance:
 
 $x = list(y=list(y1=hello,y2=world),z=list(z1=foo,z2=bar))
 $y = quote(x$y$y1)
 $eval(y)
 [1] hello
 
 
 but, I'm trying to accomplish this by building up y as a character and
 then evaluating it, and having no success.
 
 $y1=paste(x$y$,y1,sep=)
 $y1
 [1] x$y$y1
 
 
 How can I evaluate y1 as I did with y previously?  or can I?
 
 
 Much Thanks !
 
 

 if I understand you correctly you can achieve your goal much easier than 
with 
 eval, parse, substitute and the like:

 x - list(y=list(y1=hello,y2=world),z=list(z1=foo,z2=bar))

 s1 - 'y'
 s2 - 'y1'

 x[[s1]][[s2]]

 i.e. using `[[' instead of `$' for list component extraction allows to 
use 
 characters for indexing (in other words: x$y == x[['y']])


But what he actually asked for was

 I am trying to build up a quoted or character expression representing 
a
 component in a list  in order to reference it indirectly.

You just typed in x[[s1]][[s2]], not 'built [it] up'.  Suppose the 
specification had been

r - x
s - c(y, y1)

and s was of variable length?  Then you need to construct a call similar 
to x[[y]][[y1]] from r and s.

[There was another reason for sticking with $ rather than using [[: the 
latter makes unnecessary copies in released versions of R.]


-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595



CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Help needed using lattice for area plots lpolygon, xyplot.

2006-06-07 Thread toby_marks
I am trying to learn how to use the graphics from the lattice package ( 
and am very new to R). 

I am trying to replicate the example plot referenced below, by using the 
lattice xyplot  lpolygon to create panels.  I get what appears to be the 
correct shape of the filled region, but cannot get the position to overlay 
properly.  I have attempted with various settings of position.  ( i.e. 
position = c(0,0,1,1)  etc settings as well.   I am not understanding 
something about the positioning panels.  I am missing some subtle 
difference between polygon  lpolygon, or am missing something about panel 
overlays /or panel postions.

#http://addictedtor.free.fr/graphiques/graphcode.php?graph=7. 
par(bg=white) 
n - 100
set.seed(43214) #just so we have the same exact graph
x - c(0,cumsum(rnorm(n))) 
y - c(0,cumsum(rnorm(n))) 
xx - c(0:n, n:0)
yy - c(x, rev(y)) 
plot(xx, yy, type=n, xlab=Time, ylab=Distance) 
polygon(xx, yy, col=gray) 
title(Distance Between Brownian Motions) 



# using lattice.
p1 - xyplot( yy~xx,type='l');
p2 - lpolygon(xx,yy,col='blue');
print(p1,position=c(0,0,1,1), more=TRUE);
print(p2,position=c(0,0,1,1));






CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Fw: Help needed using lattice for area plots lpolygon, xyplot.

2006-06-07 Thread toby_marks
I am trying to learn how to use the graphics from the lattice package ( 
and am very new to R). 

I am trying to replicate the example plot referenced below, by using the 
lattice xyplot  lpolygon to create panels.  I get what appears to be the 
correct shape of the filled region, but cannot get the position to overlay 
properly.  I have attempted with various settings of position.  ( i.e. 
position = c(0,0,1,1)  etc settings as well.   I am not understanding 
something about the positioning panels.  I am missing some subtle 
difference between polygon  lpolygon, or am missing something about panel 
overlays /or panel postions.

#http://addictedtor.free.fr/graphiques/graphcode.php?graph=7. 
par(bg=white) 
n - 100
set.seed(43214) #just so we have the same exact graph
x - c(0,cumsum(rnorm(n))) 
y - c(0,cumsum(rnorm(n))) 
xx - c(0:n, n:0)
yy - c(x, rev(y)) 
plot(xx, yy, type=n, xlab=Time, ylab=Distance) 
polygon(xx, yy, col=gray) 
title(Distance Between Brownian Motions) 



# using lattice.
p1 - xyplot( yy~xx,type='l');
p2 - lpolygon(xx,yy,col='blue');
print(p1,position=c(0,0,1,1), more=TRUE);
print(p2,position=c(0,0,1,1));






CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Fw: Help needed using lattice for area plots lpolygon, xyplot.

2006-06-07 Thread toby_marks
Perfect.  Thank-you!



Deepayan Sarkar [EMAIL PROTECTED] 
06/07/2006 11:19 AM





To
[EMAIL PROTECTED] [EMAIL PROTECTED]
cc
r-help@stat.math.ethz.ch
Subject
Re: [R] Fw: Help needed using lattice for area plots lpolygon, xyplot.






On 6/7/06, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 I am trying to learn how to use the graphics from the lattice package (
 and am very new to R).

 I am trying to replicate the example plot referenced below, by using the
 lattice xyplot  lpolygon to create panels.  I get what appears to be 
the
 correct shape of the filled region, but cannot get the position to 
overlay
 properly.  I have attempted with various settings of position.  ( i.e.
 position = c(0,0,1,1)  etc settings as well.   I am not understanding
 something about the positioning panels.  I am missing some subtle
 difference between polygon  lpolygon, or am missing something about 
panel
 overlays /or panel postions.

 #http://addictedtor.free.fr/graphiques/graphcode.php?graph=7.
 par(bg=white)
 n - 100
 set.seed(43214) #just so we have the same exact graph
 x - c(0,cumsum(rnorm(n)))
 y - c(0,cumsum(rnorm(n)))
 xx - c(0:n, n:0)
 yy - c(x, rev(y))
 plot(xx, yy, type=n, xlab=Time, ylab=Distance)
 polygon(xx, yy, col=gray)
 title(Distance Between Brownian Motions)



 # using lattice.
 p1 - xyplot( yy~xx,type='l');
 p2 - lpolygon(xx,yy,col='blue');
 print(p1,position=c(0,0,1,1), more=TRUE);
 print(p2,position=c(0,0,1,1));

You are missing a fundamental concept in lattice, namely that of panel
functions. A literal translation of that example would be

xyplot(yy ~ xx, panel = lpolygon, col = gray)

which is more or less equivalent to

xyplot(yy ~ xx,
   panel = function(x, y, ...) {
   # panel.xyplot(x, y, ...) # unnecessary
   lpolygon(x, y, col = gray)
   })

The line commented out is the equivalent of plot(...type='n'), but is
unnecessary here.

Deepayan



CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html