Re: [R] detecting any element in a vector of strings, appearing anywhere in any of several character variables in a dataframe

2015-07-10 Thread Christopher W Ryan
Thanks everyone.  John's original solution worked great.  And with
27,000 records, 65 alarm.words, and 6 columns to search, it takes only
about 15 seconds.  That is certainly adequate for my needs.  But I
will try out the other strategies too.

And thanks also for lot's of new R things to learn--grep, grepl,
do.call . . . that's always a bonus!

--Chris Ryan

On Thu, Jul 9, 2015 at 1:52 PM, Bert Gunter bgunter.4...@gmail.com wrote:
 Yup, that does it. Let grep figure out what's a word rather than doing
 it manually. Forgot about \b

 Cheers,
 Bert


 Bert Gunter

 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
-- Clifford Stoll


 On Thu, Jul 9, 2015 at 10:30 AM, Jeff Newmiller
 jdnew...@dcn.davis.ca.us wrote:
 Just add a word break marker before and after:

 zz$v5 - grepl( paste0( \\b(, paste0( alarm.words, collapse=| ), )\\b 
 ), do.call( paste, zz[ , 2:3 ] ) ) )
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 On July 9, 2015 10:12:23 AM PDT, Bert Gunter bgunter.4...@gmail.com wrote:
Jeff:

Well, it would be much better (no loops!) except, I think, for one
issue: red would match barred and I don't think that this is what
is wanted: the matches should be on whole words not just string
patterns.

So you would need to fix up the matching pattern to make this work,
but it may be a little tricky, as arbitrary whitespace characters,
e.g.   or \n etc. could be in the strings to be matched separating
the words or ending the sentence.  I'm sure it can be done, but I'll
leave it to you or others to figure it out.

Of course, if my diagnosis is wrong or silly, please point this out.

Cheers,
Bert


Bert Gunter

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
   -- Clifford Stoll


On Thu, Jul 9, 2015 at 9:34 AM, Jeff Newmiller
jdnew...@dcn.davis.ca.us wrote:
 I think grep is better suited to this:

 zz$v5 - grepl( paste0( alarm.words, collapse=| ), do.call( paste,
zz[ , 2:3 ] ) ) )

---
 Jeff NewmillerThe .   .  Go
Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
Go...
   Live:   OO#.. Dead: OO#..
Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.
rocks...1k

---
 Sent from my phone. Please excuse my brevity.

 On July 9, 2015 8:51:10 AM PDT, Bert Gunter bgunter.4...@gmail.com
wrote:
Here's a way to do it that uses %in% (i.e. match() ) and uses only a
single, not a double, loop. It should be more efficient.

 sapply(strsplit(do.call(paste,zz[,2:3]),[[:space:]]+),
+   function(x)any(x %in% alarm.words))

 [1] FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE

The idea is to paste the strings in each row (do.call allows an
arbitrary number of columns) into a single string and then use
strsplit to break the string into individual words on whitespace.
Then the matching is vectorized with the any( %in% ... ) call.

Cheers,
Bert
Bert Gunter

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
   -- Clifford Stoll


On Thu, Jul 9, 2015 at 6:05 AM, John Fox j...@mcmaster.ca wrote:
 Dear Chris,

 If I understand correctly what you want, how about the following?

 rows - apply(zz[, 2:3], 1, function(x) any(sapply(alarm.words,
grepl, x=x)))
 zz[rows, ]

   v1  v2v3 v4
 3  -1.022329green turtleronald weasley  2
 6   0.336599  waffle the hamsterred sparks  1
 9  -1.631874 yellow giraffe with a long neck gandalf the white  1
 10  1.130622  black bear  gandalf the grey  2

 I hope this helps,
  John

 
 John Fox, Professor
 McMaster University
 Hamilton, Ontario, Canada
 http://socserv.mcmaster.ca/jfox/


 On Wed, 08 Jul 2015 22:23:37 -0400
  Christopher W. Ryan cr...@binghamton.edu wrote:
 Running R 3.1.1 on windows 7

 I want to identify as a case any record in a dataframe that
contains
any
 of several keywords in any of several variables.

 Example:

 # create a dataframe with 4 variables and 10 records
 v2 - c(white bird, blue bird, green turtle, quick brown

Re: [R] sum some columns for each row

2015-07-10 Thread Jim Lemon
Hi Dawn,
Your data are a bit messed up, but try the following:

colSums(dat[,grep(ABC,names(dat),fixed=TRUE)],na.rm=TRUE)
colSums(dat[,grep(XYZ,names(dat),fixed=TRUE)],na.rm=TRUE)

I'm assuming that you want to discard the NA values.

Jim

On Fri, Jul 10, 2015 at 6:52 AM, Rui Barradas ruipbarra...@sapo.pt wrote:
 Hello,

 Please use ?dput to give a data example, like this it's completely
 unreadable. If your data.frame is named 'dat' use

 dput(head(dat, 30))  # paste the outut of this in your mail


 And don't post in html, use plain text only, like the posting guide says.

 Rui Barradas


 Em 09-07-2015 18:12, Dawn escreveu:

 Hi,

 I have a big dataframe as follows

  109ABC109XYZ18ABC18XYZ22XYZ23ABC25ABC
 25XYZ
 30ABC31XYZ32ABC32XYZ34DCM34XYZ36ABC36SUR
 38DCM38XYZ39DCM39SUR41DCM41SUR42DCM42SUR
 46SUR52DCM64ABC64XYZ65ABC65XYZ66ABC66XYZ
 67XYZ68ABC68SUR70MES70SUR72ABC72XYZ76ABC
 76XYZ82ABC85ABCPOV
 Cluster_1171
 310145221112
  2TT:61
 Cluster_21420
 653699610131
  4TT:88
 Cluster_3336417
 1718131719221152185184
 79
 TT:227
 

 I want to get two columns, i.e,  one is to sum columns for all including
 ABC for each row and the other is  to sum columns for all including XYZ
 for
 each row.

 Is there some help? Thank you!
 Dawn

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] color2D.matplot with anchored color scale

2015-07-10 Thread Jim Lemon
Hi Phong,
This is a common problem with using color to represent numeric values.
What you want is a reference scale. Whenever you call color2D.matplot,
use the cellcolors argument to specify the colors of each cell. You
can directly call color.scale in this argument, using the xrange
argument of that function to ensure that the colors returned are
calculated for the full range:

color.scale(...,xrange=c(0,40),...)

Look at the second example in the help page for barp to see how this
is done. Notice that it doesn't matter that the actual data are in
proportions (0 to 1) and the legend is labelled in percentages (0 to
100). The data values are correctly colored for the entire scale,
although none of these values are at the endpoints.

Jim


On Fri, Jul 10, 2015 at 12:22 PM, Phong Nguyen xphon...@gmail.com wrote:
 Hello Jim,

 I have a several matrices stored in allGrid - list()

 I am using:

   color2D.matplot(grid, extremes = c(green, red), vcol = black,
 nslices = 60, show.legend=TRUE,axes=FALSE,show.values=TRUE,
 xlab=Columns,ylab=Rows)

 for each of grid in allGrid. Each grid is a matrix with element range
 from 0 to max number of allGrid, say 40.

 I want to plot many grid with color represents the number (density). But I
 cannot fix the color scale and anchor the maximum value to a fixed number.

 I have tried many things but nothing works.

 Just the extra is: I cannot make the color from green (small number) -
 yellow (middle number) - red (big number). Sometimes, the plot turns black
 and white.

 Please help me.

 Phong



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Rich Shepard

On Fri, 10 Jul 2015, David Winsemius wrote:


#Generally one needs to complete a pdf() call with:

dev.off()

# And an empty file is the symptom os such a failure.



David,

  I did leave that off the example file, but it make no difference. The
attached is the compiled example.pdf

Rich

example.pdf
Description: Adobe PDF document
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] sum some columns for each row

2015-07-10 Thread Dawn
Thank you all and sorry for the data messing. It has worked!

Best,
Dawn

On Fri, Jul 10, 2015 at 4:15 AM, Jim Lemon drjimle...@gmail.com wrote:

 Hi Dawn,
 Your data are a bit messed up, but try the following:

 colSums(dat[,grep(ABC,names(dat),fixed=TRUE)],na.rm=TRUE)
 colSums(dat[,grep(XYZ,names(dat),fixed=TRUE)],na.rm=TRUE)

 I'm assuming that you want to discard the NA values.

 Jim

 On Fri, Jul 10, 2015 at 6:52 AM, Rui Barradas ruipbarra...@sapo.pt
 wrote:
  Hello,
 
  Please use ?dput to give a data example, like this it's completely
  unreadable. If your data.frame is named 'dat' use
 
  dput(head(dat, 30))  # paste the outut of this in your mail
 
 
  And don't post in html, use plain text only, like the posting guide says.
 
  Rui Barradas
 
 
  Em 09-07-2015 18:12, Dawn escreveu:
 
  Hi,
 
  I have a big dataframe as follows
 
   109ABC109XYZ18ABC18XYZ22XYZ23ABC25ABC
  25XYZ
  30ABC31XYZ32ABC32XYZ34DCM34XYZ36ABC36SUR
  38DCM38XYZ39DCM39SUR41DCM41SUR42DCM42SUR
  46SUR52DCM64ABC64XYZ65ABC65XYZ66ABC66XYZ
  67XYZ68ABC68SUR70MES70SUR72ABC72XYZ76ABC
  76XYZ82ABC85ABCPOV
  Cluster_1171
  310145221112
   2TT:61
  Cluster_21420
  653699610131
   4TT:88
  Cluster_3336417
  1718131719221152185184
  79
  TT:227
  
 
  I want to get two columns, i.e,  one is to sum columns for all including
  ABC for each row and the other is  to sum columns for all including XYZ
  for
  each row.
 
  Is there some help? Thank you!
  Dawn
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Yihui Xie
Your LyX example has two problems: 1) We don't have your .RData; 2)
You didn't library(reshape) and library(lattice). Hence it is not a
self-contained reproducible example.

After fixing these two issues, I don't see why lattice graphics can be
problematic with knitr. There is no need to print() the plot, and no
need to pdf(), either. See the attached PDF I generated.

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Web: http://yihui.name


On Fri, Jul 10, 2015 at 7:18 PM, Rich Shepard rshep...@appl-ecosys.com wrote:
 On Fri, 10 Jul 2015, David Winsemius wrote:

 #Generally one needs to complete a pdf() call with:

 dev.off()

 # And an empty file is the symptom os such a failure.



 David,

   I did leave that off the example file, but it make no difference. The
 attached is the compiled example.pdf

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


example.pdf
Description: Adobe PDF document
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Time series exercise (was: (no subject)).

2015-07-10 Thread Rolf Turner

On 10/07/15 21:17, Lia LEE wrote:

Hello forum members,

I am taking this R course which I have to admit that it is beyond my
capability. I am asked to analyze the following data(file attached) according
to the question provided below:

1. The file [data_13-9.txt] contains a data of length 225, which seems to
have some cycle pattern.
(1) Fit a suitable model for this data, then report the model equation.
(2) Provide the forecast values for 3-steps ahead and 6-steps ahead.

I am desperately seeking for your help, since I really don't know where to
start.. I have done plot.ts(data.13-6), but not further. Above question
is just part of the whole task, but I believe solving this would be very
much helpful for me to jump in to the other questions. It would be easier
for me to follow if your answer is in R script..
I appreciate your patience and help.
Thank you so much in advance!


