Re: [R] Time Series Have Date Show Days of the Week

2012-08-11 Thread G See
Alternatively, xts has a convenience function for this

.indexwday(SPY)
will give weekdays as numbers with Sunday being 0 and Saturday being 6.

There are also several similar functions
 .indexDate(x)
 .indexday(x)
 .indexmday(x)
 .indexwday(x)
 .indexweek(x)
 .indexmon(x)
 .indexyday(x)
 .indexyear(x)
 .indexhour(x)
 .indexmin(x)
 .indexsec(x)

Regards,
Garrett

On Wed, Aug 1, 2012 at 6:04 PM, R. Michael Weylandt
michael.weyla...@gmail.com wrote:
 On Wed, Aug 1, 2012 at 12:54 PM, Douglas Karabasz
 doug...@sigmamonster.com wrote:
 I used quantmod to pull in price data from the ticker SPY.  The data has
 date and closing price.  I would like to show the day of the week for each
 closing price.  Is that possible?  Also, I would like to add the back into
 the data frame in a new column without changing the structure of the data
 set if possible.



  SPY

 2009-01-02 92.96

 2009-01-05 92.85

 2009-01-06 93.47

 2009-01-07 90.67

 2009-01-08 91.04

 2009-01-09 89.09



 str(SP500)

 An 'xts' object from 2009-01-02 to 2012-07-31 containing:

   Data: num [1:902, 1] 93 92.8 93.5 90.7 91 ...

 - attr(*, dimnames)=List of 2

   ..$ : NULL

   ..$ : chr SPY

   Indexed by objects of class: [Date] TZ:

   xts Attributes:

 List of 4

 $ tclass : chr [1:2] POSIXct POSIXt

 $ tzone  : chr 

 $ src: chr yahoo

 $ updated: POSIXct[1:1], format: 2012-07-31 17:59:16


 Hi Doug,

 No, this isn't quite doable. I'll give a somewhat technical
 description of why and then I'll propose a work around

  Technical Stuff ---

 An xts object consists of two fundamental parts -- an index which is
 numeric (seconds since the epoch usually) and its coredata which is,
 in your case, the prices. The coredata is and must be all of the
 same type -- either integer, double, or string; internally, this is
 because it's all actually a matrix, which is in turn an atomic vector,
 and to be any sort of performant, we need them all of the same type.
 So there's no way for the coredata to have the _number_ 24 and the
 _string_ day of the week tuesday.  We'll come back to this though.

 So you might ask about the index... xts hard-codes selected index
 classes to work. None of them currently have printing methods that
 write out the day of the week like you want, though you could define
 your own time index and use it in zoo if desired. That's almost
 certainly overkill though.

  What to do 

 In light of the above, the easiest thing is probably to encode the day
 of the week as an integer if you really need it for calculations:

 as.numeric(factor(strptime(index(x), %A)))

 will create that and then you can cbind() it on.

 Alternatively, you can cbind() just strptime(index(... on and you will
 change the coredata() to character. I'd do this instead if you're only
 looking for human output. Even better on the just look pretty front
 would be to make it into a data.frame for printing only:

 data.frame(x, `Day of the Week` = strptime(index(x), %A))

 but again -- that's only for printing: it will destroy the xts-ness.

 Best,
 Michael



 Thank you,

 Douglas




 [[alternative HTML version deleted]]

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

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Installing packages from RProfile.site file

2012-07-18 Thread G See
abhisarihan,

Please don't crosspost!
http://stackoverflow.com/questions/11530800/installing-packages-from-rprofile-site-file

Thanks,
Garrett

On Tue, Jul 17, 2012 at 2:34 PM, abhisarihan abhisari...@gmail.com wrote:
 I am trying to install custom packages upon starting R. A lot of the code
 that is written by us right now is available for editing to the users. To
 try and protect the code, I am packaging the production level code and
 having the users install it on their machine during start up.

 However, when I try to install packages in RProfile.site file, the program
 goes into a loop and R is constantly launched over and over. I noticed that
 a lock file for the package is created along with the package in the library
 folder within R.

 Here is the code I have added to the site file:

 if(length(grep(customPackage, installed.packages()[,1]))==0) {
 install.packages(customPackage, repos=NULL, type=source)
 }

 When I try to run this code after starting R (without changing the site
 file), it installs the package perfectly fine and moves on. However, when I
 try to do it through the RProfile file, that's when it creates the problems.

 Any help on this matter would be greatly appreciated!

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Installing-packages-from-RProfile-site-file-tp4636794.html
 Sent from the R help mailing list archive at Nabble.com.

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

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


Re: [R] moving averages on specific interval and merge

2012-05-12 Thread G See
Dear R-help,

Please direct answers to this question to the R-sig-finance list copy
of this question
(http://stat.ethz.ch/pipermail/r-sig-finance/2012q2/010209.html)

Thank you,
Garrett

On Sat, May 12, 2012 at 4:39 AM, Jim Green
student.northwest...@gmail.com wrote:
 Greetings!

 I am using quantstrat and xts to do some intraday work and come up
 with this problem. the xts object temp in the following example is
 attached as and rda file.

 head(temp)
                   A.Open A.High  A.Low A.Close A.Volume
 2012-02-01 08:29:00  42.47  43.76 41.410   43.76     2071
 2012-02-01 09:30:00  43.38  43.38 42.970   43.15    40300
 2012-02-01 09:31:00  43.14  43.28 43.130   43.28    14990
 2012-02-01 09:32:00  43.27  43.37 43.270   43.37     3300
 2012-02-01 09:33:00  43.37  43.50 43.370   43.48     3056
 2012-02-01 09:34:00  43.49  43.50 43.396   43.44    10968

 tail(temp)
                    A.Open  A.High   A.Low A.Close A.Volume
 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650      170
 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710      474
 2012-03-27 16:10:00 45.9131 45.9131 45.9131 45.9131     1800
 2012-03-27 16:13:00 45.6952 45.6952 45.6952 45.6952      300
 2012-03-27 16:15:00 45.9368 45.9368 45.9368 45.9368      791
 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000    22000


 I would like to calculate moving averages of minute volume for
 specific minute and merge with the original minute ohlc data.

 take 09:40:00 for example, calculate the average previous 10 days
 volume between 09:39:00 to 09:40:00 and merge with exiting data.

 ultimately I want to get an xts object with columns

 Open   High   Low   Close   Volume   Average.Volume.at.current.interval
 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650      170   177
 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710      474  500
 ...
 ...
 ..
 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000    22000 1000

 any pointers are appreciated!

 Jim.

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


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


Re: [R] setwd et chaines de caracteres

2012-03-17 Thread G See
R tmp - tempdir()
R dir.create(file.path(tmp, a space))
R setwd(file.path(tmp, a space))
R getwd()
[1] /private/var/folders/ss/9z_gwf2j5bbbrhnv67_gh770gp/T/Rtmpg1MLIT/a
space


On Sat, Mar 17, 2012 at 8:08 AM, David Winsemius dwinsem...@comcast.net wrote:

 On Mar 17, 2012, at 3:43 AM, André Smolarz wrote:

 Bonjour,

 J'utilise R sous Mac OS X 10.6.8 et je souhaiterais savoir s'il est
 possible d'utiliser la commande setwd() avec un nom de réperoire
 contenant des espaces ?

 Si oui, comment faire ?


 I had no trouble using setwd() with a  folder name having with a space in
 it. If you are having difficulty you need to describe your problems.

 Mac specific questions are supposed to go to the R-SIG-Mac mailing list.

 --

 David Winsemius, MD
 West Hartford, CT

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] subsetting by cell value with a list

2012-03-15 Thread G See
 my.df - data.frame(IDX=1:42, x=rnorm(1:42))
 my.df[my.df$IDX %in% c(17, 42), ]
   IDX  x
17  17 -0.5110095
42  42 -1.0686427

Garrett

On Thu, Mar 15, 2012 at 3:25 PM, Ed Siefker ebs15...@gmail.com wrote:
 I would like to subset by dataframe by matching all rows that have any value
 from a list of values.  I can get it to work if I have exactly one value,
 I'm not
 sure how to do it with a list of values though.

 This works and gives me exactly one line:
 my.df[ which( mydf$IDX==17)), ]

 I would like to do something like this:
 my.df[ which( mydf$IDX==c(17, 42), ]

 Obviously that won't work, but I hope the meaning is clear.
 What's the right way to express this?

        [[alternative HTML version deleted]]

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

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


Re: [R] subsetting by cell value with a list

2012-03-15 Thread G See
On second thought, I must not understand your question because your
code works fine for me.

 my.df[ which(my.df$IDX == c(17, 42)), ]
   IDX  x
17  17 -0.5110095
42  42 -1.0686427

 my.df[my.df$IDX == c(17, 42), ]
   IDX  x
17  17 -0.5110095
42  42 -1.0686427

Can you provide sample data?  What is the output of dput(head(my.df))


On Thu, Mar 15, 2012 at 3:38 PM, G See gsee...@gmail.com wrote:
 my.df - data.frame(IDX=1:42, x=rnorm(1:42))
 my.df[my.df$IDX %in% c(17, 42), ]
   IDX          x
 17  17 -0.5110095
 42  42 -1.0686427

 Garrett

 On Thu, Mar 15, 2012 at 3:25 PM, Ed Siefker ebs15...@gmail.com wrote:
 I would like to subset by dataframe by matching all rows that have any value
 from a list of values.  I can get it to work if I have exactly one value,
 I'm not
 sure how to do it with a list of values though.

 This works and gives me exactly one line:
 my.df[ which( mydf$IDX==17)), ]

 I would like to do something like this:
 my.df[ which( mydf$IDX==c(17, 42), ]

 Obviously that won't work, but I hope the meaning is clear.
 What's the right way to express this?

        [[alternative HTML version deleted]]

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

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


Re: [R] pasting several things

2012-03-02 Thread G See
Try this:

x - structure(list(day = 19, C1 = structure(1L, .Label = c(, C1
), class = factor), C2 = structure(2L, .Label = c(, C2), class =
factor),
   C3 = structure(1L, .Label = c(, C3), class = factor),
   Q1 = structure(2L, .Label = c(, Q1), class = factor),
   Q2 = structure(2L, .Label = c(, Q2), class = factor),
   Q3 = structure(1L, .Label = c(, Q3), class = factor)), .Names =
c(day,
C1, C2, C3, Q1, Q2, Q3), row.names = 8, class = data.frame)

paste(x[1, 1], do.call(paste, c(x[1, x != ][, -1], list(sep=_))), sep= -)

# Output looks like this
 paste(x[1, 1], do.call(paste, c(x[1, x != ][, -1], list(sep=_))), sep= 
 -)
[1] 19 -C2_Q1_Q2
 x[1, 2] - C1
 paste(x[1, 1], do.call(paste, c(x[1, x != ][, -1], list(sep=_))), sep= 
 -)
[1] 19 -C1_C2_Q1_Q2

HTH,
Garrett

On Fri, Mar 2, 2012 at 2:39 PM, chuck.01 charliethebrow...@gmail.com wrote:
 I have this type of format:

 structure(list(day = 19, C1 = structure(1L, .Label = c(, C1
 ), class = factor), C2 = structure(2L, .Label = c(, C2), class =
 factor),
    C3 = structure(1L, .Label = c(, C3), class = factor),
    Q1 = structure(2L, .Label = c(, Q1), class = factor),
    Q2 = structure(2L, .Label = c(, Q2), class = factor),
    Q3 = structure(1L, .Label = c(, Q3), class = factor)), .Names =
 c(day,
 C1, C2, C3, Q1, Q2, Q3), row.names = 8, class = data.frame)


 and want something like this:

  19 -C2 _Q1_Q2

 any ideas?  obviously I could use paste() and get this.  Keep in mind I have
 many of these and the presence of C1, C2, ... etc will vary.


 Thanks.

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/pasting-several-things-tp4439770p4439770.html
 Sent from the R help mailing list archive at Nabble.com.

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

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


[R] Cannot get == operator to return TRUE

2012-02-03 Thread G See
I have a data.frame named df. The dput of df is at the bottom of this e-mail.
What I'd like to do is replace the n/a  values with NA.  On Mac OSX, it works
to do this:
df[df == n/a] - NA

However, it does not work on Ubuntu.  See below.

Thanks in advance,
Garrett

 x - df[27, 4] # complete data.frame dput is below
 dput(x)
n/a 
 x == n/a 
[1] FALSE
 x == n/a
[1] FALSE
 str(x)
 chr n/a 
 is.na(x)
[1] FALSE
 grep(n/a , x)
integer(0)
 grep(n/a, x)
[1] 1


 sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] XML_3.4-3  qmao_1.1.10
[3] FinancialInstrument_0.10.9 quantmod_0.3-17
[5] TTR_0.21-0 Defaults_1.1-1
[7] xts_0.8-3  zoo_1.7-6

loaded via a namespace (and not attached):
[1] grid_2.14.1lattice_0.20-0 tools_2.14.1



### More detail ###
## Here is the complete data.frame
 dput(df)
structure(list(SYMBOL = c(GOOG , GOOG , GOOG , GOOG ,
GOOG , GOOG , GOOG , GOOG , GOOG , GOOG , GOOG ,
GOOG , GOOG , GOOG , GOOG , GOOG , GOOG , GOOG ,
GOOG , GOOG , GOOG , GOOG , GOOG , GOOG , GOOG ,
GOOG , GOOG , GOOG , GOOG , GOOG ), PERIOD = c(Q4 2011,
Q3 2011, Q2 2011, Q1 2011, Q4 2010, Q3 2010, Q2 2010,
Q1 2010, Q4 2009, Q3 2009, Q2 2009, Q1 2009, Q4 2008,
Q3 2008, Q2 2008, Q1 2008, Q4 2007, Q3 2007, Q2 2007,
Q1 2007, Q4 2006, Q3 2006, Q2 2006, Q1 2006, Q4 2005,
Q3 2005, Q2 2005, Q1 2005, Q4 2004, Q3 2004),
`EVENT TITLE` = c(Q4 2011 Google Earnings Release, Q3 2011
Google Inc Earnings Release,
Q2 2011 Google Inc Earnings Release, Q1 2011 Google Inc
Earnings Release,
Q4 2010 Google Earnings Release, Q3 2010 Google Earnings Release,
Q2 2010 Google Earnings Release, Q1 2010 Google Earnings Release,
Q4 2009 Google Earnings Release, Q3 2009 Google Earnings Release,
Q2 2009 Google Earnings Release, Q1 2009 Google Earnings Release,
Q4 2008 Google Earnings Release, Q3 2008 Google Earnings Release,
Q2 2008 Google Earnings Release, Q1 2008 Google Earnings Release,
Q4 2007 Google Earnings Release, Q3 2007 Google Earnings Release,
Q2 2007 Google Earnings Release, Q1 2007 Google Earnings Release,
Q4 2006 Google Earnings Release, Q3 2006 Google Earnings Release,
Q2 2006 Google Earnings Release, Q1 2006 Google Earnings Release,
Q4 2005 Google Earnings Release, Q3 2005 Google Earnings Release,
Q2 2005 Google Earnings Release, Q1 2005 Google Earnings Release,
Q4 2004 Google Earnings Release, Q3 2004 Google Earnings Release
), `EPS ESTIMATE` = c($ 10.49 , $ 8.74 , $ 7.85 ,
$ 8.10 , $ 8.09 , $ 6.68 , $ 6.52 , $ 6.60 ,
$ 6.50 , $ 5.42 , $ 5.09 , $ 4.93 , $ 4.95 ,
$ 4.76 , $ 4.74 , $ 4.52 , $ 4.44 , $ 3.78 ,
$ 3.59 , $ 3.30 , $ 2.92 , $ 2.42 , $ 2.22 ,
$ 1.97 , n/a , n/a , n/a , n/a , n/a ,
n/a ), `EPS ACTUAL` = c($ 9.50 , $ 9.72 , $ 8.74 ,
$ 8.08 , $ 8.75 , $ 7.64 , $ 6.45 , $ 6.76 ,
$ 6.79 , $ 5.89 , $ 5.36 , $ 5.16 , $ 5.10 ,
$ 4.92 , $ 4.63 , $ 4.84 , $ 4.43 , $ 3.91 ,
$ 3.56 , $ 3.68 , $ 3.18 , $ 2.62 , $ 2.49 ,
$ 2.29 , n/a , n/a , n/a , n/a , n/a ,
n/a ), `PREV. YEAR ACTUAL` = c($ 8.75 , $ 7.64 ,
$ 6.45 , $ 6.76 , $ 6.79 , $ 5.89 , $ 5.36 ,
$ 5.16 , $ 5.10 , $ 4.92 , $ 4.63 , $ 4.84 ,
$ 4.43 , $ 3.91 , $ 3.56 , $ 3.68 , $ 3.18 ,
$ 2.62 , $ 2.49 , $ 2.29 , n/a , n/a , n/a ,
n/a , n/a , n/a , n/a , n/a , n/a , n/a 
), TIME = c(2012-01-19 15:15:00 CST, 2011-10-13 15:15:00 CDT,
2011-07-14 15:15:00 CDT, 2011-04-14 15:15:00 CDT, 2011-01-20
15:15:00 CST,
2010-10-14 15:15:00 CDT, 2010-07-15 15:15:00 CDT, 2010-04-15
15:15:00 CDT,
2010-01-21 15:15:00 CST, 2009-10-15 15:15:00 CDT, 2009-07-16
15:15:00 CDT,
2009-04-16 15:15:00 CDT, 2009-01-22 15:15:00 CST, 2008-10-16
15:15:00 CDT,
2008-07-17 15:15:00 CDT, 2008-04-17 15:15:00 CDT, 2008-01-31
15:15:00 CST,
2007-10-18 15:15:00 CDT, 2007-07-19 15:15:00 CDT, 2007-04-19
15:15:00 CDT,
2007-01-31 15:15:00 CST, 2006-10-19 15:15:00 CDT, 2006-07-20
15:15:00 CDT,
2006-04-20 15:15:00 CDT, 2006-01-31 15:15:00 CST, 2005-10-20
15:15:00 CDT,
2005-07-21 15:15:00 CDT, 2005-04-21 15:15:00 CDT, 2005-02-01
15:15:00 CST,
2004-10-21 15:15:00 CDT)), .Names = c(SYMBOL, PERIOD,
EVENT TITLE, EPS ESTIMATE, EPS ACTUAL, PREV. YEAR ACTUAL,
TIME), row.names = 2:31, na.action = structure(31L, .Names = 32,
class = omit), class = data.frame)

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

Re: [R] Cannot get == operator to return TRUE

2012-02-03 Thread G See
Hi Sarah,

Thank you very much for the response.

In fact, it does work on Mac even without including the space:

 Symbol - GOOG
 require(XML)
Loading required package: XML
 URL - paste(http://earnings.com/company.asp?client=cbticker=;, Symbol, 
 sep=)
 x - readHTMLTable(URL, stringsAsFactors=FALSE)
 table.loc - tail(grep(Earnings Releases, x), 1) + 1
 if (identical(numeric(0), table.loc)) return(NULL)
 rdata - x[[table.loc]]
 header - rdata[1, ]
 rdata - rdata[-1, ]
 colnames(rdata) - header
 #format ticker column
 rdata[, 1] - gsub(\r\n\t\t\t, , rdata[, 1])
 rdata - na.omit(rdata)

 any(is.na(rdata))
[1] FALSE
 rdata[rdata == n/a] - NA
 any(is.na(rdata))
[1] TRUE

Garrett

On Fri, Feb 3, 2012 at 9:57 AM, Sarah Goslee sarah.gos...@gmail.com wrote:
 Is that exactly what you're doing, in a clean session?

 x - rdata[27, 4]

 x == n/a 
 [1] TRUE
 x == n/a
 [1] FALSE

 Because as long as the space is included, the test should be TRUE.

 (I renamed the dput object rdata, because df() is a base function.)

 df[df == n/a] - NA
 shouldn't work on Mac, or any other system, because no elements of
 your data frame are n/a, but are instead n/a 

 If it were my data, I'd get rid of the spaces at the end of the values before
 trying to do anything, either before reading it into R, or with gsub() after.

 Sarah

 On Fri, Feb 3, 2012 at 10:25 AM, G See gsee...@gmail.com wrote:
 I have a data.frame named df. The dput of df is at the bottom of this 
 e-mail.
 What I'd like to do is replace the n/a  values with NA.  On Mac OSX, it 
 works
 to do this:
 df[df == n/a] - NA

 However, it does not work on Ubuntu.  See below.

 Thanks in advance,
 Garrett

 x - df[27, 4] # complete data.frame dput is below
 dput(x)
 n/a 
 x == n/a 
 [1] FALSE
 x == n/a
 [1] FALSE
 str(x)
  chr n/a 
 is.na(x)
 [1] FALSE
 grep(n/a , x)
 integer(0)
 grep(n/a, x)
 [1] 1


 sessionInfo()
 R version 2.14.1 (2011-12-22)
 Platform: x86_64-pc-linux-gnu (64-bit)

 locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=C                 LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

 other attached packages:
 [1] XML_3.4-3                  qmao_1.1.10
 [3] FinancialInstrument_0.10.9 quantmod_0.3-17
 [5] TTR_0.21-0                 Defaults_1.1-1
 [7] xts_0.8-3                  zoo_1.7-6

 loaded via a namespace (and not attached):
 [1] grid_2.14.1    lattice_0.20-0 tools_2.14.1



 ### More detail ###
 ## Here is the complete data.frame
 dput(df)
 structure(list(SYMBOL = c(GOOG , GOOG , GOOG , GOOG ,
 GOOG , GOOG , GOOG , GOOG , GOOG , GOOG , GOOG ,
 GOOG , GOOG , GOOG , GOOG , GOOG , GOOG , GOOG ,
 GOOG , GOOG , GOOG , GOOG , GOOG , GOOG , GOOG ,
 GOOG , GOOG , GOOG , GOOG , GOOG ), PERIOD = c(Q4 2011,
 Q3 2011, Q2 2011, Q1 2011, Q4 2010, Q3 2010, Q2 2010,
 Q1 2010, Q4 2009, Q3 2009, Q2 2009, Q1 2009, Q4 2008,
 Q3 2008, Q2 2008, Q1 2008, Q4 2007, Q3 2007, Q2 2007,
 Q1 2007, Q4 2006, Q3 2006, Q2 2006, Q1 2006, Q4 2005,
 Q3 2005, Q2 2005, Q1 2005, Q4 2004, Q3 2004),
    `EVENT TITLE` = c(Q4 2011 Google Earnings Release, Q3 2011
 Google Inc Earnings Release,
    Q2 2011 Google Inc Earnings Release, Q1 2011 Google Inc
 Earnings Release,
    Q4 2010 Google Earnings Release, Q3 2010 Google Earnings Release,
    Q2 2010 Google Earnings Release, Q1 2010 Google Earnings Release,
    Q4 2009 Google Earnings Release, Q3 2009 Google Earnings Release,
    Q2 2009 Google Earnings Release, Q1 2009 Google Earnings Release,
    Q4 2008 Google Earnings Release, Q3 2008 Google Earnings Release,
    Q2 2008 Google Earnings Release, Q1 2008 Google Earnings Release,
    Q4 2007 Google Earnings Release, Q3 2007 Google Earnings Release,
    Q2 2007 Google Earnings Release, Q1 2007 Google Earnings Release,
    Q4 2006 Google Earnings Release, Q3 2006 Google Earnings Release,
    Q2 2006 Google Earnings Release, Q1 2006 Google Earnings Release,
    Q4 2005 Google Earnings Release, Q3 2005 Google Earnings Release,
    Q2 2005 Google Earnings Release, Q1 2005 Google Earnings Release,
    Q4 2004 Google Earnings Release, Q3 2004 Google Earnings Release
    ), `EPS ESTIMATE` = c($ 10.49 , $ 8.74 , $ 7.85 ,
    $ 8.10 , $ 8.09 , $ 6.68 , $ 6.52 , $ 6.60 ,
    $ 6.50 , $ 5.42 , $ 5.09 , $ 4.93 , $ 4.95 ,
    $ 4.76 , $ 4.74 , $ 4.52 , $ 4.44 , $ 3.78 ,
    $ 3.59 , $ 3.30 , $ 2.92 , $ 2.42 , $ 2.22 ,
    $ 1.97 , n/a , n/a , n/a , n/a , n/a ,
    n/a ), `EPS ACTUAL` = c($ 9.50 , $ 9.72 , $ 8.74 ,
    $ 8.08 , $ 8.75 , $ 7.64 , $ 6.45 , $ 6.76 ,
    $ 6.79 , $ 5.89 , $ 5.36 , $ 5.16 , $ 5.10 ,
    $ 4.92 , $ 4.63 , $ 4.84 , $ 4.43 , $ 3.91 ,
    $ 3.56 , $ 3.68 , $ 3.18 , $ 2.62 , $ 2.49 ,
    $ 2.29 , n/a , n/a , n/a , n/a , n/a ,
    n/a ), `PREV. YEAR ACTUAL` = c($ 8.75 , $ 7.64 ,
    $ 6.45

Re: [R] Cannot get == operator to return TRUE

2012-02-03 Thread G See
Petr,

Thank you!  That is great.

Do you know of a way to print a string such that I can see whether it
contains a string or a no-break space?

Thanks,
Garrett

On Fri, Feb 3, 2012 at 10:01 AM, Petr Savicky savi...@cs.cas.cz wrote:
 On Fri, Feb 03, 2012 at 09:25:10AM -0600, G See wrote:
 I have a data.frame named df. The dput of df is at the bottom of this 
 e-mail.
 What I'd like to do is replace the n/a  values with NA.  On Mac OSX, it 
 works
 to do this:
 df[df == n/a] - NA

 However, it does not work on Ubuntu.  See below.

 Thanks in advance,
 Garrett

  x - df[27, 4] # complete data.frame dput is below
  dput(x)
 n/a 

 Hi.

 This string contains a no-break space, not a space.

  n/a  == n/a\uA0

  [1] TRUE

  n/a\uA0

  [1] n/a 

 Hope this helps.

 Petr Savicky.

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

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


Re: [R] Cannot get == operator to return TRUE

2012-02-03 Thread G See
Sorry, I meant
Do you know of a way to print a string such that I can see whether it
contains a *space* or a no-break space?


On Fri, Feb 3, 2012 at 10:10 AM, G See gsee...@gmail.com wrote:
 Petr,

 Thank you!  That is great.

 Do you know of a way to print a string such that I can see whether it
 contains a string or a no-break space?

 Thanks,
 Garrett

 On Fri, Feb 3, 2012 at 10:01 AM, Petr Savicky savi...@cs.cas.cz wrote:
 On Fri, Feb 03, 2012 at 09:25:10AM -0600, G See wrote:
 I have a data.frame named df. The dput of df is at the bottom of this 
 e-mail.
 What I'd like to do is replace the n/a  values with NA.  On Mac OSX, it 
 works
 to do this:
 df[df == n/a] - NA

 However, it does not work on Ubuntu.  See below.

 Thanks in advance,
 Garrett

  x - df[27, 4] # complete data.frame dput is below
  dput(x)
 n/a 

 Hi.

 This string contains a no-break space, not a space.

  n/a  == n/a\uA0

  [1] TRUE

  n/a\uA0

  [1] n/a 

 Hope this helps.

 Petr Savicky.

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

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


Re: [R] Cannot get == operator to return TRUE

2012-02-03 Thread G See
Thank you Duncan, that is very helpful.

Although I think we've got it sorted out now, to answer your previous
questions,  it is repeatable in a new R session, and the output of
charToRaw is below.

On Ubuntu, I get the following:
 charToRaw(x)
[1] 6e 2f 61 c2 a0

On Mac, I get:
 charToRaw(x)
[1] 6e 2f 61

Thanks to all for the help,
Garrett

On Fri, Feb 3, 2012 at 10:19 AM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 12-02-03 11:10 AM, G See wrote:

 Sorry, I meant
 Do you know of a way to print a string such that I can see whether it
 contains a *space* or a no-break space?


 Use tools::showNonASCII(x).  On Petr's example, it gives

 1: n/ac2a0

 Duncan Murdoch




 On Fri, Feb 3, 2012 at 10:10 AM, G Seegsee...@gmail.com  wrote:

 Petr,

 Thank you!  That is great.

 Do you know of a way to print a string such that I can see whether it
 contains a string or a no-break space?

 Thanks,
 Garrett

 On Fri, Feb 3, 2012 at 10:01 AM, Petr Savickysavi...@cs.cas.cz  wrote:

 On Fri, Feb 03, 2012 at 09:25:10AM -0600, G See wrote:

 I have a data.frame named df. The dput of df is at the bottom of this
 e-mail.
 What I'd like to do is replace the n/a  values with NA.  On Mac OSX,
 it works
 to do this:
 df[df == n/a]- NA

 However, it does not work on Ubuntu.  See below.

 Thanks in advance,
 Garrett

 x- df[27, 4] # complete data.frame dput is below
 dput(x)

 n/a 


 Hi.

 This string contains a no-break space, not a space.

  n/a  == n/a\uA0

  [1] TRUE

  n/a\uA0

  [1] n/a 

 Hope this helps.

 Petr Savicky.

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


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



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


Re: [R] Cannot get == operator to return TRUE

2012-02-03 Thread G See
On Fri, Feb 3, 2012 at 10:39 AM, peter dalgaard pda...@gmail.com wrote:

 So that's a nonbreak space alright. Next question: How did it get there? I'm 
 mildly surprised that it crept into the data frame, I would expect it to 
 happen much easier with things typed on the keyboard (Alt-Spc on my Mac 
 keyboard, e.g.).


Peter,
I won't venture to guess how, but this will do it.

 library(XML)
 x - readHTMLTable(http://earnings.com/company.asp?client=cbticker=GOOG;, 
 stringsAsFactors=FALSE)[[21]]
 charToRaw(x[28, 4])
[1] 6e 2f 61 c2 a0

Garrett

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


Re: [R] [R-SIG-Finance] how do I make a movie out of a timeseries of 2D data?

2012-01-12 Thread G See
Michael,

Please don't cross post to both lists.  If it doesn't have to do with
finance, don't send it it r-sig-finance.

Thanks,
Garrett

On Thu, Jan 12, 2012 at 8:38 AM, Michael comtech@gmail.com wrote:
 Hi all,

 I have an array of 1 x 200 x 200 numbers... which is a time-series of
 200x200 2D data...

 The 1st dimension is the time index.

 Is there a way to make a movie out of these data - i.e. playback 1
 frames(200x200) at a playback rate per second?

 Thanks a lot!

        [[alternative HTML version deleted]]

 ___
 r-sig-fina...@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-sig-finance
 -- Subscriber-posting only. If you want to post, subscribe first.
 -- Also note that this is not the r-help list where general R questions 
 should go.

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


Re: [R] Problem installing tweetR on Ubuntu

2011-10-19 Thread G See
This will help you solve your problem
http://www.omegahat.org/RCurl/FAQ.html

-Garrett

On Wed, Oct 19, 2011 at 8:16 PM, Axel Urbiz axel.ur...@gmail.com wrote:

 Dear List,

 When I try to install tweetR on Ubuntu, I get the error message below. It
 is
 a problem with the dependency RCurl. This package is not available for
 Windows on CRAN, but I would assume that I should have no problem with
 linux.

 Any help is much appreciated.

 R version: 2.12.1
 Platform: x86_64-pc-linux-gnu (64-bit)

 * installing *source* package ‘RCurl’ ...
 checking for curl-config... no
 Cannot find curl-config
 ERROR: configuration failed for package ‘RCurl’
 * removing ‘/home/leo/R/x86_64-pc-linux-gnu-library/2.12/RCurl’
 ERROR: dependency ‘RCurl’ is not available for package ‘twitteR’
 * removing ‘/home/leo/R/x86_64-pc-linux-gnu-library/2.12/twitteR’


 Regards,
 Axel.

[[alternative HTML version deleted]]


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



[[alternative HTML version deleted]]

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


Re: [R] problem with quantmod package

2011-10-18 Thread G See
I'm not sure how to easily get that data from google (see Michael's
message), but it's available from yahoo.

getSymbols('TCS.NS', src='yahoo')

I've found that historical stock data from Yahoo is typically cleaner and
more reliable than from Google.  The other main difference is that Yahoo
provides OHLCV and Adjusted columns, where the Adjusted column is the close
price series adjusted for dividends and splits.  Google, does not provide
unadjusted or completely adjusted data.  Instead, they give you data that
has been adjusted for splits, but not for dividends.

If you really want the yahoo data to look like google data, you could adjust
it for splits, and not for dividends like this

TCS - adjustOHLC(TCS.NS, adjust='split')

HTH,
Garrett

p.s.  If there is any reason to use historic stock price data from google
instead of yahoo, I would be very interested to hear it (off-list of course,
since it's off-topic)


On Tue, Oct 18, 2011 at 8:19 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 I believe it's because they are not made available for download as a csv
 file.

 Compare:

 https://www.google.com/finance/historical?q=NSE:TCS

 with

 https://www.google.com/finance/historical?q=NASDAQ:AAPL

 You'll see that for AAPL, there is an option to export prices on the
 right hand side: that's what getSymbol() takes advantage of.

 Why it exists I don't know, but it probably has to do with how much
 google is willing to pay for licensing to foreign exchanges.

 You could perhaps write something to read the price table that google
 shows or if you find the data available elsewhere on a csv, I'm sure
 the package authors would be willing to add another method for
 getSymbols.

 Michael

 On Tue, Oct 18, 2011 at 1:07 AM, ATANU ata.s...@gmail.com wrote:
  i am using quantmod package.it get stock quotes from google finanace.
 but
  unfortunately i am not able to get the quotations of some stocks(e.g.
  NSE:TCS,NSE:SAIL ) through the getSymbol command of this package
 although
  they are available in the google finance website. anyone please help me.
  thanks in advance.
 
  --
  View this message in context:
 http://r.789695.n4.nabble.com/problem-with-quantmod-package-tp3914263p3914263.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 

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


[[alternative HTML version deleted]]

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