As Bert Gunter said, we don't do homework for people on this list. 
Notwithstanding I couldn't resist having a crack at analysing your time 
series, and I found it, uh, challenging to say the least.  I think of 
myself as having at least *some* skill at fitting time series models, 
and I struggled to find a model that fitted adequately to your data.
(I finally managed to get a decent fit, after trying a number of models 
on a hammer-and-hope basis.)


Perhaps I am even more of a thicko than I think I am.  Nevertheless it 
seems to me that your instructor has dropped you in the deep end by 
setting you this exercise.  (Perhaps I am missing something obvious, as 
is so often the case.  Others may wish to chime in with some comments to 
the effect You idiot Rolf.  The *obvious* model is )


At any rate, your first stop should be your instructor.  Get him or her 
to give you some pointers as to how to get started.  That is what 
instructors are for.


cheers,

Rolf Turner

Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread David Winsemius

On Jul 10, 2015, at 2:57 PM, Rich Shepard wrote:

 On Fri, 10 Jul 2015, Hadley Wickham wrote:
 
 Have you tried explicitly print()ing the lattice graphics in your knitr
 doc?
 
 Hadley,
 
  Only now. Had not thought of trying this before.
 
 pdf('carlin-1-descriptive.pdf')
 print(xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T))

#Generally one needs to complete a pdf() call with:

dev.off()

# And an empty file is the symptom os such a failure.


David.
 
 No error messages, but no graphic, either. Without specifying the pdf
 device, TeX complains it cannot find a graphics device and lists bit-mapped,
 ps and svg devices.
 
  Most likely I do not have the correct syntax.
 
 Thanks,
 
 Rich
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Hadley Wickham
I'd recommend starting with a simpler .Rmd or .Rnw file, rather than
using it with lyx. The basic .Rmd file below works for me without any
further adjustments:

# Lattice test

```{r}
library(lattice)
xyplot(mpg ~ wt, data = mtcars)
```


Hadley

On Fri, Jul 10, 2015 at 3:39 PM, Rich Shepard rshep...@appl-ecosys.com wrote:
 On Fri, 10 Jul 2015, Hadley Wickham wrote:

 You shouldn't be explicitly opening a device in a knitr document.


 Hadley,

   Didn't think so.

 I think maybe you should post a minimal document so we can figure out
 what's going wrong.


   Agreed. Attached are the raw data (carlin.csv) and a stripped down LyX
 document with the knitr chunks.

   This is my first attempt to use knitr; I'm reading the knitr book and
 that's where I got the impression that lattice graphics are not supported.

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



-- 
http://had.co.nz/

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


Re: [R] (no subject)

2015-07-10 Thread Jeff Newmiller
I was under the impression that different instructional environments have 
different standards for ethical conduct, so we list members cannot in general 
know whether we would be condoning/assisting in cheating. However, if you are 
taking a class, then the instructor/institution should be providing appropriate 
resources to assist the student so we should not have to second guess them 
anyway. Reducing list volume is at best a secondary concern from my perspective.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On July 10, 2015 10:30:41 AM PDT, Bert Gunter bgunter.4...@gmail.com wrote:
Sorry Lia. We don't do homework on this list. You can imagine how
clogged it would be if we did.

Maybe you'll get lucky and someone will answer you privately.
Otherwise, seek help from your teachers, fellow students, and/or
course homework forums.

Cheers,
Bert


Bert Gunter

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
   -- Clifford Stoll


On Fri, Jul 10, 2015 at 2:17 AM, Lia LEE ljylia.0...@gmail.com wrote:
 Hello forum members,

 I am taking this R course which I have to admit that it is beyond my
 capability. I am asked to analyze the following data(file attached)
according
 to the question provided below:

 1. The file [data_13-9.txt] contains a data of length 225, which
seems to
 have some cycle pattern.
 (1) Fit a suitable model for this data, then report the model
equation.
 (2) Provide the forecast values for 3-steps ahead and 6-steps ahead.

 I am desperately seeking for your help, since I really don't know
where to
 start.. I have done plot.ts(data.13-6), but not further. Above
question
 is just part of the whole task, but I believe solving this would be
very
 much helpful for me to jump in to the other questions. It would be
easier
 for me to follow if your answer is in R script..
 I appreciate your patience and help.
 Thank you so much in advance!

 Cheers,
 Lia

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Embed fonts in an R graph

2015-07-10 Thread David Winsemius

On Jul 10, 2015, at 8:45 AM, David Winsemius wrote:

 
 On Jul 10, 2015, at 7:40 AM, Edwin Sun wrote:
 
 Hello all,
 
 I cannot embed a common font type into an R graph. I did it successfully in
 December 2014 with the previous R version. However, with R 3.2.1 in July
 2015, the following sample codes do not work anymore.
 
 pdf(file = c:/testA.pdf, family = serif)
 plot(x = 1:10, y = rnorm(10))
 dev.off()
 embedFonts(file = c:/testA.pdf, outfile = c:/testB.pdf)
 
 
 When you look at ?embedFonts it becomes obvious that this is a process 
 mediated by GhostScript, an external program no under the control of the R 
 Team, but rather a system facility that you are responsible for maintaining 
 on your unspecified (but inferable) operating system.
 

And don't forget to read your News. In this case, there is an item in the very 
first entry about embedFonts:

 str(news())
Classes ‘news_db_from_Rd’, ‘news_db’ and 'data.frame':  681 obs. of  4 
variables:
 $ Version : chr  3.1.2 3.1.2 3.1.2 3.1.2 ...
 $ Date: chr  NA NA NA NA ...
 $ Category: chr  NEW FEATURES NEW FEATURES NEW FEATURES NEW FEATURES 
...
 $ Text: chr  embedFonts() now defaults to format = \ps2write\ for .ps 
and .eps\nfiles.  This is available in Ghostscript 9.x (since 2010) | 
__truncated__ For consistency with [dpqr]norm(), [dp]lnorm(sdlog = 0) model 
a\npoint mass at exp(mulog) rather than return NaN (for an error)| 
__truncated__ capabilities() now reports if ICU is compiled in for use 
for\ncollation (it is only actually used if a suitable locale is set f| 
__truncated__ (OS X only.) Package tcltk checks when loaded if it is 
linked\nagainst the CRAN X11-based Tcl/Tk and if so that the Tcl/Tk\ncom| 
__truncated__ ...
 - attr(*, bad)= logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
 - attr(*, package)= chr R

Here's a way to search for any others:

 newstuff$Text[ grepl(embed, newstuff$Text) ]
[1] embedFonts() now defaults to format = \ps2write\ for .ps and 
.eps\nfiles.  This is available in Ghostscript 9.x (since 2010) whereas\nthe 
previous default, format = \pswrite\, was removed in\nGhostscript 9.10.
[2] Error messages from bugs in embedded Sexpr code in Sweave documents\nnow 
report the source location.
 
[3] read.table(), readLines() and scan() have a new argument to\ninfluence the 
treatment of embedded nuls.
   
[4] read.table(), readLines() and scan() now warn when an embedded nul\nis 
found in the input.  (Related to PR#15625 which was puzzled by\nthe behaviour 
in this unsupported case.)   




 
 As a result, both testA.pdf and testB.pdf cannot embed the fonts into the
 graph.
 
 That sentence did not make sense to me. I would have expected 'testA.pdf to 
 have been altered at all.
 
 -- 
 David.
 
 Since You are posting through Nabble I'd suggest you read the Posting Guide:
 
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 Specifically, Adobe Acrobt reveals that Times-Roman is substituted
 by TimesNewRomanPSMT, and ZapfDingbats is substituted by AdobePiStd. 
 
 Any help is greatly appreciated.
 
 Edwin
 
 http://r.789695.n4.nabble.com/file/n4709707/Capture.png 
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Embed-fonts-in-an-R-graph-tp4709707.html
 Sent from the R help mailing list archive at Nabble.com.
 -- 
 
 David Winsemius
 Alameda, CA, USA
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Embed fonts in an R graph

2015-07-10 Thread Edwin Sun
Hello all,

I cannot embed a common font type into an R graph. I did it successfully in
December 2014 with the previous R version. However, with R 3.2.1 in July
2015, the following sample codes do not work anymore.

pdf(file = c:/testA.pdf, family = serif)
plot(x = 1:10, y = rnorm(10))
dev.off()
embedFonts(file = c:/testA.pdf, outfile = c:/testB.pdf)

As a result, both testA.pdf and testB.pdf cannot embed the fonts into the
graph. Specifically, Adobe Acrobt reveals that Times-Roman is substituted
by TimesNewRomanPSMT, and ZapfDingbats is substituted by AdobePiStd. 

Any help is greatly appreciated.

Edwin

http://r.789695.n4.nabble.com/file/n4709707/Capture.png 




--
View this message in context: 
http://r.789695.n4.nabble.com/Embed-fonts-in-an-R-graph-tp4709707.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Embed fonts in an R graph

2015-07-10 Thread David Winsemius

On Jul 10, 2015, at 7:40 AM, Edwin Sun wrote:

 Hello all,
 
 I cannot embed a common font type into an R graph. I did it successfully in
 December 2014 with the previous R version. However, with R 3.2.1 in July
 2015, the following sample codes do not work anymore.
 
 pdf(file = c:/testA.pdf, family = serif)
 plot(x = 1:10, y = rnorm(10))
 dev.off()
 embedFonts(file = c:/testA.pdf, outfile = c:/testB.pdf)
 

When you look at ?embedFonts it becomes obvious that this is a process mediated 
by GhostScript, an external program no under the control of the R Team, but 
rather a system facility that you are responsible for maintaining on your 
unspecified (but inferable) operating system.


 As a result, both testA.pdf and testB.pdf cannot embed the fonts into the
 graph.

That sentence did not make sense to me. I would have expected 'testA.pdf to 
have been altered at all.

-- 
David.

Since You are posting through Nabble I'd suggest you read the Posting Guide:

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


 Specifically, Adobe Acrobt reveals that Times-Roman is substituted
 by TimesNewRomanPSMT, and ZapfDingbats is substituted by AdobePiStd. 
 
 Any help is greatly appreciated.
 
 Edwin
 
 http://r.789695.n4.nabble.com/file/n4709707/Capture.png 
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Embed-fonts-in-an-R-graph-tp4709707.html
 Sent from the R help mailing list archive at Nabble.com.
-- 

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Corrected: approaches tpmatrix multiplication of each layer of 3-d array with different matrix

2015-07-10 Thread Jeff Newmiller
Strictly speaking, the answer is yes because you can unroll the loop, but that 
probably is not what you really want or need to do.

Your example seems about right, but it is not clear how you plan to make 44 
conform with 5500.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On July 10, 2015 6:44:19 AM PDT, Ranjan Maitra maitra.mbox.igno...@inbox.com 
wrote:
Hi,

Sorry to post again, but there is a careless error in my first R code
snippet:

--- begin R code ---
 
AA - array(1:60, dim = c(5500,44,33))
BB - array(1:60, dim = c(44,44,33))
 
 
arraymatprod - function(A, B) {
EE - array(dim=dim(A));
for (i in 1:dim(A)[3]) EE[,,i] - A[,,i] %*% B[,,i]
EE
}

system.time(arraymatprod(AA, BB))

--- end R code ---

The second snippet is correct:

--- begin R code ---

arraymatrixproduct - function(A, B) {
   require(abind)
   dA - dim(A)[1]
   AB - abind(A, B, along = 1)
   array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA, ] %*%
mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
}

system.time(arraymatrixproduct(AA, BB))

--- end R code ---

However, the second is almost twice as long as the first snippet.

Many thanks,
Ranjan


On Fri, 10 Jul 2015 08:23:49 -0500 Ranjan Maitra
maitra.mbox.igno...@inbox.com wrote:

 Dear friends,
 
 I have two 3-d arrays of appropriate dimensions. I want to
postmultiply the 2-D matrix layers of the first with the 2-D matrix
layers of the second. Can I do this easily in R avoiding loops?
 
 As an example:
 
 --- begin R code ---
 
 AA - array(1:60, dim = c(5500,44,33))
 BB - array(1:60, dim = c(44,44,33))
 
 
 arraymatprod - function(A, B) {
 EE - array(dim=dim(A));
 for (i in 1:3) EE[,,i] - A[,,i] %*% B[,,i]
 EE
 }
 
 system.time(arraymatprod(AA, BB))
 
 --- end R code ---
 
 So, is there a way to do this without the loop?
 
 Of course, I could abind the arrays and then use apply with an
appropriate function which would be as follows:
 
 --- begin R code ---
 
 arraymatrixproduct - function(A, B) {
  require(abind)
  dA - dim(A)[1]
  AB - abind(A, B, along = 1)
  array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA, ]
%*% mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
 }
 
 system.time(arraymatrixproduct(AA, BB))
 
 --- end R code ---
 
 However, this turns out to be slower -- perhaps because of the use of
abind and filling the array inside the function.
 
 I just wanted suggestions to get this operation done more
efficiently.
 
 Many thanks and best wishes,
 Ranjan
 
 
 Publish your photos in seconds for FREE
 TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Corrected: approaches to matrix multiplication of each layer of 3-d array with different matrix

2015-07-10 Thread Ranjan Maitra
What does it mean to unroll the loop?

Thanks!

Ranjan


On Fri, 10 Jul 2015 07:07:15 -0700 Jeff Newmiller jdnew...@dcn.davis.ca.us 
wrote:

 Strictly speaking, the answer is yes because you can unroll the loop, but 
 that probably is not what you really want or need to do.
 
 Your example seems about right, but it is not clear how you plan to make 44 
 conform with 5500.
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.
 
 On July 10, 2015 6:44:19 AM PDT, Ranjan Maitra 
 maitra.mbox.igno...@inbox.com wrote:
 Hi,
 
 Sorry to post again, but there is a careless error in my first R code
 snippet:
 
 --- begin R code ---
  
 AA - array(1:60, dim = c(5500,44,33))
 BB - array(1:60, dim = c(44,44,33))
  
  
 arraymatprod - function(A, B) {
 EE - array(dim=dim(A));
 for (i in 1:dim(A)[3]) EE[,,i] - A[,,i] %*% B[,,i]
 EE
 }
 
 system.time(arraymatprod(AA, BB))
 
 --- end R code ---
 
 The second snippet is correct:
 
 --- begin R code ---
 
 arraymatrixproduct - function(A, B) {
  require(abind)
  dA - dim(A)[1]
  AB - abind(A, B, along = 1)
  array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA, ] %*%
 mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
 }
 
 system.time(arraymatrixproduct(AA, BB))
 
 --- end R code ---
 
 However, the second is almost twice as long as the first snippet.
 
 Many thanks,
 Ranjan
 
 
 On Fri, 10 Jul 2015 08:23:49 -0500 Ranjan Maitra
 maitra.mbox.igno...@inbox.com wrote:
 
  Dear friends,
  
  I have two 3-d arrays of appropriate dimensions. I want to
 postmultiply the 2-D matrix layers of the first with the 2-D matrix
 layers of the second. Can I do this easily in R avoiding loops?
  
  As an example:
  
  --- begin R code ---
  
  AA - array(1:60, dim = c(5500,44,33))
  BB - array(1:60, dim = c(44,44,33))
  
  
  arraymatprod - function(A, B) {
  EE - array(dim=dim(A));
  for (i in 1:3) EE[,,i] - A[,,i] %*% B[,,i]
  EE
  }
  
  system.time(arraymatprod(AA, BB))
  
  --- end R code ---
  
  So, is there a way to do this without the loop?
  
  Of course, I could abind the arrays and then use apply with an
 appropriate function which would be as follows:
  
  --- begin R code ---
  
  arraymatrixproduct - function(A, B) {
 require(abind)
 dA - dim(A)[1]
 AB - abind(A, B, along = 1)
 array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA, ]
 %*% mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
  }
  
  system.time(arraymatrixproduct(AA, BB))
  
  --- end R code ---
  
  However, this turns out to be slower -- perhaps because of the use of
 abind and filling the array inside the function.
  
  I just wanted suggestions to get this operation done more
 efficiently.
  
  Many thanks and best wishes,
  Ranjan
  
  
  Publish your photos in seconds for FREE
  TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4
  
  __
  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Important Notice: This mailbox is ignored: e-mails are set to be deleted on 
receipt. Please respond to the mailing list if appropriate. For those needing 
to send personal or professional e-mail, please use appropriate addresses.


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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] approaches tpmatrix multiplication of each layer of 3-d array with different matrix

2015-07-10 Thread Ranjan Maitra
Dear friends,

I have two 3-d arrays of appropriate dimensions. I want to postmultiply the 2-D 
matrix layers of the first with the 2-D matrix layers of the second. Can I do 
this easily in R avoiding loops?

As an example:

--- begin R code ---

AA - array(1:60, dim = c(5500,44,33))
BB - array(1:60, dim = c(44,44,33))


arraymatprod - function(A, B) {
EE - array(dim=dim(A));
for (i in 1:3) EE[,,i] - A[,,i] %*% B[,,i]
EE
}

system.time(arraymatprod(AA, BB))

--- end R code ---

So, is there a way to do this without the loop?

Of course, I could abind the arrays and then use apply with an appropriate 
function which would be as follows:

--- begin R code ---

arraymatrixproduct - function(A, B) {
require(abind)
dA - dim(A)[1]
AB - abind(A, B, along = 1)
array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA, ] %*% 
mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
}

system.time(arraymatrixproduct(AA, BB))

--- end R code ---

However, this turns out to be slower -- perhaps because of the use of abind and 
filling the array inside the function.

I just wanted suggestions to get this operation done more efficiently.

Many thanks and best wishes,
Ranjan


Publish your photos in seconds for FREE
TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Corrected: approaches tpmatrix multiplication of each layer of 3-d array with different matrix

2015-07-10 Thread Ranjan Maitra
Hi,

Sorry to post again, but there is a careless error in my first R code snippet:

--- begin R code ---
 
AA - array(1:60, dim = c(5500,44,33))
BB - array(1:60, dim = c(44,44,33))
 
 
arraymatprod - function(A, B) {
EE - array(dim=dim(A));
for (i in 1:dim(A)[3]) EE[,,i] - A[,,i] %*% B[,,i]
EE
}

system.time(arraymatprod(AA, BB))

--- end R code ---

The second snippet is correct:

--- begin R code ---

arraymatrixproduct - function(A, B) {
require(abind)
dA - dim(A)[1]
AB - abind(A, B, along = 1)
array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA, ] %*% 
mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
}

system.time(arraymatrixproduct(AA, BB))

--- end R code ---

However, the second is almost twice as long as the first snippet.

Many thanks,
Ranjan


On Fri, 10 Jul 2015 08:23:49 -0500 Ranjan Maitra 
maitra.mbox.igno...@inbox.com wrote:

 Dear friends,
 
 I have two 3-d arrays of appropriate dimensions. I want to postmultiply the 
 2-D matrix layers of the first with the 2-D matrix layers of the second. Can 
 I do this easily in R avoiding loops?
 
 As an example:
 
 --- begin R code ---
 
 AA - array(1:60, dim = c(5500,44,33))
 BB - array(1:60, dim = c(44,44,33))
 
 
 arraymatprod - function(A, B) {
 EE - array(dim=dim(A));
 for (i in 1:3) EE[,,i] - A[,,i] %*% B[,,i]
 EE
 }
 
 system.time(arraymatprod(AA, BB))
 
 --- end R code ---
 
 So, is there a way to do this without the loop?
 
 Of course, I could abind the arrays and then use apply with an appropriate 
 function which would be as follows:
 
 --- begin R code ---
 
 arraymatrixproduct - function(A, B) {
   require(abind)
   dA - dim(A)[1]
   AB - abind(A, B, along = 1)
   array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA, ] %*% 
 mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
 }
 
 system.time(arraymatrixproduct(AA, BB))
 
 --- end R code ---
 
 However, this turns out to be slower -- perhaps because of the use of abind 
 and filling the array inside the function.
 
 I just wanted suggestions to get this operation done more efficiently.
 
 Many thanks and best wishes,
 Ranjan
 
 
 Publish your photos in seconds for FREE
 TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Important Notice: This mailbox is ignored: e-mails are set to be deleted on 
receipt. Please respond to the mailing list if appropriate. For those needing 
to send personal or professional e-mail, please use appropriate addresses.


Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords  protects your account.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] cointegration and VECM, urca package and Eviews

2015-07-10 Thread mrrox
Hello,

I estimated a VECM in Eviews and R using urca package's ca.jo(), cajorl()
and vec2var() functions. 
Specifications are 'no trend' in Eviews and 'none' in R (no theory, just
testing, feel free to make changes). 

Results are different, ecm and cointegrating vectors are completely
different.

R code is: 
*johcoint=ca.jo(Ydata,type=trace,ecdet=c(none),K=2,spec=transitory)
summary(johcoint)
vecm.r1=cajorls(johcoint,r=1)
vecm.r1
vecm.l=vec2var(johcoint,r=1)
ll=irf(vecm.l, impulse = B,response = A, boot = FALSE)
plot(ll$irf[[1]])*

Data:

 AB   C  D
1   8.6469243.9251552.2977372.764267
2   8.6438104.0482152.1407312.769231
3   8.6347324.1171142.0637242.747604
4   8.6033373.9760021.9392902.741640
5   8.6043443.9246971.9282552.732419
6   8.6288873.9215171.8786742.718437
7   8.6531673.9060761.9432362.693620
8   8.6618543.9404682.1077182.670370
9   8.6098393.8727822.0030642.689212
10  8.6140913.9058391.9737192.679186
11  8.6136923.8907971.9393112.659350
12  8.6514884.0524231.9610382.640751
13  8.6544694.1375342.1308732.622611
14  8.6931214.0747532.1084272.595760
15  8.6994353.8724122.0918162.622049
16  8.8087243.8513732.3457402.646252
17  8.8144373.8060482.0571042.728953
18  8.8365293.7430461.8258272.748266
19  8.8268983.6938971.8238803.027604
20  8.8091173.6731262.0200162.820051
21  8.6549723.6529031.5232492.538225
22  8.5159173.6595921.6177342.523293
23  8.5899193.6558221.8276452.371598
24  8.5951933.6459371.8256032.251557
25  8.6153323.6292011.6619462.254364
26  8.6712223.6094641.7330732.145093
27  8.6118823.6121101.7949371.819291
28  8.6884143.5792051.5058881.654666
29  8.6901253.5549581.4265891.731257
30  8.7259323.5332881.5223111.788969
31  8.7432793.5275911.6012611.760313
32  8.6948053.5316111.6340851.732271
33  8.6879833.5273271.6019851.836593
34  8.7169763.5146451.5890351.745653
35  8.7754643.4924271.4715621.699377
36  8.8088983.4710361.4601621.686131
37  8.8428473.4511301.5795471.670513
38  8.8717863.4280021.5972161.618989
39  8.9074253.4238871.6262081.652055
40  8.9247213.4036571.5785761.509779
41  8.9411223.3576451.5212361.607082
42  9.0091123.3140891.5067581.544039
43  9.0298943.2677951.4839681.518783
44  9.0553593.2403971.5173481.517085
45  9.0402783.2354101.5904361.509334
46  8.9937963.2523741.6511061.431041
47  8.9674643.2362651.6720981.338936
48  8.9528593.2359161.6624501.287055
49  9.1214303.2175991.7112921.263948
50  9.1478713.2051941.6766411.211038

Will anyone please help why this might happen?
Perhaps I am estimating the models incorrectly?
Thank you



--
View this message in context: 
http://r.789695.n4.nabble.com/cointegration-and-VECM-urca-package-and-Eviews-tp4709708.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] [R-pkgs] interplot: a new package for visualizing interactive effects

2015-07-10 Thread Hu, Yue

Dear colleagues,

We just published a package, interplot,  in CRAN. It can be used to plots the 
conditional coefficients (marginal effects) of variables included in 
multiplicative interaction terms for various models.  The installation 
instruction and more details about the package are available in 
http://cran.r-project.org/web/packages/interplot/vignettes/interplot-vignette.html.

Please contact me with any questions, bug reports, and comments.

Best,

Hu, Yue
Ph.D. Student, Political Science,
University of Iowa,
313 Schaeffer Hall,
20E Washington St.,
Iowa City, IA, 52242.


[[alternative HTML version deleted]]

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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] clm funtion and CI

2015-07-10 Thread Luciane Maria Pilotto
I am using the commands bellow. 

##
load(file.choose())#dataframe:id3.rda
attach(id3)

dput(head(id3,10))

structure(list(regiao = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = c(Norte, Nordeste, Sudeste, Sul, 
Centro-Oeste), class = factor), estado = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(Rondonia, Acre, 
Amazonas, Roraima, Para, Amapa, Tocantins, Maranhao, 
Piaui, Ceara, Rio Grande Do Norte, Paraiba, Pernambuco, 
Alagoas, Sergipe, Bahia, Minas Gerais, Espirito Santo, 
Rio De Janeiro, Sao Paulo, Parana, Santa Catarina, Rio Grande Do Sul, 
Mato Grosso Do Sul, Mato Grosso, Goias, Distrito Federal
), class = factor), cod_mun = c(1200401L, 1200401L, 1200401L, 
1200401L, 1200401L, 1200401L, 1200401L, 1200401L, 1200401L, 1200401L
), setor = c(0556, 0556, 0556, 0556, 
0556, 0556, 0556, 0556, 0562, 0562
), cap_int = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L), .Label = c(Interior, Capital), class = factor), idade = c(15L, 
15L, 17L, 17L, 18L, 18L, 18L, 19L, 19L, 15L), getario = structure(c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c(5 anos, 12 anos, 
15 a 19 anos, 35 a 44 anos, 65 a 74 anos), class = factor), 
    sexo = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L
    ), .Label = c(Male, Female), class = factor), grp_etni = 
structure(c(1L, 
    4L, 4L, 4L, 2L, 4L, 4L, 4L, 4L, 4L), .Label = c(Branca, 
    Preta, Amarela, Parda, Indigena, Sem Informacao
    ), class = factor), quest_01 = c(8L, 2L, 4L, 4L, 3L, 4L, 
    3L, 3L, 3L, 4L), quest_02 = c(4L, 4L, 2L, 2L, 4L, 1L, 3L, 
    1L, 3L, 2L), density = c(2, 0.5, 2, 2, 0.75, 4, 1, 3, 1, 
    2), quest_03 = c(3L, 4L, 6L, 5L, 5L, 3L, 3L, 3L, 6L, 5L), 
    quest_04 = structure(c(2L, 3L, 3L, 4L, NA, 2L, 1L, NA, 3L, 
    3L), .Label = c(Ate 250, 251 a 500, 501 a 1.500, 1.501 a 2.500, 
    2.501 a 4.500, 4.501 a 9.500, Mais de 9.500, Nao sabe/Nao respondeu
    ), class = factor), inc_percapita1 = c(46.875, 500, 250, 
    500, NA, 93.75, 41.679382324, NA, 333.43505859, 250
    ), inc_percapita2 = c(46.875, 500, 250, 500, NA, 93.75, 41.679382324, 
    NA, 333.43505859, 250), inc_sqrt1 = c(132.58251953125, 
    707.106811523438, 500, 1000, NA, 187.5, 72.1687850952148, 
    NA, 577.350280761719, 500), inc_sqrt2 = c(132.58251953125, 
    707.106811523438, 500, 1000, NA, 187.5, 72.1687850952148, 
    NA, 577.350280761719, 500), q05 = c(11L, 4L, 12L, 6L, 11L, 
    10L, 7L, 12L, 8L, 7L), quest_06 = structure(c(2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(Nao, Sim, Nao se aplica, 
    Nao sabe), class = factor), quest_07 = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L), .Label = c(Nao, Sim, 
    Nao se aplica, Nao sabe), class = factor), quest_08 = c(9L, 
    9L, 9L, 9L, 9L, 9L, 9L, 9L, 3L, 9L), quest_09 = structure(c(1L,
    1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(Nao, Sim, 
    Nao se aplica, Nao sabe), class = factor), quest_10 = structure(c(5L, 
    5L, 2L, 3L, 3L, 2L, 2L, 3L, 3L, 3L), .Label = c(Menos de 1 ano,
    1 a 2 anos, 3 anos, Outros, Nïa se aplica, Nao sabe
    ), class = factor), quest_11 = structure(c(5L, 5L, 1L, 
    1L, 2L, 1L, 1L, 1L, 1L, 1L), .Label = c(Publico, Particular,
    Plano de Saude/Convenios, Outros, Nao se aplica, Nao sabe
    ), class = factor), quest_12 = structure(c(6L, 6L, 2L, 
    4L, 1L, 3L, 1L, 4L, 2L, 1L), .Label = c(Revisao/Prevencao, 
    Dor, Extracao, Tratamento, Outros, Nao se aplica, 
    Nao sabe), class = factor), quest_13 = structure(c(NA, 
    NA, 2L, 3L, 2L, 3L, 2L, 2L, 2L, 2L), .Label = c(Muito bom, 
    Bom, Regular, Ruim, Muito Ruim, Nao se aplica, 
    Nao sabe), class = factor), quest_14 = structure(c(3L, 
    2L, 3L, 4L, 2L, 2L, 4L, 3L, 4L, 2L), .Label = c(Muito satisfeito, 
    Satisfeito, Nem satisfeito/insatisfeito, Insatisfeito, 
    Muito Insatisfeito, Nao sabe), class = factor), quest_15 = 
structure(c(1L, 
    1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(Nao, Sim, 
    Nao se aplica, Nao sabe), class = factor), exame = c(1,
    1, 1, 1, 1, 1, 1, 1, 1, 1), cpod = c(3L, 
    0L, 8L, 3L, 3L, 12L, 1L, 6L, 6L, 3L), p_sang = c(0L, 1L, 
    1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L), p_calc = c(0L, 1L, 1L, 0L, 
    0L, 1L, 0L, 1L, 0L, 0L), cpi_max = structure(c(1L, 3L, 3L, 
    1L, 1L, 3L, 1L, 3L, 1L, 2L), .Label = c(Higido, Sangramento,
    Calculo, Bolsa 4-5 mm, Bolsa 6 mm ou +, 4, A, X
    ), class = factor), dai = c(21L, 32L, 23L, 21L, 19L, 18L, 
    17L, 23L, 34L, 25L), trauma = c(NA_integer_, NA_integer_, 
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
    NA_integer_, NA_integer_, NA_integer_), n_higido = c(26L, 
    28L, 24L, 24L, 25L, 17L, 27L, 25L, 24L, 25L), n_cariado = c(3L,
    0L, 6L, 2L, 0L, 2L, 1L, 2L, 4L, 3L), n_restcar = c(0L, 0L, 
    0L, 0L, 0L, 0L, 0L, 2L, 1L, 0L), n_restaur = c(0L, 0L, 2L, 
    0L, 3L, 6L, 0L, 2L, 0L, 0L), n_perdcar = c(0L, 0L, 0L, 1L, 
    0L, 4L, 0L, 0L, 1L, 0L), n_perdout = 

Re: [R] detecting any element in a vector of strings, appearing anywhere in any of several character variables in a dataframe

2015-07-10 Thread Bert Gunter
Yes. This is one of the fundamental challenges in text searching --
defining exactly what text defines a match and what doesn't. So,
continuing your example, one might imagine that heroin and heroine
might both be matches, but maybe heroines shouldn't be (e.g. if the
text contains movie reviews). So what one might want to do is add
semantic analysis to searches, à la google, a topic way beyond the
simple capabilities discussed, or likely needed, here.

Incidentally, Jeff Newmiller's (final) regular expression solution is
preferable to mine in all respects, I think.

-- Bert


Bert Gunter

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
   -- Clifford Stoll


On Fri, Jul 10, 2015 at 10:30 AM, Christopher W Ryan
cr...@binghamton.edu wrote:
 Interesting thoughts about the partial-word matches, and speed  On
 another real data set, about 73,000 records and 6 columns to search
 through for matches (one column of which contains very long character
 strings--several paragraphs each), I ran both John's and Bert's
 solutions.  John's was noticeably slower, although still quite
 tolerable.  There were a different number of matches, though:

   oic.2
 oic  FALSETRUE Sum
   FALSE 74939 074939
   TRUE274   927 1201
   Sum 75213927 76140

 where oic is the logical vector generated by John's solution, and
 oic.2 is the logical vector generated by Bert's solution. Bert's
 solution detected about 77% of the cases detected by John's.

 I'm still exploring why that might be. One possible explanation, for
 at least part of the difference, is the issue of partial-word matches.
 Substantively, I am searching ambulance run records for words related
 to opioid overdose, and I've noticed that the medics often spell
 heroin as heroine  So in this context, I like partial-word
 matches--I want to pick up records that (partially) match heroin
 because it is contained in the word heroine .

 There may be other things going on too.

 Thanks.

 --Chris

 On Thu, Jul 9, 2015 at 3:24 PM, John Fox j...@mcmaster.ca wrote:
 Dear Christopher,

 My usual orientation to this kind of one-off problem is that I'm looking for 
 a simple correct solution. Computing time is usually much smaller than 
 programming time.

 That said, Bert Gunter's solution was about 5 times faster in a simple check 
 that I ran with microbenchmark, and Jeff Newmiller's solution was about 10 
 times faster. Both Bert's and Jeff's (eventual) solution protect against 
 partial (rather than full-word) matches, while mine doesn't (though it could 
 easily be modified to do that).

 Best,
  John

 -Original Message-
 From: Christopher W Ryan [mailto:cr...@binghamton.edu]
 Sent: July-09-15 2:49 PM
 To: Bert Gunter
 Cc: Jeff Newmiller; R Help; John Fox
 Subject: Re: [R] detecting any element in a vector of strings, appearing
 anywhere in any of several character variables in a dataframe

 Thanks everyone.  John's original solution worked great.  And with
 27,000 records, 65 alarm.words, and 6 columns to search, it takes only
 about 15 seconds.  That is certainly adequate for my needs.  But I
 will try out the other strategies too.

 And thanks also for lot's of new R things to learn--grep, grepl,
 do.call . . . that's always a bonus!

 --Chris Ryan

 On Thu, Jul 9, 2015 at 1:52 PM, Bert Gunter bgunter.4...@gmail.com
 wrote:
  Yup, that does it. Let grep figure out what's a word rather than doing
  it manually. Forgot about \b
 
  Cheers,
  Bert
 
 
  Bert Gunter
 
  Data is not information. Information is not knowledge. And knowledge
  is certainly not wisdom.
 -- Clifford Stoll
 
 
  On Thu, Jul 9, 2015 at 10:30 AM, Jeff Newmiller
  jdnew...@dcn.davis.ca.us wrote:
  Just add a word break marker before and after:
 
  zz$v5 - grepl( paste0( \\b(, paste0( alarm.words, collapse=| ),
 )\\b ), do.call( paste, zz[ , 2:3 ] ) ) )
  -
 --
  Jeff NewmillerThe .   .  Go
 Live...
  DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
 Go...
Live:   OO#.. Dead: OO#..
 Playing
  Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
  /Software/Embedded Controllers)   .OO#.   .OO#.
 rocks...1k
  -
 --
  Sent from my phone. Please excuse my brevity.
 
  On July 9, 2015 10:12:23 AM PDT, Bert Gunter bgunter.4...@gmail.com
 wrote:
 Jeff:
 
 Well, it would be much better (no loops!) except, I think, for one
 issue: red would match barred and I don't think that this is what
 is wanted: the matches should be on whole words not just string
 patterns.
 
 So you would need to fix up the matching pattern to make this work,
 but it may be a little tricky, as arbitrary whitespace characters,
 e.g.   or \n etc. 

[R] (no subject)

2015-07-10 Thread Lia LEE
Hello forum members,

I am taking this R course which I have to admit that it is beyond my
capability. I am asked to analyze the following data(file attached) according
to the question provided below:

1. The file [data_13-9.txt] contains a data of length 225, which seems to
have some cycle pattern.
(1) Fit a suitable model for this data, then report the model equation.
(2) Provide the forecast values for 3-steps ahead and 6-steps ahead.

I am desperately seeking for your help, since I really don't know where to
start.. I have done plot.ts(data.13-6), but not further. Above question
is just part of the whole task, but I believe solving this would be very
much helpful for me to jump in to the other questions. It would be easier
for me to follow if your answer is in R script..
I appreciate your patience and help.
Thank you so much in advance!

Cheers,
Lia
fourth_a.ts
1 -0.0242227774450564
2 0.447778425867187
3 0.0679634009051251
4 0.390085614914361
5 0.249535226083153
6 0.518797872921499
7 -0.0969256279112136
8 0.123337983703432
9 -0.414941322119016
10 -0.27757276812968
11 0.0403939285820523
12 0.494211788018315
13 0.124244228153442
14 0.394493565117432
15 0.188705401390586
16 0.532762644104765
17 -0.10747895472636
18 0.144164346660537
19 -0.336048738751554
20 -0.268668787023198
21 0.0632175364558109
22 0.425890066866375
23 0.129576388534439
24 0.434428059119178
25 0.166373082777172
26 0.500324747168639
27 -0.181757008467706
28 0.111908426500126
29 -0.271053619415509
30 -0.167744715393572
31 -0.0338728333227656
32 0.333625139545928
33 0.0140758980245519
34 0.357007127635719
35 0.117528321727847
36 0.436606929603184
37 -0.281483140210634
38 0.0207127868483681
39 -0.347869271054934
40 -0.173998579595848
41 -0.0799206011874377
42 0.277044216890528
43 -0.114919716596858
44 0.284979270819777
45 -0.0204983858654412
46 0.404494915834395
47 -0.293744301550975
48 0.127254025577103
49 -0.260160101188769
50 -0.0875216627615043
51 -0.0462217977187355
52 0.397719199372734
53 -0.0591056840364732
54 0.367738474710558
55 -0.0152206137909984
56 0.353167727849039
57 -0.312136059481424
58 0.143633095475107
59 -0.171180250675521
60 -0.0465141674925802
61 0.0899046896169316
62 0.598910847300957
63 0.0475490561242251
64 0.358240966214597
65 -0.115970806757625
66 0.322290982770865
67 -0.286140052945316
68 0.0618578078197809
69 -0.212161273189703
70 -0.0454341579685268
71 0.0105666268253198
72 0.581041116690388
73 0.0693941384243427
74 0.261971378607031
75 -0.123479577576325
76 0.367590419177466
77 -0.141235430279281
78 0.116237028180501
79 -0.198695126295741
80 -0.0657961678537194
81 -0.0135147919675166
82 0.64984396453257
83 -0.0167548399541178
84 0.227526983440523
85 -0.299388449116629
86 0.416617177307962
87 -0.203407983560365
88 -0.0023010455436364
89 -0.282560660653303
90 -0.176413766464725
91 -0.0983101390414709
92 0.676705573655853
93 0.0203031107706873
94 0.312294913410111
95 -0.165489563226253
96 0.495102364234008
97 -0.305931623403696
98 0.0254406084608136
99 -0.225414817884392
100 -0.15036962703039
101 -0.112423279517229
102 0.745007684199088
103 0.0255308466866797
104 0.315917556432058
105 -0.303111962111323
106 0.4422161899518
107 -0.369563414156803
108 0.0535188548883159
109 -0.164608441001884
110 -0.156343742785993
111 -0.207438206198236
112 0.689341282064895
113 -0.00226758654004458
114 0.288620788540252
115 -0.400804924124587
116 0.359566102139385
117 -0.321517807983831
118 0.00695988179093469
119 -0.231063555270884
120 -0.0754597599841716
121 -0.217474888732617
122 0.683362779387654
123 -0.00314961139535584
124 0.30330965844177
125 -0.345238161601586
126 0.360311898301801
127 -0.301677126208083
128 0.0752078039771654
129 -0.155192129731062
130 -0.061593861998895
131 -0.219884190719033
132 0.628023504848516
133 -0.0382384606055213
134 0.297499086480709
135 -0.346531677222434
136 0.327798639134225
137 -0.391356801473802
138 0.0491703726922144
139 -0.249887313782597
140 -0.114655677012198
141 -0.220433378749168
142 0.560059582446338
143 -0.196920702930255
144 0.219878996139467
145 -0.373914844022043
146 0.292758745532306
147 -0.471257747874178
148 0.101291169049118
149 -0.177115964022913
150 -0.132451723823155
151 -0.21848909838528
152 0.514021082036989
153 -0.211628524400154
154 0.249156930945686
155 -0.277957223804047
156 0.292060580594635
157 -0.411605289128537
158 0.15610957238629
159 -0.167147715462073
160 -0.116581851584324
161 -0.234964260449157
162 0.526997072058525
163 -0.234040498456114
164 0.193292408158503
165 -0.286173628961541
166 0.329912374179291
167 -0.439242525292821
168 0.12873648130915
169 -0.211483057184516
170 -0.160118716712957
171 -0.168318618554501
172 0.553840105722893
173 -0.184533155434883
174 0.134661753730845
175 -0.264620194457709
176 0.378708889591781
177 -0.400340933892769
178 0.105012175958662
179 -0.28484391241728
180 -0.200352172901001
181 -0.217957678983035
182 0.524658753398018
183 -0.287612226565405
184 0.0883221554409499
185 -0.341060900924494
186 0.263243703023783
187 

[R] Reading the non delimited file with no particular patterns in the data to R

2015-07-10 Thread jagadishpchary
I am beginner in R and I want to read a ASCII file to R environment. However,
the ASCII file is a non delimited and the data is not continuous (have some
blank spaces between the variables) so in order to read the data i have used
the below syntax i.e
test - read.fwf(D:/R_process/ASCII.txt, width = c(10, 4, 1, 4, 9, 9,
1,1,1,1,1,1,1,3,8))

Now i am able to read it but the data read is wrong. Actually my out put
should have only the applicable variables data but not the blank data.
Attached is the ASCII data. Please let me know how should i write the syntax
to read only the applicable data in the file.

Thanks for your help in advance. test.txt
http://r.789695.n4.nabble.com/file/n4709699/test.txt  



--
View this message in context: 
http://r.789695.n4.nabble.com/Cross-tabulation-with-top-one-variable-and-side-as-multiple-variables-tp4708379p4709699.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 embed a 3D plot created by ??rgl?? into gWidgets ggraphics device???

2015-07-10 Thread just_rookie
I created some 3D cubes by using rgl package. The next step is to embed the 
3D plot(rgl device) into ggraphics device from the gWidgets package, but 
I have no idea how to implement it. Is there a way to implement by gWidgets 
or other package? Any help? Thank you in advance!

My code:
library(rgl)
library(scatterplot3d)
library(gWidgets)
options(guiToolkit=RGtk2)


df-data.frame(x=c(1,2,3,4),
   y=c(2,4,6,8),
   z=c(3,6,9,12),
   value=c(33,43,75,21))

clr - df$value/max(df$value)
f - colorRamp(c(green, yellow, purple, red))

## 3D PLOT
for(i in 1:length(df$x)){
  shade3d(translate3d(scale3d(cube3d(col=rgb(f(clr[i])/255),alpha=0.15 ),
 10.0, 10.0, 2.5),df$x[i],df$y[i],df$z[i]))
} 

window - gwindow(TEST, width = 800, height= 600, visible = FALSE)
group - ggroup(cont = window, expand = TRUE)

loadBtn - gbutton(display, cont = group)

addHandlerChanged(loadBtn, handler = function(h,...){
  sudwin-gwindow(3D,visible = TRUE)
  dev - ggraphics(cont=subwin)
   DO NOT KNOW HOW TO DO NEXT...
})
visible(window)-TRUE
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 assign value to a variable dynamically constructed

2015-07-10 Thread Bert Gunter
I'll let Bill respond in detail if he cares to(he is both more
knowledgable and fluent at this than I), but as a nearly unbreakable
rule, get() and assign() should not be used in R. Basically, they
represent a macro (script)-oriented strategy for handling R's objects,
whereas R is designed to use an object-oriented (everything is an
object) and functional (all procedures are functions) approach.
Using get() and assign() leads to messy, confusing, error-prone,
non-portable code in R, and that's why they should be avoided.

For details, you should consult web tutorials, John Chambers's books,
and other books on R programming.

Cheers,
Bert


Bert Gunter

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
   -- Clifford Stoll


On Fri, Jul 10, 2015 at 9:44 AM, Bastien Tran bastien.t...@gmail.com wrote:
 Dear all,

 Provided I understood correctly, shouldn't assign() do the trick? Most 
 similar threads seem to include this approach (among others, indeed).

 Regards,
 Bastien


 On Wednesday, July 8, 2015 at 7:30:04 PM UTC+2, William Dunlap wrote:
 You can use an environment instead of a list using the same [[ syntax.  It
 is like 'get0(..., inherit=FALSE)' on the left side of the - and like
 'assign(...)' on the right side.   E.g.,
myData - new.env()
varName - v1
myData[[varName]] - 1:10
myData[[varName]][4] - myData[[varName]][4] * 100
myData[[varName]]
#  [1]   1   2   3 400   5   6   7   8   9  10
names(myData)
# [1] v1
 (Before R-3.2.0 or so, you had to use objects(myData,all=TRUE) if
 myData was an environment and names(myData) if it was a list.  Now
 names() works for environments.)

 It is better to use a dedicated environment (or list) for each set of
 related
 variables so that name collisions do not cause problems.


 Bill Dunlap
 TIBCO Software
 wdunlap tibco.com

 On Wed, Jul 8, 2015 at 10:06 AM, Greg Snow 538...@gmail.com wrote:

  This is FAQ 7.21.
 
  The most important part of the answer in FAQ 7.21 is the last section
  where it states that it is often easier to use a list rather than
  messing around with trying to dynamically name global variables.
 
  If you tell us what you are trying to accomplish then we may have
  better advice.  The route you are headed down now usually leads to
  inefficient code and hard to find bugs.
 
  On Tue, Jul 7, 2015 at 2:53 PM, Jun Shen jun.shen...@gmail.com wrote:
   Dear list,
  
   Let's say we have a variable (id), whose name is dynamically constructed.
   This variable represents a vector or data frame with many elements. Now I
   want to specifically assign a value to one of the elements. I couldn't
  get
   it right.
  
   test - 'id' # id is dynamically constructed through paste()
  
   id - 1:4
  
   # I can get the element by doing
  
   get(test)[2]
  
   # Now I want to assign a value to the second element of this dynamical
   variable.
  
   get(test)[2] - 5  # doesn't work.
  
   Thanks a lot.
  
   Jun Shen
  
   [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
   https://stat.ethz.ch/mailman/listinfo/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
 
  __
  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 the non delimited file with no particular patterns in the data to R

2015-07-10 Thread Clint Bowman

Is this what your are expecting?

test - read.fwf(test.dat, width = c(10, 4, 1, 4, 9, 

12,26,1,1,1,1,1,1,3,8))

test

  V1   V2 V3 V4   V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15
1  1 2015  1  4 0.766696  1  1  0  0   0   0   0   0   0  10
2  2 2015  1  4 1.458186  1  1  0  0   0   1   0   0   0  20
3  3 2015  1  4 0.185492  1  1  0  0   0   0   0   0   0  15
4  4 2015  1  4 0.961584  1  1  0  0   0   0   0   0   0   3
5  5 2015  1  4 0.650091  2  0  0  0   1   0   0   0   0  NA
6  6 2015  1  4 0.430350  1  1  0  0   0   0   0   0   0  20
7  7 2015  1  4 3.192895  2  1  0  1   1   0   0   0   0   0
8  8 2015  1  4 0.617127  1  1  0  1   0   1   0   0   0  15
9  9 2015  1  4 0.399207  1  1  0  0   0   0   0   0   0  10

Clint

Clint BowmanINTERNET:   cl...@ecy.wa.gov
Air Quality Modeler INTERNET:   cl...@math.utah.edu
Department of Ecology   VOICE:  (360) 407-6815
PO Box 47600FAX:(360) 407-7534
Olympia, WA 98504-7600

USPS:   PO Box 47600, Olympia, WA 98504-7600
Parcels:300 Desmond Drive, Lacey, WA 98503-1274

On Fri, 10 Jul 2015, jagadishpchary wrote:


I am beginner in R and I want to read a ASCII file to R environment. However,
the ASCII file is a non delimited and the data is not continuous (have some
blank spaces between the variables) so in order to read the data i have used
the below syntax i.e
test - read.fwf(D:/R_process/ASCII.txt, width = c(10, 4, 1, 4, 9, 9,
1,1,1,1,1,1,1,3,8))

Now i am able to read it but the data read is wrong. Actually my out put
should have only the applicable variables data but not the blank data.
Attached is the ASCII data. Please let me know how should i write the syntax
to read only the applicable data in the file.

Thanks for your help in advance. test.txt
http://r.789695.n4.nabble.com/file/n4709699/test.txt



--
View this message in context: 
http://r.789695.n4.nabble.com/Cross-tabulation-with-top-one-variable-and-side-as-multiple-variables-tp4708379p4709699.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] predict.poly for multivariate data

2015-07-10 Thread Keith Jewell
A recent stackoverflow post 
http://stackoverflow.com/questions/31134985 How do you make R poly() 
evaluate (or “predict”) multivariate new data (orthogonal or raw)? made 
me look at poly and polym again.


predict.poly doesn't work with multivariate data because for such data 
poly calls polym which does not:

a) return an object inheriting from class poly;
b) return the coefficients needed to make predictions;
c) accept coefficients as an argument or include code to make predictions.

This does lead to some wrong answers without warnings. e.g.
## vanilla poly and polym ###
library(datasets)
alm - lm(stack.loss ~ poly(Air.Flow, Water.Temp, degree=3), stackloss)
# correct prediction values [1:10]
alm$fitted.values[1:10]
# predict(alldata)[1:10] gives correct values
predict(alm, stackloss)[1:10]
# predict(partdata) gives wrong values
predict(alm, stackloss[1:10,])
#
I guess - but haven't confirmed - that with multivariate newdata 
predict.lm(alm, newdata) calculates new orthogonal polynomials based on 
newdata rather than applying the original coefficients.


Below I append versions of:
a) polym edited to address the three points above;
b) poly slightly edited to reflect the changes in polym;
c) predict.poly unaltered, just to get it in the same environment as 
polym and poly for testing.

After implementing these the three sets of predictions above all agree.

I'm very ready to believe that I've got the wrong end of the stick 
and/or my suggestions can be improved so I welcome correction.


Otherwise, how do I go about getting these changes implemented?
I see stats is maintained by R Core Team. Are they likely to pick it up 
from here, or do I need to take any other action?


Best regards

Keith Jewell

### polym ##
polym - function (..., degree = 1, coefs = NULL, raw = FALSE)
# add coefs argument
{
  if(is.null(coefs)) {
dots - list(...)
nd - length(dots)
if (nd == 0)
  stop(must supply one or more vectors)
if (nd == 1)
  return(poly(dots[[1L]], degree, raw = raw))
n - sapply(dots, length)
if (any(n != n[1L]))
  stop(arguments must have the same length)
z - do.call(expand.grid, rep.int(list(0:degree), nd))
s - rowSums(z)
ind - (s  0)  (s = degree)
z - z[ind, ]
s - s[ind]
aPoly - poly(dots[[1L]], degree, raw = raw) # avoid 2 calcs
res - cbind(1, aPoly)[, 1 + z[, 1]]
# attribute coefs = list of coefs from individual variables
if (!raw) coefs - list(attr(aPoly, coefs))
for (i in 2:nd) {
  aPoly - poly(dots[[i]], degree, raw = raw)
  res - res * cbind(1, aPoly)[, 1 + z[, i]]
  if (!raw) coefs - c(coefs, list(attr(aPoly, coefs)))
}
colnames(res) - apply(z, 1L, function(x) paste(x, collapse = .))
attr(res, degree) - as.vector(s)
if (!raw) attr(res, coefs) - coefs
class(res) - c(poly, matrix) # add poly class
res
  }
  else
  {
nd - length(coefs)# number of variables
newdata - as.data.frame(list(...)) # new data
if (nd != ncol(newdata)) stop(wrong number of columns in newdata)
z - do.call(expand.grid, rep.int(list(0:degree), nd))
s - rowSums(z)
ind - (s  0)  (s = degree)
z - z[ind, ]
res - cbind(1, poly(newdata[[1]], degree=degree, 
coefs=coefs[[1]]))[, 1 + z[, 1]]
for (i in 2:nd) res - res*cbind(1, poly(newdata[[i]], 
degree=degree, coefs=coefs[[i]]))[, 1 + z[, i]]

colnames(res) - apply(z, 1L, function(x) paste(x, collapse = .))
res
  }
}
##

 poly ##
poly - function (x, ..., degree = 1, coefs = NULL, raw = FALSE)
{
  dots - list(...)
  if (nd - length(dots)) {
if (nd == 1  length(dots[[1L]]) == 1L)
  degree - dots[[1L]]
# pass coefs argument as well
else return(polym(x, ..., degree = degree, coefs=coefs, raw = raw))
  }
  if (is.matrix(x)) {
m - unclass(as.data.frame(cbind(x, ...)))
# pass coefs argument as well
return(do.call(polym, c(m, degree = degree, raw = raw, 
list(coefs=coefs

  }
  if (degree  1)
stop('degree' must be at least 1)
  if (anyNA(x))
stop(missing values are not allowed in 'poly')
  n - degree + 1
  if (raw) {
Z - outer(x, 1L:degree, ^)
colnames(Z) - 1L:degree
attr(Z, degree) - 1L:degree
class(Z) - c(poly, matrix)
return(Z)
  }
  if (is.null(coefs)) {
if (degree = length(unique(x)))
  stop('degree' must be less than number of unique points)
xbar - mean(x)
x - x - xbar
X - outer(x, seq_len(n) - 1, ^)
QR - qr(X)
if (QR$rank  degree)
  stop('degree' must be less than number of unique points)
z - QR$qr
z - z * (row(z) == col(z))
raw - qr.qy(QR, z)
norm2 - colSums(raw^2)
alpha - (colSums(x * raw^2)/norm2 + xbar)[1L:degree]
Z - raw/rep(sqrt(norm2), each = length(x))
colnames(Z) - 1L:n - 1L
Z - Z[, -1, drop = FALSE]
attr(Z, degree) - 1L:degree
attr(Z, coefs) - list(alpha = alpha, norm2 = c(1,
   

Re: [R] How to assign value to a variable dynamically constructed

2015-07-10 Thread Bastien Tran
Dear all,

Provided I understood correctly, shouldn't assign() do the trick? Most similar 
threads seem to include this approach (among others, indeed).

Regards,
Bastien


On Wednesday, July 8, 2015 at 7:30:04 PM UTC+2, William Dunlap wrote:
 You can use an environment instead of a list using the same [[ syntax.  It
 is like 'get0(..., inherit=FALSE)' on the left side of the - and like
 'assign(...)' on the right side.   E.g.,
myData - new.env()
varName - v1
myData[[varName]] - 1:10
myData[[varName]][4] - myData[[varName]][4] * 100
myData[[varName]]
#  [1]   1   2   3 400   5   6   7   8   9  10
names(myData)
# [1] v1
 (Before R-3.2.0 or so, you had to use objects(myData,all=TRUE) if
 myData was an environment and names(myData) if it was a list.  Now
 names() works for environments.)
 
 It is better to use a dedicated environment (or list) for each set of
 related
 variables so that name collisions do not cause problems.
 
 
 Bill Dunlap
 TIBCO Software
 wdunlap tibco.com
 
 On Wed, Jul 8, 2015 at 10:06 AM, Greg Snow 538...@gmail.com wrote:
 
  This is FAQ 7.21.
 
  The most important part of the answer in FAQ 7.21 is the last section
  where it states that it is often easier to use a list rather than
  messing around with trying to dynamically name global variables.
 
  If you tell us what you are trying to accomplish then we may have
  better advice.  The route you are headed down now usually leads to
  inefficient code and hard to find bugs.
 
  On Tue, Jul 7, 2015 at 2:53 PM, Jun Shen jun.shen...@gmail.com wrote:
   Dear list,
  
   Let's say we have a variable (id), whose name is dynamically constructed.
   This variable represents a vector or data frame with many elements. Now I
   want to specifically assign a value to one of the elements. I couldn't
  get
   it right.
  
   test - 'id' # id is dynamically constructed through paste()
  
   id - 1:4
  
   # I can get the element by doing
  
   get(test)[2]
  
   # Now I want to assign a value to the second element of this dynamical
   variable.
  
   get(test)[2] - 5  # doesn't work.
  
   Thanks a lot.
  
   Jun Shen
  
   [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
   https://stat.ethz.ch/mailman/listinfo/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
 
  __
  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] (no subject)

2015-07-10 Thread Bert Gunter
Sorry Lia. We don't do homework on this list. You can imagine how
clogged it would be if we did.

Maybe you'll get lucky and someone will answer you privately.
Otherwise, seek help from your teachers, fellow students, and/or
course homework forums.

Cheers,
Bert


Bert Gunter

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
   -- Clifford Stoll


On Fri, Jul 10, 2015 at 2:17 AM, Lia LEE ljylia.0...@gmail.com wrote:
 Hello forum members,

 I am taking this R course which I have to admit that it is beyond my
 capability. I am asked to analyze the following data(file attached) according
 to the question provided below:

 1. The file [data_13-9.txt] contains a data of length 225, which seems to
 have some cycle pattern.
 (1) Fit a suitable model for this data, then report the model equation.
 (2) Provide the forecast values for 3-steps ahead and 6-steps ahead.

 I am desperately seeking for your help, since I really don't know where to
 start.. I have done plot.ts(data.13-6), but not further. Above question
 is just part of the whole task, but I believe solving this would be very
 much helpful for me to jump in to the other questions. It would be easier
 for me to follow if your answer is in R script..
 I appreciate your patience and help.
 Thank you so much in advance!

 Cheers,
 Lia

 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] tcltk2 entry box

2015-07-10 Thread Matthew

Thank you very much, Greg, for the tkwait commands.

 I am just starting to try out examples on the sciviews web page to get 
a feel for tcltk in R and the tkwait.variable and tkwait.window seem 
like they could be very useful to me. I will add these in to my practice 
scripts and see what I can do with them.


Matthew

On 7/9/2015 5:31 PM, Greg Snow wrote:

If you want you script to wait until you have a value entered then you
can use the tkwait.variable or tkwait.window commands to make the
script wait before continuing (or you can bind the code to a button so
that you enter the value, then click on the button to run the code).

On Wed, Jul 8, 2015 at 7:58 PM, Matthew McCormack
mccorm...@molbio.mgh.harvard.edu wrote:

Wow !  Very nice.  Thank you very much, John.  This is very helpful and just
what I need.
Yes, I can see that I should have paid attention to tcltk before going to
tcltk2.

Matthew


On 7/8/2015 8:37 PM, John Fox wrote:

Dear Matthew,

For file selection, see ?tcltk::tk_choose.files or ?tcltk::tkgetOpenFile .

You could enter a number in a tk entry widget, but, depending upon the
nature of the number, a slider or other widget might be a better choice.

For a variety of helpful tcltk examples see
http://www.sciviews.org/_rgui/tcltk/, originally by James Wettenhall but
now maintained by Philippe Grosjean (the author of the tcltk2 package).
(You
probably don't need tcltk2 for the simple operations that you mention, but
see ?tk2spinbox for an alternative to a slider.)

Best,
   John

---
John Fox, Professor
McMaster University
Hamilton, Ontario, Canada
http://socserv.socsci.mcmaster.ca/jfox/





-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Matthew
Sent: July-08-15 8:01 PM
To: r-help
Subject: [R] tcltk2 entry box

Is anyone familiar enough with the tcltk2 package to know if it is
possible to have an entry box where a user can enter information (such
as a path to a file or a number) and then be able to use the entered
information downstream in a R script ?

The idea is for someone unfamiliar with R to just start an R script that
would take care of all the commands for them so all they have to do is
get the script started. However, there is always a couple of pieces of
information that will change each time the script is used (for example,
a different file will be processed by the script). So, I would like a
way for the user to input that information as the script ran.

Matthew McCormack

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


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 embed a 3D plot created by “rgl” into gWidgets ggraphics device“?

2015-07-10 Thread Duncan Murdoch
On 10/07/2015 8:43 AM, just_rookie wrote:
 I created some 3D cubes by using rgl package. The next step is to embed the 
 3D plot(rgl device) into ggraphics device from the gWidgets package, 
 but I have no idea how to implement it. Is there a way to implement by 
 gWidgets or other package? Any help? Thank you in advance!

Is there an existing widget that displays HTML, and can display WebGL?
Then it's probably easiest to use rgl::writeWebGL to create the
Javascript code, and that other widget to display it.

If you want it displayed using native OpenGL code, it's likely a lot
more work.  On Windows it's probably easiest; I don't know how hard it
would be to do on other platforms.  I would not personally spend any
time on it.

Duncan Murdoch

 My code:
 library(rgl)
 library(scatterplot3d)
 library(gWidgets)
 options(guiToolkit=RGtk2)
 
 
 df-data.frame(x=c(1,2,3,4),
y=c(2,4,6,8),
z=c(3,6,9,12),
value=c(33,43,75,21))
 
 clr - df$value/max(df$value)
 f - colorRamp(c(green, yellow, purple, red))
 
 ## 3D PLOT
 for(i in 1:length(df$x)){
   shade3d(translate3d(scale3d(cube3d(col=rgb(f(clr[i])/255),alpha=0.15 ),
  10.0, 10.0, 
 2.5),df$x[i],df$y[i],df$z[i]))
 } 
 
 window - gwindow(TEST, width = 800, height= 600, visible = FALSE)
 group - ggroup(cont = window, expand = TRUE)
 
 loadBtn - gbutton(display, cont = group)
 
 addHandlerChanged(loadBtn, handler = function(h,...){
   sudwin-gwindow(3D,visible = TRUE)
   dev - ggraphics(cont=subwin)
    DO NOT KNOW HOW TO DO NEXT...
 })
 visible(window)-TRUE
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Corrected: approaches to matrix multiplication of each layer of 3-d array with different matrix

2015-07-10 Thread Jeff Newmiller
EE[,,1] - A[,,1] %*% B[,,1]
EE[,,2] - A[,,2] %*% B[,,2]
EE[,,3] - A[,,3] %*% B[,,3]
etc.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On July 10, 2015 8:37:37 AM PDT, Ranjan Maitra maitra.mbox.igno...@inbox.com 
wrote:
What does it mean to unroll the loop?

Thanks!

Ranjan


On Fri, 10 Jul 2015 07:07:15 -0700 Jeff Newmiller
jdnew...@dcn.davis.ca.us wrote:

 Strictly speaking, the answer is yes because you can unroll the loop,
but that probably is not what you really want or need to do.
 
 Your example seems about right, but it is not clear how you plan to
make 44 conform with 5500.

---
 Jeff NewmillerThe .   .  Go
Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
Go...
   Live:   OO#.. Dead: OO#.. 
Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#. 
rocks...1k

---
 Sent from my phone. Please excuse my brevity.
 
 On July 10, 2015 6:44:19 AM PDT, Ranjan Maitra
maitra.mbox.igno...@inbox.com wrote:
 Hi,
 
 Sorry to post again, but there is a careless error in my first R
code
 snippet:
 
 --- begin R code ---
  
 AA - array(1:60, dim = c(5500,44,33))
 BB - array(1:60, dim = c(44,44,33))
  
  
 arraymatprod - function(A, B) {
 EE - array(dim=dim(A));
 for (i in 1:dim(A)[3]) EE[,,i] - A[,,i] %*% B[,,i]
 EE
 }
 
 system.time(arraymatprod(AA, BB))
 
 --- end R code ---
 
 The second snippet is correct:
 
 --- begin R code ---
 
 arraymatrixproduct - function(A, B) {
 require(abind)
 dA - dim(A)[1]
 AB - abind(A, B, along = 1)
 array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA, ]
%*%
 mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
 }
 
 system.time(arraymatrixproduct(AA, BB))
 
 --- end R code ---
 
 However, the second is almost twice as long as the first snippet.
 
 Many thanks,
 Ranjan
 
 
 On Fri, 10 Jul 2015 08:23:49 -0500 Ranjan Maitra
 maitra.mbox.igno...@inbox.com wrote:
 
  Dear friends,
  
  I have two 3-d arrays of appropriate dimensions. I want to
 postmultiply the 2-D matrix layers of the first with the 2-D matrix
 layers of the second. Can I do this easily in R avoiding loops?
  
  As an example:
  
  --- begin R code ---
  
  AA - array(1:60, dim = c(5500,44,33))
  BB - array(1:60, dim = c(44,44,33))
  
  
  arraymatprod - function(A, B) {
  EE - array(dim=dim(A));
  for (i in 1:3) EE[,,i] - A[,,i] %*% B[,,i]
  EE
  }
  
  system.time(arraymatprod(AA, BB))
  
  --- end R code ---
  
  So, is there a way to do this without the loop?
  
  Of course, I could abind the arrays and then use apply with an
 appropriate function which would be as follows:
  
  --- begin R code ---
  
  arraymatrixproduct - function(A, B) {
require(abind)
dA - dim(A)[1]
AB - abind(A, B, along = 1)
array(apply(X = AB, MARGIN = 3, FUN = (function(mat) ((mat[1:dA,
]
 %*% mat[(dA+1):(dim(AB)[1]),], dim = dim(A))
  }
  
  system.time(arraymatrixproduct(AA, BB))
  
  --- end R code ---
  
  However, this turns out to be slower -- perhaps because of the use
of
 abind and filling the array inside the function.
  
  I just wanted suggestions to get this operation done more
 efficiently.
  
  Many thanks and best wishes,
  Ranjan
  
  
  Publish your photos in seconds for FREE
  TRY IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if4
  
  __
  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 

Re: [R] How to assign value to a variable dynamically constructed

2015-07-10 Thread William Dunlap
Yes, assign() and get() can do this, but I think the [[]] syntax is simpler
and makes it easier to switch between lists and environments for
data organization.

E.g., the translation of
   myData[[varName]][4] - myData[[varName]][4] * 100
where myData is an environment to the get/assign style
would be something like
   tmp - get(varName, envir=myData)
   tmp[4] - tmp[4] * 100
   assign(varName, tmp, envir=myData)

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Jul 10, 2015 at 9:44 AM, Bastien Tran bastien.t...@gmail.com
wrote:

 Dear all,

 Provided I understood correctly, shouldn't assign() do the trick? Most
 similar threads seem to include this approach (among others, indeed).

 Regards,
 Bastien


 On Wednesday, July 8, 2015 at 7:30:04 PM UTC+2, William Dunlap wrote:
  You can use an environment instead of a list using the same [[ syntax.
 It
  is like 'get0(..., inherit=FALSE)' on the left side of the - and like
  'assign(...)' on the right side.   E.g.,
 myData - new.env()
 varName - v1
 myData[[varName]] - 1:10
 myData[[varName]][4] - myData[[varName]][4] * 100
 myData[[varName]]
 #  [1]   1   2   3 400   5   6   7   8   9  10
 names(myData)
 # [1] v1
  (Before R-3.2.0 or so, you had to use objects(myData,all=TRUE) if
  myData was an environment and names(myData) if it was a list.  Now
  names() works for environments.)
 
  It is better to use a dedicated environment (or list) for each set of
  related
  variables so that name collisions do not cause problems.
 
 
  Bill Dunlap
  TIBCO Software
  wdunlap tibco.com
 
  On Wed, Jul 8, 2015 at 10:06 AM, Greg Snow 538...@gmail.com wrote:
 
   This is FAQ 7.21.
  
   The most important part of the answer in FAQ 7.21 is the last section
   where it states that it is often easier to use a list rather than
   messing around with trying to dynamically name global variables.
  
   If you tell us what you are trying to accomplish then we may have
   better advice.  The route you are headed down now usually leads to
   inefficient code and hard to find bugs.
  
   On Tue, Jul 7, 2015 at 2:53 PM, Jun Shen jun.shen...@gmail.com
 wrote:
Dear list,
   
Let's say we have a variable (id), whose name is dynamically
 constructed.
This variable represents a vector or data frame with many elements.
 Now I
want to specifically assign a value to one of the elements. I
 couldn't
   get
it right.
   
test - 'id' # id is dynamically constructed through paste()
   
id - 1:4
   
# I can get the element by doing
   
get(test)[2]
   
# Now I want to assign a value to the second element of this
 dynamical
variable.
   
get(test)[2] - 5  # doesn't work.
   
Thanks a lot.
   
Jun Shen
   
[[alternative HTML version deleted]]
   
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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
  
   __
   R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
   https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Rich Shepard

On Fri, 10 Jul 2015, Roy Mendelssohn - NOAA Federal wrote:


Don’t know for certain but might this help:


  It's very interesting, but does not appear to resolve the immediate need
to write the R code in a knitr chunk for incorporation into the compiled LyX
document.

  The gridGraphics package description notes that both lattice and ggplot2
are built on the grid framework, and the new gridGraphics package will
'echo' either to a grid format for further tweaking. Unless the knitr
package will accept the echoed image ...

  It does not. Here is what the compiled document shows (the R code is
included in the document):

pdf('carlin-1-description.pdf')
xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T)
require(gridGraphics)

## Loading required package:  gridGraphics
## Loading required package:  grid

grid.echo()

## Error in grid.echo.recordedplot(recordPlot(), newpage, prefix): No
## graphics to replay

dev.off()

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Hadley Wickham
Have you tried explicitly print()ing the lattice graphics in your knitr doc?

Hadley

On Friday, July 10, 2015, Rich Shepard rshep...@appl-ecosys.com wrote:

   Hadley's ggplot2 book is quite old and a new version is in the works, but
 not yet out. I've been using lattice graphics but the knitr package doesn't
 support lattice, only basic plots and ggplot2. My Web searches for Trellis
 plots in ggplot2 equivalent to those in lattice have not been productive.

   I would appreciate a pointer to a resource that would teach me how to
 translate from lattice xyplot() to ggplot2 ggplot().

   This is one such plot needing translation:

 xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T)

 Rich

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



-- 
http://had.co.nz/

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Rich Shepard

On Fri, 10 Jul 2015, Hadley Wickham wrote:


Have you tried explicitly print()ing the lattice graphics in your knitr
doc?


Hadley,

  Only now. Had not thought of trying this before.

pdf('carlin-1-descriptive.pdf')
print(xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T))

No error messages, but no graphic, either. Without specifying the pdf
device, TeX complains it cannot find a graphics device and lists bit-mapped,
ps and svg devices.

  Most likely I do not have the correct syntax.

Thanks,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Jeff Newmiller
I don't actually use lattice very much, but I have no difficulty setting up a 
lattice plot in a knitr/rmarkdown file, and can think of no reason why you 
might have concluded that knitr does not support lattice.

Sorry, not going to translate your non-reproducible example... please go the 
extra little effort to dput some example data so we can communicate clearly 
about your problem. [1]

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
 
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On July 10, 2015 2:09:45 PM PDT, Rich Shepard rshep...@appl-ecosys.com wrote:
Hadley's ggplot2 book is quite old and a new version is in the works,
but
not yet out. I've been using lattice graphics but the knitr package
doesn't
support lattice, only basic plots and ggplot2. My Web searches for
Trellis
plots in ggplot2 equivalent to those in lattice have not been
productive.

  I would appreciate a pointer to a resource that would teach me how to
translate from lattice xyplot() to ggplot2 ggplot().

   This is one such plot needing translation:

xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T)

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Roy Mendelssohn - NOAA Federal
Don’t know for certain but might this help:

http://journal.r-project.org/archive/2015-1/murrell.pdf

From the latest issue of R Journal.  

Abstract The gridGraphics package provides a function, grid.echo(), that can be 
used to convert a plot drawn with the graphics package to a visually identical 
plot drawn using grid. This conversion provides access to a variety of grid 
tools for making customisations and additions to the plot that are not possible 
with the graphics package.

-Roy

 On Jul 10, 2015, at 2:09 PM, Rich Shepard rshep...@appl-ecosys.com wrote:
 
  Hadley's ggplot2 book is quite old and a new version is in the works, but
 not yet out. I've been using lattice graphics but the knitr package doesn't
 support lattice, only basic plots and ggplot2. My Web searches for Trellis
 plots in ggplot2 equivalent to those in lattice have not been productive.
 
  I would appreciate a pointer to a resource that would teach me how to
 translate from lattice xyplot() to ggplot2 ggplot().
 
  This is one such plot needing translation:
 
 xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T)
 
 Rich
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

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

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

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Rich Shepard

  Hadley's ggplot2 book is quite old and a new version is in the works, but
not yet out. I've been using lattice graphics but the knitr package doesn't
support lattice, only basic plots and ggplot2. My Web searches for Trellis
plots in ggplot2 equivalent to those in lattice have not been productive.

  I would appreciate a pointer to a resource that would teach me how to
translate from lattice xyplot() to ggplot2 ggplot().

  This is one such plot needing translation:

xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T)

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Rich Shepard

On Fri, 10 Jul 2015, Roy Mendelssohn - NOAA Federal wrote:


Don’t know for certain but might this help:
http://journal.r-project.org/archive/2015-1/murrell.pdf
From the latest issue of R Journal.


Roy,

  Thanks. I'll certainly read that article.

Carpe weekend,

Rich

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Hadley Wickham
You shouldn't be explicitly opening a device in a knitr document. I think
maybe you should post a minimal document so we can figure out what's going
wrong.

Hadley

On Friday, July 10, 2015, Rich Shepard rshep...@appl-ecosys.com wrote:

 On Fri, 10 Jul 2015, Hadley Wickham wrote:

  Have you tried explicitly print()ing the lattice graphics in your knitr
 doc?


 Hadley,

   Only now. Had not thought of trying this before.

 pdf('carlin-1-descriptive.pdf')
 print(xyplot(value ~ sampdate | variable, data=carlin.1.melt, rm.na = T))

 No error messages, but no graphic, either. Without specifying the pdf
 device, TeX complains it cannot find a graphics device and lists
 bit-mapped,
 ps and svg devices.

   Most likely I do not have the correct syntax.

 Thanks,

 Rich

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



-- 
http://had.co.nz/

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/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] Trellis Plots: translating lattice xyplot() to ggplot()

2015-07-10 Thread Rich Shepard

On Fri, 10 Jul 2015, Hadley Wickham wrote:


You shouldn't be explicitly opening a device in a knitr document.


Hadley,

  Didn't think so.


I think maybe you should post a minimal document so we can figure out
what's going wrong.


  Agreed. Attached are the raw data (carlin.csv) and a stripped down LyX
document with the knitr chunks.

  This is my first attempt to use knitr; I'm reading the knitr book and
that's where I got the impression that lattice graphics are not supported.

Richsiteid,sampdate,Temp.h2o,Temp.air,Disc.cfs,Turb,SC,DO,pH,ANC,HCO3,CO3,Alk,Hard,TDS,TSS,N.tot,N.org,NH4,NO3,NO2,PO4,C,Ca,Mg,Na,K,Cl,SO4,F,Si,As,Ba,Be,Cd,Cr,Co,Cu,Fe,Pb,Mn,Mo,Ni,Ag,Sr,V,Zi,Al,Li,Se,CN,Hg
10321000,1965-10-01,,,98,,490,,8.4,,238,4,,150,,40,12,46,,
10321000,1965-11-01,,,141,,507,,8.3,213,252,4,,170,,50,11,42,,
10321000,1965-12-01,,,128,,564,,8.1,238,290,0,,190,359,56,13,47,6.4,16,37,0.5,40,
10321000,1966-01-01,,,122,,506,,8.2,212,259,0,,170,321,50,11,45,6.1,16,34,0.6,31,
10321000,1966-01-17,,,97,,551,,8.5,241,276,9,,200,,58,13,48,,
10321000,1966-02-01,,,108,,506,,8.2,216,263,0,,180,,52,11,42,,
10321000,1966-03-01,,,384,,516,,7.7,201,245,0,,160,,46,11,46,8,
10321000,1966-03-18,,,701,,628,,8.1,235,286,0,,190,,51,16,61,8.5,
10321000,1966-04-01,,,612,,470,,8,189,231,0,,160,301,43,12,40,6.3,14,37,0.5,34,
10321000,1966-04-11,,,541,,423,,8,172,210,0,,140,,40,10,34,5.4,
10321000,1966-04-18,,,355,,466,,8.1,193,235,0,,160,,43,12,39,5.9,
10321000,1966-05-01,,,167,,498,,8,208,253,0,,170,,46,13,42,6.8,
10321000,1966-05-06,,,260,,420,,8.1,181,221,0,,140,,41,10,33,5.4,
10321000,1966-07-01,,,7,,566,,8,226,275,0,,180,450,47,16,52,96,21,48,0.6,34,
10321000,1966-08-01,,,3.9,,550,,8.1,210,256,0,,170,,40,17,51,9.7,
10321000,1966-09-01,,,4.1,,536,,8.4,208,254,0,,170,,41,17,48,8.9,
10321000,1966-10-01,,,7.7,,546,,8.4,220,260,4,,190,340,48,16,46,8.5,19,43,0.5,27,
10321000,1966-11-01,,,16,,536,,8.4,224,263,5,,180,,49,15,45,7.6,
10321000,1966-12-01,,,31,,533,,8.6,222,248,11,,180,336,50,13,47,7.5,14,37,0.5,34,
10321000,1966-12-16,,,30,,615,,8.6,264,296,13,,210,,60,14,56,8.7,
10321000,1967-01-01,,,43,,517,,8.8,214,228,16,,170,333,50,12,48,7.3,19,40,0.5,28,
10321000,1967-02-01,,,72,,513,,8.7,217,234,15,,180,,51,12,46,6.9,
10321000,1967-02-12,,,113,,474,,8.3,189,230,3,,160,,46,11,41,6.8,
10321000,1967-03-01,,,232,,464,,8.5,174,212,7,,150,,44,10,41,6.6,
10321000,1967-03-25,,,422,,498,,8.5,179,218,6,,160,,48,10,43,6.5,
10321000,1967-04-01,,,333,,448,,8.5,164,200,5,,150,283,42,11,39,5.7,15,40,0.5,26,
10321000,1967-05-01,,,327,,451,,8.5,165,201,6,,150,,43,10,38,5.8,
10321000,1967-05-10,,,406,,371,,8.3,127,155,2,,110,,29,9.5,34,5.7,
10321000,1967-05-14,,,396,,435,,8.3,158,193,2,,160,,45,11,38,6.7,
10321000,1967-05-20,,,844,,365,,8,147,179,0,,150,,45,8.1,25,5.6,
10321000,1967-06-01,,,1560,,443,,8.4,189,230,4,,180,,55,10,35,6.7,
10321000,1967-07-01,,,1340,,386,,8.5,175,213,13,,150,255,47,8.6,27,4.8,7.4,14,0.5,28,
10321000,1967-07-11,,,651,,406,,8.3,187,228,2,,170,,55,9.1,27,5,
10321000,1967-07-21,,,254,,453,,8.2,207,252,0,,190,,58,10,35,6,
10321000,1967-08-01,,,48,,,
10321000,1967-08-01,,,48,,525,,8.2,223,272,0,,190,,53,13,47,7.4,
10321000,1967-09-01,,,18,,508,,8.1,210,256,0,,180,,46,15,45,7.9,
10321000,1967-10-01,,,20,,556,,8.4,221,255,7,,180,322,47,15,45,8.2,16,32,0.6,24,
10321000,1967-10-01,,,7.7,,546,,8.4,213,260,4,,190,340,0.0248,16,46,8.5,19,43,0.5,27,
10321000,1967-10-09,,,27,,612,,8.4,242,281,7,,190,,53,15,57,11,
10321000,1967-10-17,,,23,,586,,8.2,238,290,0,,190,,53,15,49,8.3,
10321000,1967-11-01,,,36,,582,,8.4,238,278,6,,190,,55,14,50,7.8,
10321000,1967-12-01,,,44,,565,,8.2,239,292,0,,170,,50,12,53,8.2,