Re: [R] Calculating distance matrix for large dataset

2013-05-03 Thread steven mosher
 I have a version that uses bigmemory on my blog, but looks at distance on
a sphere for a 36k * 36K  matrix

 not hundreds of Gb  so I dont know if the approach will work for you


http://stevemosher.wordpress.com/2012/04/12/nick-stokes-distance-code-now-with-big-memory/


Steve

However,  I never tested it with
On May 2, 2013 9:40 PM, HJ YAN yhj...@googlemail.com wrote:

 Dear R users


 I wondered if any of you ever tried to calculate distance matrix with very
 large data set, and if anyone out there can confirm this error message I
 got actually mean that my data is too large for this task.

 negative length vectors are not allowed


 My data size and code used

  dim(mydata_nor)[1] 365000144 d - dist(mydata_nor, method =
 euclidean)



 Here my data has 1000 samples each has a year data observed by 10 minutes
 interval daily, so the size is  (365* 1000) * 144.


 I checked the manual of function 'dist' but can not see the upper limit
 size allowed, and I bet there should be one, so any hints is appreciated.


 I would also be grateful if any other method for calculating distance
 matrix for large dataset could be advised.



 I appreciate reproducible code should be provided for your advice, so try
 below if needed:

 A-matrix(1:365000*144,nrow=365000,ncol=144) dim(A)[1] 365000144
 d1-dist(A,method=euclidean)Error in dist(A, method = euclidean) :
   negative length vectors are not allowed




 Many thanks in advance!

 HJ

 [[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] How can I map numbers to colours with raster?

2012-10-29 Thread steven mosher
see the function level() in raster. also levelplot in rastervis package.
you basically create a raster attribute table coerce the raster to factor
class and plot. check geo sig i have posted the same question there
On Oct 29, 2012 2:15 AM, Jonsson amen.alya...@bordeaux.inra.fr wrote:

 This code will read binary file and display it as a map. may problem is
 that
 this code is using a continuous colour scheme, even though I have discrete
 data (which  is a classification scheme). How can I map numbers to colours
 with raster? Please

 require(raster)
 conne - file(C:\\lai.bin, rb)
 sd- readBin(conne, integer(), size=1,  n=360*720, signed=F)
  y-t(matrix((data=sd), ncol=360, nrow=720))
  r = raster(y)
 extent(r) = extent(c(xmn=-180,xmx=180,ymn=-90,ymx=90))
 plot(r)





 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-can-I-map-numbers-to-colours-with-raster-tp4647742.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] bigmemory for dataframes?

2012-10-18 Thread steven mosher
i believe ff has a dataframe class. as for your object data im less clear.
how big is it
On Oct 18, 2012 12:45 PM, Alexander Shenkin ashen...@ufl.edu wrote:

 Hi Folks,

 I've been bumping my head against the 4GB limit for 32-bit R.  I can't
 go to 64-bit R due to package compatibility issues (ROBDC - possible but
 painful, xlsReadWrite - not possible, and others).  I have a number of
 big dataframes whose columns all sorts of data types - factor,
 character, integer, etc.  I run and save models that keep copies of the
 modeled data inside the model objects as well (mle2 objects, to be
 specific).

 I'm searching for a way to cache some of these dataframes and objects to
 virtual memory (I think I'm using the right terminology...).  I've read
 around, and while bigmemory and ff and the like would likely suit my
 purposes if I were just dealing with numeric matricies, I'm dealing with
 dataframes and objects.

 Any thoughts would be greatly appreciated!

 Thanks,
 Allie

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


[[alternative HTML version deleted]]

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


Re: [R] R process must die - can I save history?

2012-10-02 Thread steven mosher
thanks Dr. R. this will come in handy in the future as I have a knack for
hanging R.
On Oct 2, 2012 12:01 PM, Prof Brian Ripley rip...@stats.ox.ac.uk wrote:

 On 02/10/2012 18:29, Bert Gunter wrote:

 ?history

 in a fresh R session, to see what might be possible. I'll bet the
 answer is, No, you're screwed, though. Nevertheless, maybe Linux
 experts can save you.


 Maybe not.  On a Unix-alike see ?Signals.  If you can find the pid of the
 R process and it is still running (and not e.g. suspended),

 kill -USR1 pid

 will save the workspace and history.


 May the Force be with you.

 -- Bert

 On Tue, Oct 2, 2012 at 10:17 AM, Mike Miller mbmille...@gmail.com
 wrote:

 I connected from my desktop Linux box to a Linux server using ssh in an
 xterm, but that xterm was running in Xvnc.  I'm running R on the server
 in
 that xterm (over ssh).  Something went wrong with Xvnc that has caused
 it to
 hang, probably this bug:

 https://bugs.launchpad.net/**ubuntu/+source/vnc4/+bug/**819473https://bugs.launchpad.net/ubuntu/+source/vnc4/+bug/819473

 So I can't get back to that ssh session or to R.  I had done a bunch of
 work
 in R but the command history hasn't been written out.  If I kill R, I
 assume
 the command history is gone.  I wish I could somehow cause R to dump the
 command history.  Is there any way to tell the running R process to write
 the history somewhere?

 Thanks in advance.

 Mike

 --
 Michael B. Miller, Ph.D.
 Minnesota Center for Twin and Family Research
 Department of Psychology
 University of Minnesota

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






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

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


[[alternative HTML version deleted]]

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


Re: [R] How to arrange the GUI's in window in tcltk package???

2012-08-25 Thread steven mosher
1. get programming grapgical user interfaces in R. lawrence and verzani.

2. if you used gwidgets on gtk i could tell you exactly what to do.

3. with the toolkit youve selected i think tlpack controls the way children
are placed in a container. default is top to bottom
On Aug 24, 2012 11:27 PM, punitha punitha@wipro.com wrote:

 Hi,

   I am new to R, I need your help. I have been said to create a GUI in
 R,
   I started using Tcltk package which was very easy to learn and code,
   but i am unable to arrange the GUI's in proper order in the window
 they are always arranged one below the other, please can anyone help me in
 solving this problem,
  Is there any links which will help me solve this problem with example.

Thanks in advance.

 with regards,
 Punitha




 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-arrange-the-GUI-s-in-window-in-tcltk-package-tp4641279.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] building binary tree

2012-06-28 Thread steven mosher
I believe chambers book has an example using S4 classes. which isnt much
help for a beginner.

you can do it the old school way. build it by hand with one vector of
pointers and another data structure of leaf nodes. there is nothing magical
about a tree. you can build one in basic or fortran. painful but good for
ur character.
On Jun 27, 2012 10:09 PM, Peppino giuseppel...@hotmail.com wrote:

 Hi I am new with R

 I Have to build a binary tree with R. I'm very confused was wondering if
 anyone had any R sample code they would share. I've come across a lot of
 C++
 code(nothing in R) and this is not helping.

 Any bady can help me?

 Bye

 Giuseppe

 --
 View this message in context:
 http://r.789695.n4.nabble.com/building-binary-tree-tp4634592.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] A basic design question for R

2012-06-16 Thread steven mosher
use a list. or create new class which is a list
On Jun 16, 2012 8:52 AM, Onur Uncu onuru...@gmail.com wrote:

 Hello R Community,

 I have the following design question. I have a data set that looks
 like this (shortened for the sake of example).

 Gender  Age
  M  70
  F   65
  M  70

 Each row represents a person with an age/gender combination. We could
 put this data into a data frame.

 Now, I would like to do some actuarial analysis on this data set. To
 do so, I need to create and store a mortality curve for each person in
 the table (a mortality curve is a matrix with 2 columns: date and
 survival probability). I can write a function that returns a mortality
 curve given gender and age.  The question is the following: In what
 data format should I store all these mortality curve objects? Should I
 add a column to the data frame and each entry in that column is a
 matrix (a mortality curve)? This way, the mortality curve would be
 stored next to age/gender data in the data frame. However, I read in
 several places that putting vectors/matrices as elements of a data
 frame is a bad idea. I do not know why. What is a good design choice
 in this instance please? How should I store the mortality curves?

 Thank you for your help.

 __
 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] Converting to XTS loses data.frame structure

2012-05-29 Thread steven mosher
is there a statement of work for the summer of code work.
On May 29, 2012 12:19 PM, Joshua Ulrich josh.m.ulr...@gmail.com wrote:

 On Tue, May 29, 2012 at 2:11 PM, Noah Silverman noahsilver...@ucla.edu
 wrote:
  Hello,
 
  I noticed something odd when working with data frames and xts objects.
 
  If I read in a CSV file, R creates a nice data.frame.  This works well.
 
  If I then convert to an XTS object, I see that all the values in the
 data are now quoted.  My data is a mix of numeric and character.  This is
 usually seen when converting a data.frame to a matrix, as R will treat all
 the data as the same class. (character)
 
  How can I ensure that R creates an XTS object that is still a data.frame
 so that all the data are the correct type??
 
 You can't.  xts/zoo objects are a matrix with an index attribute.
 Since you can't mix types in a matrix, you can't mix types in an
 xts/zoo object.  That said, part of the xts Google Summer of Code
 project is to create an xts-like object that allows mixed types.

 Best,
 --
 Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

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


[[alternative HTML version deleted]]

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


Re: [R] Failure building any package

2012-05-17 Thread steven mosher
Did you edit the description file and the namespace file and the  Rd files?

Although my tutorial is for windows if you follow steps 8 thru 10 on mac it
should work

http://stevemosher.wordpress.com/step-8-the-sample-package/



On Thu, May 17, 2012 at 7:44 PM, Noah Silverman noahsilver...@ucla.eduwrote:

 Hello,

 I'm attempting to build a package using R 2.15.0 on OS X

 I am getting a generic failure when performing a cran type check on the
 package.  Even with a very simple test package, it still fails int he same
 place.

 Example:

 In R:
 rm(list=ls())
 foo - function(x){print(x)}
 package.skeleton(name=foo)

 Then, at the command line:
 R CMD build foo
 R CMD check --as-cran foo_1.0.tar.gz

 Some output not included here
 * checking whether package ‘foo’ can be installed … ERROR
 Installation failed.
 See ‘foo.Rcheck/00install.out’ for details.

 Looking at the 00install.out file, I see:

 * installing *source* package ‘foo’ ...
 ** R
 Error in parse(outFile) : 5949:10: unexpected symbol
 5948: c(01, 00, 00, 00, 01, 00, 00, 00, 00, 00, 00, 00, 00, 00,
 5949: e0, 3f
  ^
 ERROR: unable to collate and parse R files for package ‘foo’


 Can anyone help explain what is happening here?  This is the most generic
 and empty package I can think of, so not sure why a build is failing.

 Thanks!


 --
 Noah Silverman
 UCLA Department of Statistics
 8117 Math Sciences Building
 Los Angeles, CA 90095

 __
 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] using wildcards in download.file?

2012-04-13 Thread steven mosher
one way to solve your problem is to fetch the directory using rcurl. then
mapply using the dirlist as a parameter passed to download file
On Apr 13, 2012 9:24 AM, MacQueen, Don macque...@llnl.gov wrote:

 If you take a thorough look at the help page for download.file, and follow
 its advice, you may find a solution.

 Hint:
 The help page for download.file says,

 -- quote --
 The function 'download.file' can be used to download a single file
 as described by 'url' from the internet and store it in
 'destfile'.
 -- end quote --

 I'd say that makes it pretty clear the answer is no.

 Further on in the help page in the See Also section it refers to another
 package.

 Hint:
 A help page for one of the functions in that packages says,
 -- quote --
 # FTP
   # Download the files within a directory.

 -- end quote --


 which looks promising.


 --
 Don MacQueen

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





 On 4/12/12 2:07 PM, jt...@mappi.helsinki.fi jt...@mappi.helsinki.fi
 wrote:

 Hi,
 Do you know whether it is possible to use wildcards in download.file()?
 For example:
 url = ftp://abc.com/*.*; # to download all the files in the ftp folder
 download.file(url,destfile=...) # does not work, any solutions?
 
 Thanks!
 
 JIng
 
 __
 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.


Re: [R] Help - Importing data from txt and xlsx files

2012-04-13 Thread steven mosher
read your file with readLines(). copy the first few lines for me to read
here

test - readLines(yur filename)
test[1:5]

post the result. we can figure it out from there
On Apr 13, 2012 11:46 AM, AMFTom the.quiet.r...@gmail.com wrote:

 Dear Thierry,

 Thanks for your help. Now though, I try to import data from a txt file, and
 it says either

  mydataframe - read.table(Lv2.8.txt)
 Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
 :
  line 3 did not have 15 elements

 or

  mydataframe - read.table(Lv2.8.txt, header = TRUE)
 Error in read.table(Lv2.8.txt, header = TRUE) :
  more columns than column names

 even though I seem to have put a column name into the txt file for each
 column. Any ideas?

 Thanks again!

 Tom

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Help-Importing-data-from-txt-and-xlsx-files-tp4554622p4555001.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] Applying a function to categorized data?

2012-04-12 Thread steven mosher
 Welcome to R and the list.

 Others may suggest books ( Nutshell was my first ) but first there are
some things that will help you
 both in programming and getting help on the list.

 You should post executable code in your question. So, build a toy example
of the data.frame you have
and show what you tried. Folks here should be able to run your toy example
and  show you how to get the answer you want.

For your problem I'm guessing that aggregate() would be one path

?aggregate

 you will need to specify   by  to aggregate by month

Steve

On Thu, Apr 12, 2012 at 7:10 AM, Robert Latest boblat...@gmail.com wrote:

 Hi all,

 I'm just getting started in R. My problem is the following:

 I have a data frame (v1) with lots of production data measurements.
 Each row contains a single measurement ('ARI_MIT') with a timestamp. I
 want to lump the data by months with their mean and standard
 deviation.

 I have already successfully managed to do the lumping by adding
 another column to my data frame:

 v1$MONTH = strftime(v1$TIMESTAMP, %y%m)

 This makes a nice month-wise boxplot of my data, although I don't have
 an idea why:
 boxplot(v1$ARI_MIT ~ v1$MONTH)

 I don't need this plotted, though, but in the form of a new data frame
 with three columns: the month, the mean, and the standard deviation of
 all values from that month.

 I tried un-stacking v1 into a list of vectors and then looping over
 its elements, calculating the mean of each group:

 for (i in unstack(v1, v1$ARI_MIT ~ v1$MONTH)) { write(mean(i), ) }

 This works, but how do I get the data into a data frame? With the
 month labels in a column? They are not avaliable inside the loop body.

 I know I need to get a book on R.

 Thanks,
 robert

 __
 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] Listing the contents of an FTP directory via R?

2012-04-09 Thread steven mosher
A couple of ways.

using Rcurl   you can use the  curlOption of dirlistonly.

otherwise you can read the page and parse.  I've got some code around here
to do that.

Steve

On Mon, Apr 9, 2012 at 11:27 AM, Jonathan Greenberg j...@illinois.eduwrote:

 R-helpers:

 I'd like to be able to store all the file information from an ftp site
 (e.g. file and foldernames) through an R command.  Any ideas how to do
 this?  Here's an example site to use:

 ftp://e4ftl01.cr.usgs.gov/MOTA/MCD15A3.005

 --j

 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Department of Geography and Geographic Information Science
 University of Illinois at Urbana-Champaign
 607 South Mathews Avenue, MC 150
 Urbana, IL 61801
 Phone: 415-763-5476
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
 http://www.geog.illinois.edu/people/JonathanGreenberg.html

 __
 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] Listing the contents of an FTP directory via R?

2012-04-09 Thread steven mosher
Ya I hit the same error with my code that reads directories.
I'll try some other stuff . I think I hit this error before I  with usgs.


On Mon, Apr 9, 2012 at 11:40 AM, Jonathan Greenberg j...@illinois.eduwrote:

 Steven:

 Thanks -- I seem to be running into the problem with the link I sent along:

  getURL(ftp://e4ftl01.cr.usgs.gov/MOTA/MCD15A3.005/,verbose=TRUE,dirlistonly
 = TRUE)
 Error in function (type, msg, asError = TRUE)  : RETR response: 550

 I'm wondering if it might be a passive ftp issue, but:
  getURL(ftp://e4ftl01.cr.usgs.gov/MOTA/MCD15A3.005/,verbose=TRUE,ftp.use.epsv=TRUE,
 dirlistonly = TRUE)
 Error in function (type, msg, asError = TRUE)  :
  FTP response reading failed

 Does not seem to work...  Thoughts?

 --j

 On Mon, Apr 9, 2012 at 1:32 PM, steven mosher mosherste...@gmail.com
 wrote:
  A couple of ways.
 
  using Rcurl   you can use the  curlOption of dirlistonly.
 
  otherwise you can read the page and parse.  I've got some code around
 here
  to do that.
 
  Steve
 
  On Mon, Apr 9, 2012 at 11:27 AM, Jonathan Greenberg j...@illinois.edu
  wrote:
 
  R-helpers:
 
  I'd like to be able to store all the file information from an ftp site
  (e.g. file and foldernames) through an R command.  Any ideas how to do
  this?  Here's an example site to use:
 
  ftp://e4ftl01.cr.usgs.gov/MOTA/MCD15A3.005
 
  --j
 
  --
  Jonathan A. Greenberg, PhD
  Assistant Professor
  Department of Geography and Geographic Information Science
  University of Illinois at Urbana-Champaign
  607 South Mathews Avenue, MC 150
  Urbana, IL 61801
  Phone: 415-763-5476
  AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
  http://www.geog.illinois.edu/people/JonathanGreenberg.html
 
  __
  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.
 
 



 --
 Jonathan A. Greenberg, PhD
 Assistant Professor
 Department of Geography and Geographic Information Science
 University of Illinois at Urbana-Champaign
 607 South Mathews Avenue, MC 150
 Urbana, IL 61801
 Phone: 415-763-5476
 AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
 http://www.geog.illinois.edu/people/JonathanGreenberg.html


[[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] Listing the contents of an FTP directory via R?

2012-04-09 Thread steven mosher
  Directory A
HREF=/MOTA/MCD15A3.005/2003.07.04/B2003.07.04/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.07.08/B2003.07.08/B/A

10/18/2011 06:00PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.07.12/B2003.07.12/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.07.16/B2003.07.16/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.07.20/B2003.07.20/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.07.24/B2003.07.24/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.07.28/B2003.07.28/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.08.01/B2003.08.01/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.08.05/B2003.08.05/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.08.09/B2003.08.09/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.08.13/B2003.08.13/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.08.17/B2003.08.17/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.08.21/B2003.08.21/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.08.25/B2003.08.25/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.08.29/B2003.08.29/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.09.02/B2003.09.02/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.09.06/B2003.09.06/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.09.10/B2003.09.10/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.09.14/B2003.09.14/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.09.18/B2003.09.18/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.09.22/B2003.09.22/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.09.26/B2003.09.26/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.09.30/B2003.09.30/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.10.04/B2003.10.04/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.10.08/B2003.10.08/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.10.12/B2003.10.12/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.10.16/B2003.10.16/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.10.20/B2003.10.20/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.10.24/B2003.10.24/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.10.28/B2003.10.28/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.11.01/B2003.11.01/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.11.05/B2003.11.05/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.11.09/B2003.11.09/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.11.13/B2003.11.13/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.11.17/B2003.11.17/B/A

10/18/2011 06:00PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.11.21/B2003.11.21/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.11.25/B2003.11.25/B/A

10/18/2011 06:00PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.11.29/B2003.11.29/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.12.03/B2003.12.03/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.12.07/B2003.12.07/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.12.11/B2003.12.11/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.12.15/B2003.12.15/B/A

10/18/2011 06:01PM  Directory A
HREF=/MOTA/MCD15A3.005/2003.12.23/B2003.12.23/B/A

On Mon, Apr 9, 2012 at 11:40 AM, Jonathan Greenberg j...@illinois.eduwrote:

 Steven:

 Thanks -- I seem to be running into the problem with the link I sent along:

  getURL(ftp://e4ftl01.cr.usgs.gov/MOTA/MCD15A3.005/,verbose=TRUE,dirlistonly
 = TRUE)
 Error in function (type, msg, asError = TRUE)  : RETR response: 550

 I'm wondering if it might be a passive ftp issue, but:
  getURL(ftp://e4ftl01.cr.usgs.gov/MOTA/MCD15A3.005/,verbose=TRUE,ftp.use.epsv=TRUE,
 dirlistonly = TRUE)
 Error in function (type, msg, asError = TRUE)  :
  FTP response reading failed

 Does not seem to work...  Thoughts?

 --j

 On Mon, Apr 9, 2012 at 1:32 PM, steven mosher mosherste...@gmail.com
 wrote:
  A couple of ways.
 
  using Rcurl   you can use the  curlOption of dirlistonly.
 
  otherwise you can read the page and parse.  I've got some code around
 here
  to do that.
 
  Steve
 
  On Mon, Apr 9, 2012 at 11:27 AM, Jonathan Greenberg j...@illinois.edu
  wrote:
 
  R-helpers:
 
  I'd like to be able to store all the file information from an ftp site
  (e.g. file and foldernames) through an R command.  Any ideas how to do
  this?  Here's an example site to use:
 
  ftp://e4ftl01.cr.usgs.gov/MOTA/MCD15A3.005
 
  --j
 
  --
  Jonathan A. Greenberg, PhD
  Assistant Professor
  Department

Re: [R] Handling 8GB .txt file in R?

2012-03-25 Thread steven mosher
As the other poster noted, you can just skip lines.

Big matrix should work just fine, except I am not sure how the dates will
be handled

Here is some sample code from my stuff
txtName   is the file name of the file you are reading
Directory   is the path where you want to write the file.backed matrix
filenameis the file.backed big matrix
dname  is a filename for describing the data
sep   What's your separator, comma or space?  below I use tab,
because my file is tab delimited

replace my column names with yours

PERMNO  DATETICKERPERMCO PRC
VOLNUMTRDvwretdewretd

Your dates may be coerced in factors. Not sure how that will work.
You can also try ff

  options(bigmemory.allow.dimnames=TRUE)
 D- read.big.matrix(txtName, skip = 5,
 backingpath = Directory,
  backingfile = filename,
 descriptorfile = dname,
 sep = \t,
 type = double,
 col.names =
 c(Id,SeriesNo,Date,Temp,Unc,Obs,Tobs)
 )



On Sat, Mar 24, 2012 at 9:20 PM, iliketurtles isaacm...@gmail.com wrote:

 Thanks to all the suggestions. To the first individual that replied, I
 can't
 do any stuff with unix or perl. All I know is R.

 @KEN:
 I'm using Windows 7, 64 bit.

 @Steve:
 Here's the readLines output.. As we can see, lines 1-3 are empty and line 5
 is empty, and there's also empty elements after line 5!.

  [1]  
  [2] 
 
  [3]  
  [4]   PERMNO  DATETICKERPERMCO PRC
 VOLNUMTRDvwretdewretd
  [5] 
  [6]106/01/19867952  .
 . . -0.000138  0.001926
  [7]107/01/1986OMFGA   7952-2.56250
 1000 .  0.013809  0.011061
  [8]108/01/1986OMFGA   7952-2.5
 12800 . -0.020744 -0.005117
  [9]109/01/1986OMFGA   7952-2.5
 1400 . -0.011219 -0.011588
  [10]110/01/1986OMFGA   7952-2.5
 8500 .  0.83  0.003651
  [11]113/01/1986OMFGA   7952-2.62500
 5450 .  0.002749  0.002433

 -
 

 Isaac
 Research Assistant
 Quantitative Finance Faculty, UTS
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Handling-8GB-txt-file-in-R-tp4500971p4502706.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] video recorded simulations in R?

2012-03-24 Thread steven mosher
see the package animate
On Mar 24, 2012 7:37 AM, Sarah Goslee sarah.gos...@gmail.com wrote:

 The easiest approach is to save your plot as a bitmap every x-th
 iteration, and then use other tools to animate them. I use ImageMagick for
 this, but I'm sure there are other options.

 Sarah

 On Mar 23, 2012, at 11:28 PM, C W tmrs...@gmail.com wrote:

  Hi everyone,
  Is it possible to video record simulations in R?
  Say, for instance, I am plotting samples using MCMC algorithm, and then
  showing its convergence after 1 iterations.  I was wondering if
 anyone
  has done this before?
 

 __
 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] Memory issue. XXXX

2012-03-02 Thread steven mosher
1. How much RAM do you have (looks like 2GB ) . If you have more than 2GB
then you can allocate
more memory with memory.size()

2. If you have 2GB or less then you have a couple options

a) make sure your session is clean of unnecessary objects.
b) Dont read in all the data if you dont need to ( see colClasses  to
control this )
c) use the bigmemory package or ff package
d) buy more RAM


On Fri, Mar 2, 2012 at 6:57 AM, Dan Abner dan.abne...@gmail.com wrote:

 Hi everyone,

 Any ideas on troubleshooting this memory issue:

  d1-read.csv(arrears.csv)
 Error: cannot allocate vector of size 77.3 Mb
 In addition: Warning messages:
 1: In class(data) - data.frame :
  Reached total allocation of 1535Mb: see help(memory.size)
 2: In class(data) - data.frame :
  Reached total allocation of 1535Mb: see help(memory.size)
 3: In class(data) - data.frame :
  Reached total allocation of 1535Mb: see help(memory.size)
 4: In class(data) - data.frame :
  Reached total allocation of 1535Mb: see help(memory.size)


 Thanks!

 Dan

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


[[alternative HTML version deleted]]

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


[R] Question about tables in bigtabulate

2012-02-29 Thread steven mosher
I have a large file backed big. matrix, with millions of rows and 20
columns.

The columns contain data that I simply need to tabulate. There are a few
dozen unique
values. and I just want a frequency count

Test code with a small big matrix.

library(bigmemory)
library(bigtabulate)

  test - big.matrix(nrow = 100, ncol = 10)
  test[,1:3]- sample(150)
  test[,4:6]- sample(100)
  test[,7:10]- sample(100)

##so we have  sample big memory matrix. Its not file backed but will do
for testing.
##the result we want is one that you would get if you could run table()
 on the bigmatrix
##thats emulated in this example by coercing the bigmatrix to a matrix.
##in the real application that is not possible, because of RAM limits
  P - table(as.matrix(test))

##  the package big tabulate has a version of table called  bigtable.
##  you can run table on an individual column.
## I want to run it on all the columns. basically combine the results of
running it on individual columns
## if you try to specify multiple columns, you get a contingency table, and
if you use too many
## columns you will hang your system hard .. so dont try the line below .
Well at least I hung my system

#  Ouch - bigtable(test, ccols = seq(1,10))

So, is there a simple way to  get the answer as emulated by
 P-table(as.matrix(test))
without coercing to a matrix.

TIA

[[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] best option for big 3D arrays?

2012-02-27 Thread steven mosher
Thanks,

 That helped. Maybe when I get a chance I will do some blog posts on  the
basics of ff
 I think some tutorials would be a good idea

Steve

On Mon, Feb 27, 2012 at 3:47 AM, Djordje Bajic je.li@gmail.com wrote:

 Steven, sorry for the delay in responding,

 I have been investigating this also and here is the way I do it (though
 probably not the best way):

 # .. define a 3D array
  ngen = 904
  gratios - ff(NA, dim=rep(ngen,3), vmode=double)

 # .. fill the array with standard R functions

  ffsave (gratios, file=mydir/myfile)# without extension
  finalizer(gratios) - delete

 # ..

 so, you firstly define the ff object, you put the data inside, and you
 ffsave it. The ffsave function will generate two files, with extensions
 ffdata and a Rdata. Then you set 'delete' to be the 'finalizer' of the
 object; in this way you avoid ff to save it in some tmp dir and occupy disk
 space forever. Then, you can access your object in the next R session:

  ffload(mydir/myfile)# also without extension

 I hope this helped.

 Cheers,

 djordje



 2012/2/23 steven mosher mosherste...@gmail.com

  Did you have to use a particular filename?  or extension.
 
  I created a similar file but then could not read it back in
 
  Steve
 
  On Mon, Feb 13, 2012 at 6:45 AM, Djordje Bajic je.li@gmail.com
 wrote:
 
  I've been investigating and I partially respond myself. I tried the
  packages 'bigmemory' and 'ff' and for me the latter did the work I need
  pretty straightforward. I create the array in filebacked form with the
  function ff, and it seems that the usual R indexing works well. I have
 yet
  to see the limitations, but I hope it helps.
 
  a foo example:
 
  myArr - ff(NA, dim=rep(904,3), filename=arr.ffd, vmode=double)
  myMat - matrix(1:904^2, ncol=904)
  for ( i in 1:904 ) {
 myArr[,,i] - myMat
  }
 
  Thanks all,
 
  2012/2/11 Duncan Murdoch murdoch.dun...@gmail.com
 
   On 12-02-10 9:12 AM, Djordje Bajic wrote:
  
   Hi all,
  
   I am trying to fill a 904x904x904 array, but at some point of the
 loop
  R
   states that the 5.5Gb sized vector is too big to allocate. I have
  looked
   at
   packages such as bigmemory, but I need help to decide which is the
  best
   way to store such an object. It would be perfect to store it in this
   cube
   form (for indexing and computation purpouses). If not possible, maybe
  the
   best is to store the 904 matrices separately and read them
 individually
   when needed?
  
   Never dealed with such a big dataset, so any help will be appreciated
  
   (R+ESS, Debian 64bit, 4Gb RAM, 4core)
  
  
   I'd really recommend getting more RAM, so you can have the whole thing
   loaded in memory.  16 Gb would be nice, but even 8Gb should make a
   substantial difference.  It's going to be too big to store as an array
   since arrays have a limit of 2^31-1 entries, but you could store it
 as a
   list of matrices, e.g.
  
   x - vector(list, 904)
   for (i in 1:904)
x[[i]] - matrix(0, 904,904)
  
   and then refer to entry i,j,k as x[[i]][j,k].
  
   Duncan Murdoch
  
  
  
 
 [[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.


[[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] best option for big 3D arrays?

2012-02-23 Thread steven mosher
Did you have to use a particular filename?  or extension.

I created a similar file but then could not read it back in

Steve

On Mon, Feb 13, 2012 at 6:45 AM, Djordje Bajic je.li@gmail.com wrote:

 I've been investigating and I partially respond myself. I tried the
 packages 'bigmemory' and 'ff' and for me the latter did the work I need
 pretty straightforward. I create the array in filebacked form with the
 function ff, and it seems that the usual R indexing works well. I have yet
 to see the limitations, but I hope it helps.

 a foo example:

 myArr - ff(NA, dim=rep(904,3), filename=arr.ffd, vmode=double)
 myMat - matrix(1:904^2, ncol=904)
 for ( i in 1:904 ) {
myArr[,,i] - myMat
 }

 Thanks all,

 2012/2/11 Duncan Murdoch murdoch.dun...@gmail.com

  On 12-02-10 9:12 AM, Djordje Bajic wrote:
 
  Hi all,
 
  I am trying to fill a 904x904x904 array, but at some point of the loop R
  states that the 5.5Gb sized vector is too big to allocate. I have looked
  at
  packages such as bigmemory, but I need help to decide which is the
 best
  way to store such an object. It would be perfect to store it in this
  cube
  form (for indexing and computation purpouses). If not possible, maybe
 the
  best is to store the 904 matrices separately and read them individually
  when needed?
 
  Never dealed with such a big dataset, so any help will be appreciated
 
  (R+ESS, Debian 64bit, 4Gb RAM, 4core)
 
 
  I'd really recommend getting more RAM, so you can have the whole thing
  loaded in memory.  16 Gb would be nice, but even 8Gb should make a
  substantial difference.  It's going to be too big to store as an array
  since arrays have a limit of 2^31-1 entries, but you could store it as a
  list of matrices, e.g.
 
  x - vector(list, 904)
  for (i in 1:904)
   x[[i]] - matrix(0, 904,904)
 
  and then refer to entry i,j,k as x[[i]][j,k].
 
  Duncan Murdoch
 
 
 

[[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] package.skeleton()

2011-12-19 Thread steven mosher
Here ben

 I have a tutorial on how to do it

http://stevemosher.wordpress.com/step-8-the-sample-package/



On Sun, Dec 18, 2011 at 11:49 PM, Petr PIKAL petr.pi...@precheza.cz wrote:

 Hi

 If I remember correctly I do

 start clear R -vanilla session
 copy my functions to it.
 run package.skeleton(some.name)

 which creates the some.name directory.

 Regards
 Petr

  Hi Duncan,
 
  Thanks for your response.  That's the confusing thing, I didn't receive
 a
  message and I can't seem to find the new source package directory
  anywhere.  I would greatly appreciate any advice about what I might be
  doing wrong.
 
  Happy Holidays,
 
  Ben
 
  On Fri, Dec 16, 2011 at 7:12 PM, Duncan Murdoch
 murdoch.dun...@gmail.comwrote:
 
   On 11-12-16 4:12 PM, Ben Ganzfried wrote:
  
   Hi--
  
   I'm creating an R package, I've read through Writing R Extensions
 and
   the
   package.skeleton() R page-- and I'm still running into a little
 confusion.
   I would greatly appreciate any advice you can provide.
  
   Where do I run my following line of code from?:
  
   package.skeleton(name = a, code_files = EsetObject.r
  
  
   I'm currently running it from Rgui, but when I type the line above
 nothing
   happens.
  
  
   What is supposed to happen is that a new source package directory will
 be
   created in the current directory (what getwd() gives you).  Did that
   happen?  (I thought a message would also be printed and apparently
 you're
   not seeing that, but maybe it just worked without telling you.)
  
   Duncan Murdoch
  
Thank you very much.
  
   Ben
  
  [[alternative HTML version deleted]]
  
   __**
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/
  mailman/listinfo/r-help
   PLEASE do read the posting guide http://www.R-project.org/**
   posting-guide.html http://www.R-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
  
  
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

 __
 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] Levenshtein-Distance

2011-10-20 Thread steven mosher
check the help archives.

 hclust  with method=ward  might be what you are looking for



On Wed, Oct 19, 2011 at 2:43 PM, Jörg Reuter jo...@reuter.at wrote:
 I am very new to R, so sorry that I ask stupid things.
 I want compare a Matrix row by row and at the end I want to a Matrix with
 the Levenshtein-Distance.
 Example:
 The Data (Learningpath in a E-Learning-System):
 5 12 24 35
 1 24 35
 3  35 35 45 35
 Now I need a comand, which compare the first line with the second,
 then with the third and write the result in a new Matrix. I found many
 Funktion in R, but all compare Strings, but I have numbers.
 After that I want to use the ward-argorithm at the result.
 Can anyone give me a hint, I am at the end with my nervs.

 Joerg

 __
 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] Problem with twitteR package

2011-10-11 Thread steven mosher
check the version of  libcurl you have installed. If you have an older
version  some of the
options may not be present.



On Sun, Oct 9, 2011 at 10:39 AM, Steven Oliver s1oli...@ucsd.edu wrote:
 Hey Guys,

 I just started fooling around with the twitteR package in order to get a 
 record of all tweets from a single public account. When I run userTimeline, I 
 get the default 20 most recent tweets just fine. However, when I specify an 
 arbitrary number of tweets (as described in the documentation from June 14th, 
 2011), I get the following warning:

 bjaTweets-userTimeline(BeijingAir, n=50)
 Warning message:
 In mapCurlOptNames(names(.els), asNames = TRUE) :
  Unrecognized CURL options: n

 Does anyone familiar with the twitteR package know what is going on with 
 options? Alternatively, if there are any other simple means for getting this 
 sort of data?

 Steve
 __
 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] Best Package to Extract Numbers from this Image?

2011-10-06 Thread steven mosher
 You can probably use  the package jpg , It will be a pain.  You will
have to read it in as a jpg
 then isolate the numbers ( by row and column ) then figure out some
way ( probably not that hard)
 to identify the numbers
 from the bit pattern.  I tried something similar with the png
package. it was not elegant



On Thu, Oct 6, 2011 at 6:28 PM, Jason Rupert jasonkrup...@yahoo.com wrote:
 I've done a bit of searching around on the forums looking for an R Package to 
 extract the numbers from an image like the following:
 http://www.whnt.com/extras/whnt/weather/7day_640.jpg

 I would like to be able to do this in an automated way, so thanks for any 
 hints and tips.
        [[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] Hourly data with zoo

2011-09-12 Thread steven mosher
Gabor.. thanks.

zr - zooreg(rnorm(24), as.chron(2011-01-01), frequency = 24)

a couple issues:  my date data  has missing days and missing hours..
Sorry if I was not clear on
that.. I input it to a data frame and dates are of the form  20110101
and hours are in the format
0,100,200

The end goal is to create a data structure for around 200 series aligned by time

On Mon, Sep 12, 2011 at 3:48 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 On Mon, Sep 12, 2011 at 1:58 AM, steven mosher mosherste...@gmail.com wrote:
 I have date data as a numeric and hourly data in 0 to 2300 hours in a 
 dataframe.

 d  -  rep(20110101,24)
 h  -  seq(from =  0, to  =  2300, by  = 100)

 df  -  data.frame(LST_DATE  =  d,  LST_TIME  =  h,  data  =  rnorm(24, 0, 
 1))

 S  -  chron(dates. = as.character(df$LST_DATE), times. =
 paste(as.character(df$LST_TIME/100), :0:0, sep  = ),
           format  = c(dates  =  Ymd,  times =  h:m:s))
 X  -  zoo(df$data, order.by = S)

 And I want to create a regular zoo series,  The above works but its
 pretty ugly. Is there a more elegant way to do this.

 You probably want to create a zooreg object:

 library(zoo)
 library(chron)

 zr - zooreg(rnorm(24), as.chron(2011-01-01), frequency = 24)

 although if you really do want a zoo object that is not a zooreg
 object then you can do it like this:

 z - as.zoo(zr)

 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com


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


Re: [R] Hourly data with zoo

2011-09-12 Thread steven mosher
worked beautifully.

Thanks.

On Mon, Sep 12, 2011 at 9:45 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 On Mon, Sep 12, 2011 at 11:57 AM, steven mosher mosherste...@gmail.com 
 wrote:
 Gabor.. thanks.

 zr - zooreg(rnorm(24), as.chron(2011-01-01), frequency = 24)

 a couple issues:  my date data  has missing days and missing hours..
 Sorry if I was not clear on
 that.. I input it to a data frame and dates are of the form  20110101
 and hours are in the format
 0,100,200

 The end goal is to create a data structure for around 200 series aligned by 
 time

 Try this:

 v - df$data
 z - zoo(v, as.chron(d, format = %Y%m%d) + h / 2400)



 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com


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


[R] Hourly data with zoo

2011-09-11 Thread steven mosher
I have date data as a numeric and hourly data in 0 to 2300 hours in a dataframe.

d  -  rep(20110101,24)
h  -  seq(from =  0, to  =  2300, by  = 100)

df  -  data.frame(LST_DATE  =  d,  LST_TIME  =  h,  data  =  rnorm(24, 0, 1))

S  -  chron(dates. = as.character(df$LST_DATE), times. =
paste(as.character(df$LST_TIME/100), :0:0, sep  = ),
   format  = c(dates  =  Ymd,  times =  h:m:s))
X  -  zoo(df$data, order.by = S)

And I want to create a regular zoo series,  The above works but its
pretty ugly. Is there a more elegant way to do this.

__
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] Elegant way to subtract matrix from array

2011-07-27 Thread steven mosher
there are really two related problems here

I have a 2D matrix


A - matrix(1:100,nrow=20,ncol =5)


S - matrix(1:10,nrow=2,ncol =5)


#I want to subtract S from A. so that S would be subtracted from the
first 2 rows of

#A, then the next two rows and so on.


#I have a the same problem with a 3D array

# where I want to subtract Q for every layer (1-10) in Z

# I thought I solved this one with  array(mapply(-,Z,Q),dim=dim(Z))

# but got the wrong answers


Z - array(1:100,dim=c(2,5,10))

Q - matrix(1:10,nrow=2,ncol =5)

[[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] Elegant way to subtract matrix from array

2011-07-27 Thread steven mosher
Cool,

 I looked at sweep but didnt consider it as I thought it was restricted to
certain functions.
So thanks for that solution.

  yes the data is very large and the future work will increase 10 fold,

as for the matrix one I'm not too keen on replicating the smaller matrix,
I've had one guy using the package who has hit the memory limits.. I have
one more thing to try

Thanks!

Steve

On Wed, Jul 27, 2011 at 1:42 AM, Gavin Simpson gavin.simp...@ucl.ac.ukwrote:

 On Wed, 2011-07-27 at 01:06 -0700, steven mosher wrote:
  there are really two related problems here
 
  I have a 2D matrix
 
 
  A - matrix(1:100,nrow=20,ncol =5)
 
 
  S - matrix(1:10,nrow=2,ncol =5)
 
 
  #I want to subtract S from A. so that S would be subtracted from the
  first 2 rows of
 
  #A, then the next two rows and so on.

 For this one, I have used the following trick to replication a matrix

do.call(rbind, rep(list(mat), N)

 where we convert the matrix, `mat`, to a list and repeat that list `N`
 times, and arrange for the resulting list to be rbind-ed. For your
 example matrices, the following does what you want:

A - do.call(rbind, rep(list(S), nrow(A)/nrow(S)))

 Whether this is useful will depend on the dimension of A and S - from
 your posts on R-Bloggers, I can well imagine you are dealing with large
 matrices.

  #I have a the same problem with a 3D array
 
  # where I want to subtract Q for every layer (1-10) in Z
 
  # I thought I solved this one with  array(mapply(-,Z,Q),dim=dim(Z))
 
  # but got the wrong answers
 
 
  Z - array(1:100,dim=c(2,5,10))
 
  Q - matrix(1:10,nrow=2,ncol =5)

 For this one, consider the often overlooked function `sweep()`:

sweep(Z, c(1,2), Q, -)

 does what you wanted. c(1,2) is the `MARGIN` argument over the
 dimensions that Q will be swept from.

 HTH

 G

 --
 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
  Dr. Gavin Simpson [t] +44 (0)20 7679 0522
  ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
  Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
  Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
  UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



[[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] Elegant way to subtract matrix from array

2011-07-27 Thread steven mosher
Thanks Gabor!



On Wed, Jul 27, 2011 at 3:08 AM, Gabor Grothendieck ggrothendi...@gmail.com
 wrote:

 On Wed, Jul 27, 2011 at 4:06 AM, steven mosher mosherste...@gmail.com
 wrote:
  there are really two related problems here
 
  I have a 2D matrix
 
 
  A - matrix(1:100,nrow=20,ncol =5)
 
 
  S - matrix(1:10,nrow=2,ncol =5)
 
 
  #I want to subtract S from A. so that S would be subtracted from the
  first 2 rows of
 
  #A, then the next two rows and so on.
 
 
  #I have a the same problem with a 3D array
 
  # where I want to subtract Q for every layer (1-10) in Z
 
  # I thought I solved this one with  array(mapply(-,Z,Q),dim=dim(Z))
 
  # but got the wrong answers
 
 
  Z - array(1:100,dim=c(2,5,10))
 
  Q - matrix(1:10,nrow=2,ncol =5)
 

 For the first one:

   matrix(c(t(A)) - c(t(S)), nrow(A), byrow = TRUE)

 or this version which may seem a bit more complex but has the
 advantage that it shows the general form of which both your questions
 are special cases:

ix - 2:1
aperm(array(c(aperm(A, ix)) - c(t(S)), dim(A)[ix]), ix)

 Now, as mentioned, the answer to second question is the same except for ix:

ix - c(2, 1, 3)
aperm(array(c(aperm(Z, ix)) - c(t(Q)), dim(Z)[ix]), ix)


 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com


[[alternative HTML version deleted]]

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


Re: [R] How to convert number (matlab) to date

2011-07-18 Thread steven mosher
Thanks, I just upgraded to 1.7.1

Also thanks for adding the  t()  function.



On Mon, Jul 18, 2011 at 12:38 PM, Gabor Grothendieck 
ggrothendi...@gmail.com wrote:

 On Mon, Jul 18, 2011 at 2:57 PM, peter dalgaard pda...@gmail.com wrote:
 
  On Jul 18, 2011, at 20:19 , Gabor Grothendieck wrote:
 
  On Mon, Jul 18, 2011 at 1:59 PM, peter dalgaard pda...@gmail.com
 wrote:
 
  On Jul 18, 2011, at 16:36 , Gabor Grothendieck wrote:
 
  .
 
  However, this was after reinstalling and reloading zoo. Restarting R
 and retrying did indeed make things work.
 
 
  Does the fact that it worked if R was restarted, but not without,
  imply that there is something in R that needs to be fixed?
 
  Well, zoo is rewriting code in base. Apparently, it didn't do it again
 on the second library(zoo). Not really sure who to blame for what...
 
 
  Its done in the .onLoad function in zzz.R in zoo.  It seems that if
  one re-installs zoo and then runs it that the .onLoad is not rerun.  I
  would have thought it would reload the package and therefore .onLoad
  would be run again..
 
  Also there exists .onAttach but its not used by zoo.  Should the code
  for as.Date.numeric be put in an .onAttach instead or in both .onLoad
  and .onAttach?
 
  Or perhaps not at all!
 
  I'll leave this discussion for others.
 

 An INSTALL file has been added to zoo to ask users to restart R after
 installing zoo.


 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com

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


[[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] Storing and managing custom R functions for re-use

2011-07-10 Thread steven mosher
Same here.

Just made my first package and regret not having learned how to do it from
the very beginning.

Steve


On Sun, Jul 10, 2011 at 3:27 AM, Michael Dewey i...@aghmed.fsnet.co.ukwrote:

 At 12:30 09/07/2011, Simon Chamaillé-Jammes wrote:

 Dear all,

 sorry if this is a bit on the sidetrack for R-help.

 As a regular R user I have developed quite a lot of custom R functions, to
 the point of not always remembering what I have already programmed, where
 the file is and so on.
 I was wondering what other people do in this regards. A basic file with
 all your functions, or a custom R package, or directly integrated into a
 profile file ??? I'm considering that a blog with tagged posts may be a good
 solution (and really good ones could join R-bloggers maybe).

 If someone is happy to share what (s)he considers good practice, thanks.


 I spent too many years doing what you say you are doing because creating a
 package seemed quite complicated. Once I took the plunge I found it well
 worth the effort. You do have to invest time and effort to begin with.

 You will find
 ?package.skeleton
 ?prompt
 rewarding reading as well as those sections of the R extensions document
 which are relevant to your use.

 Good luck


  simon



 Michael Dewey
 i...@aghmed.fsnet.co.uk
 http://www.aghmed.fsnet.co.uk/**home.htmlhttp://www.aghmed.fsnet.co.uk/home.html


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


[[alternative HTML version deleted]]

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


Re: [R] Package warnings

2011-06-22 Thread steven mosher
Thanks Duncan, I'll join Dev and ask the questions over there.

Steve

On Wed, Jun 22, 2011 at 7:19 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 11-06-21 11:58 PM, steven mosher wrote:

 Thanks to all your help I've just finished my first package and I have a
 couple of questions



   I want to submit to CRAN but I have  1 warning

   checking for code/documentation mismatches ... WARNING
 Data sets with usage in documentation object 'FILE.PARAMETERS' but not in
 code:
   FILE.PARAMETERS

 I actually have a few instances with the same issue. I have a handful of
 data objects, things like URLs
 and some file parameters ( like column widths etc). These are declared in
 an
 R file and then loaded
 (lazyData no)

 There are help files for all these objects, and some of them get used in
 the
 code as defaults for when
 functions are called
  foo- function( x, y=FILE.PARAMETERS)

 So why do I get this warning? is it one I have to fix? and should I be
 asking this on the dev list?


 Yes, you should fix almost all warnings, and yes, questions like this
 belong on the R-devel list.

 When you ask there, it would be helpful to be very specific:  show us the
 start of the Rd file that is being complained about (the \usage and \docType
 sections are of particular interest), and give us the exact details about
 how the data object is being created.

 Duncan Murdoch


 Thanks again for all your help, hope this is right place to ask.

[[alternative HTML version deleted]]

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




[[alternative HTML version deleted]]

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


Re: [R] Package warnings

2011-06-22 Thread steven mosher
 Thanks all the issue is closed.

  in this case I had a data element  FILE.PARAMETERS = list()

  the .Rd files created by package.skelton() for data objects  had the
following for \usage.



 \usage{data(FILE.PARAMETERS)}

 I left that as is and  CHECK throws a warning.

 checking for code/documentation mismatches ... WARNING
Data sets with usage in documentation object 'FILE.PARAMETERS' but not in
code:

changing \usage  cleared the warning

\usage{FILE.PARAMETERS}

clears check!  crantastic, no warnings, no errors!



On Wed, Jun 22, 2011 at 8:29 AM, steven mosher mosherste...@gmail.comwrote:

 Thanks Duncan, I'll join Dev and ask the questions over there.

 Steve


 On Wed, Jun 22, 2011 at 7:19 AM, Duncan Murdoch 
 murdoch.dun...@gmail.comwrote:

 On 11-06-21 11:58 PM, steven mosher wrote:

 Thanks to all your help I've just finished my first package and I have a
 couple of questions



   I want to submit to CRAN but I have  1 warning

   checking for code/documentation mismatches ... WARNING
 Data sets with usage in documentation object 'FILE.PARAMETERS' but not in
 code:
   FILE.PARAMETERS

 I actually have a few instances with the same issue. I have a handful of
 data objects, things like URLs
 and some file parameters ( like column widths etc). These are declared in
 an
 R file and then loaded
 (lazyData no)

 There are help files for all these objects, and some of them get used in
 the
 code as defaults for when
 functions are called
  foo- function( x, y=FILE.PARAMETERS)

 So why do I get this warning? is it one I have to fix? and should I be
 asking this on the dev list?


 Yes, you should fix almost all warnings, and yes, questions like this
 belong on the R-devel list.

 When you ask there, it would be helpful to be very specific:  show us the
 start of the Rd file that is being complained about (the \usage and \docType
 sections are of particular interest), and give us the exact details about
 how the data object is being created.

 Duncan Murdoch


 Thanks again for all your help, hope this is right place to ask.

[[alternative HTML version deleted]]

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





[[alternative HTML version deleted]]

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


[R] Package warnings

2011-06-21 Thread steven mosher
Thanks to all your help I've just finished my first package and I have a
couple of questions



  I want to submit to CRAN but I have  1 warning

  checking for code/documentation mismatches ... WARNING
Data sets with usage in documentation object 'FILE.PARAMETERS' but not in
code:
  FILE.PARAMETERS

I actually have a few instances with the same issue. I have a handful of
data objects, things like URLs
and some file parameters ( like column widths etc). These are declared in an
R file and then loaded
(lazyData no)

There are help files for all these objects, and some of them get used in the
code as defaults for when
functions are called
 foo - function( x, y=FILE.PARAMETERS)

So why do I get this warning? is it one I have to fix? and should I be
asking this on the dev list?

Thanks again for all your help, hope this is right place to ask.

[[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] Permission denied in Windows 7

2011-06-09 Thread steven mosher
Prof, Ripley.

I think I figured it out.  I took the instructions for  code_files to mean
that you had to supply the
path to the directory and not the paths to all the files within that
directory.

I'll show my work below  which should make  clear the mistake that I made

  sessionInfo()R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] R.utils_1.7.5 R.oo_1.8.0R.methodsS3_1.2.1

loaded via a namespace (and not attached):
[1] tools_2.13.0
   getwd()[1] C:/Users/steve/Documents/GHCNPackage
list.files(full.names=TRUE)[1] ./d.R ./f.R

  filePath - getwd()  filePath[1]
C:/Users/steve/Documents/GHCNPackage
package.skeleton(name=testpackage,code_files=filePath)Error in
file(file, r) : cannot open the connectionIn addition: Warning
message:In file(file, r) :
  cannot open file 'C:/Users/steve/Documents/GHCNPackage': Permission denied

# Looks like I need a path all the way to the file.

# start with one file to test   testFile
-file.path(filePath,d.R,fsep=.Platform$file.sep)
package.skeleton(name=testpackage,code_files=testFile)Creating
directories ...Creating DESCRIPTION ...Creating Read-and-delete-me
...Copying code files ...Making help files ...Done.Further steps are
described in './testpackage/Read-and-delete-me'.  ?package.skeleton()

  testFile2 -file.path(filePath,f.R,fsep=.Platform$file.sep)
package.skeleton(name=testpackage,code_files=c(testFile,testFile2))Creating
directories ...Error in package.skeleton(name = testpackage,
code_files = c(testFile,  :
  directory './testpackage' already exists
package.skeleton(name=testpackage,code_files=c(testFile,testFile2))Creating
directories ...Creating DESCRIPTION ...Creating Read-and-delete-me
...Copying code files ...Making help files ...Done.Further steps are
described in './testpackage/Read-and-delete-me'.


Success. I assumed that you just passed in the directory that   contained
all the source
Files and that all the files in that directory ending in .R would be used.

Thanks

On Wed, Jun 8, 2011 at 11:44 PM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote:

 On Wed, 8 Jun 2011, steven mosher wrote:

  I'm using package.skeleton()  windows 7, 64 bit.

 When I try to specify the code_files

 package_skeleton(code_files =   some directory)

 I get a warning that that the connection cannot be opened and
 I get a Permissions denied error.


 Which connection?  Please copy-and-paste exactly what you did and what the
 output was.


  I'm running R as admin and I've given everybody full permissions on the
 folder.

 What am I missing


 There can be more to that on Windows 7.  Is it read-only, for example?
 One thing which often catches users of POSIX operating systems (like me) is
 that read-only files are also no-delete files.

 [[alternative HTML version deleted]]


 Please don't keep sending HTML when the posting guide expressly asked you
 not to.

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


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


[[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] Permission denied in Windows 7

2011-06-08 Thread steven mosher
I'm using package.skeleton()  windows 7, 64 bit.

When I try to specify the code_files

package_skeleton(code_files =   some directory)

I get a warning that that the connection cannot be opened and
I get a Permissions denied error.

I'm running R as admin and I've given everybody full permissions on the
folder.

What am I missing

[[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] Questions about building R packages

2011-06-08 Thread steven mosher
here  i wrote a step by step tutorial.

http://stevemosher.wordpress.com/2011/06/09/making-simple-packages-in-r-on-windows/

On Wed, Jun 8, 2011 at 1:17 PM, Xia.Li oddity...@gmail.com wrote:

 Hello R users,

 I have difficulties when trying to make R packages. I tried to read many
 tutorials but still could not find out the right way. Could any one help me
 out please? (I'm using Windows xp.)

 After running package.skeleton() and edit those RD files, I don't know how
 to use Rtools (or CMD shell?) to build the zip file. I installed the Rtools
 from Murdoch's link, but it doesn't look like a software...

 Anyone could give me a tutorial with more details about Rtools (or CMD
 shell)? I've already have MikTex installed.

 Thanks!

 --
 View this message in context:
 http://r.789695.n4.nabble.com/Questions-about-building-R-packages-tp3583510p3583510.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] Problem with package development

2011-06-02 Thread steven mosher
I hope you're successful because I'm having issues as well building a simple
package on
windows.  maybe when you're finished  you can share back a step by step
guide.

On Thu, Jun 2, 2011 at 12:21 PM, Nipesh Bajaj bajaj141...@gmail.com wrote:

 I have run R CMD check trial1 and saw an error. This says that:

 * checking pdf version of manual without hyperrefs or index  ... ERROR
 Re-running with no redirection of stdout/stderr.
 Hmm... looks like a package
 Error in texi2dvi(Rd2.tex, pdf = (out_ext == pdf), quiet = FALSE, :
 pdflatex is not available
 Error in running tools:: texi2dvi

 Does this information hwlp you to suggest something? Please let me
 know what else I can provide.

 Thanks,

 On Fri, Jun 3, 2011 at 12:00 AM, Nipesh Bajaj bajaj141...@gmail.com
 wrote:
  What else I need to do? In the Read-and-delete-me file following steps
  are asked to perform:
  * Edit the help file skeletons in 'man', possibly combining help files
  for multiple functions.
  * Edit the exports in 'NAMESPACE', and add necessary imports.
  * Put any C/C++/Fortran code in 'src'.
  * If you have compiled code, add a useDynLib() directive to 'NAMESPACE'.
  * Run R CMD build to build the package tarball.
  * Run R CMD check to check the package tarball.
 
  I editied the help page for fn1() function (as I already communicated
  in previous mail) as follows:
  \name{fn1}
  \alias{fn1}
 
  \title{
  A function.
  }
 
  \description{
  A function.
  }
 
  \usage{
  A function.
  }
 
  \arguments{
  A function.
  }
 
  \value{
  A function.
  }
 
  \author{
  \bold{Me}
  \cr
  \email{m...@me.com}
  }
 
  And regarding th Namespace file, this time I put
  package.skeleton(trial1,namespace = FALSE, code_files =
  f:/trial.r)
  
 
  I do not have any C/C++ code so I ignored 3rd step.
 
  then Read-and-delete-me file asking me to build the package, so in
  cmd, I run following:
  cd C:\R_PackageBuild
  Rcmd build –binary trial1
 
  What I am missing in this entire process? Do you please point me?
 
  Thanks,
 
 
  On Thu, Jun 2, 2011 at 11:40 PM, Duncan Murdoch
  murdoch.dun...@gmail.com wrote:
  On 02/06/2011 2:03 PM, Nipesh Bajaj wrote:
 
  Thanks Prof. Ripley and Duncan for your pointers. Noting down your
  points I have modified my way of building package and have done
  following so far:
 
  1. In my C: drive I create one working folder naming R_PackageBuild
  2. In R console I have written following codes:
setwd(c:/R_packageBuild)
package.skeleton(trial1,namespace = TRUE, code_files =
 f:/trial.r)
  3. then I opened cmd and wrote following:
  cd C:\R_PackageBuild
  Rcmd build –binary trial1
 
  This process halted with following error:
  Error: unexpected symbol in 
  “tools:::.test_load_package(‘trial1′,….)”
  Execution halted
  ERROR: loading failed
 
  What I have missed in this process? Can you please help me how to
  solve this issue?
 
  You haven't done the manual changes required between steps 2 and 3.
   package.skeleton() creates the skeleton of a package; you run it once
 as
  you are starting development, the do a lot of manual updates, described
 on
  the ?package.skeleton help page, and in the  ‘Read-and-delete-me’ file.
   Once those are done, step 3 should succeed.
 
  Duncan Murdoch
 
  Thanks,
 
  PS: I am sorry I missplet 'Program Files'. Thanks Prof. Ripley for this
  pointer.
 
  On Wed, Jun 1, 2011 at 11:41 AM, Prof Brian Ripley
  rip...@stats.ox.ac.uk  wrote:
On Wed, 1 Jun 2011, Nipesh Bajaj wrote:
  
I have been struggling for last one hour but not yet any through.
  
However again I recreate the package.skeleton and run R CMD check
   trial3
  
Here are the errors:
  
warning in dir.create(pkgoutdir, mode = 0755):
cannot create dir 'c:\Program files\R\R-2.13.0\bin\trial3.Rcheck',
reason .
Error in printLog(Log, , text, \n): object 'Log' not found
Execution haulted
  
Why I am getting this error? what is that Log. I will really
appreciate if somebody please help me to figure out.
  
R CMD check writes a (in your case) trial3.Rcheck directory, and in
   there in
file 00check.log a copy of the log.  If it cannot create
 trial3.Rcheck
   it
cannot write the log.
  
I would be surprised that even on Windows Vista the message was
   literally
  
reason .
  
but if it was, blame Microsoft for their error messages.
But
  
cannot create dir 'c:\Program files\R\R-2.13.0\bin\trial3.Rcheck',
  
is clear enough.  You need to run 'R CMD check' in your user area.
In case you did this because that is where you though 'R' was, it is
   not the
correct R.exe.   You may need to add
  
c:\Program Files\R\R-2.13.0\bin\i386
  
(assuming 32-bit R) to your path.
  
However, your use of e.g. 'Program files' suggests you are not
   accurately
transmitting the messages you got.
  
  
  
Thanks,
  
On Wed, Jun 1, 2011 at 1:20 AM, Nipesh 

Re: [R] help with barplot

2011-05-28 Thread steven mosher
Thanks,

  ggplot is on my list of things to learn before Hadley comes here to the
bay area
 to give a session on interactive graphics in R

On Fri, May 27, 2011 at 10:29 PM, Joshua Wiley jwiley.ps...@gmail.comwrote:

 Hi Steven,

 This is not, strictly speaking, the answer to your question (hopefully
 Tom already answered that).  Rather, it is the answer to questions you
 *might* have asked (and perhaps one of them will be one you wished you
 had asked).

 Barplots have a low data:ink ratio...you are using an entire plot to
 convey 8 means.  A variety of alternatives exist.  As a minimal first
 step, you could just use points to show the means and skip all the
 wasted bar space, and you might add error bars in (A).  You could also
 use boxplots to give your viewers (or just yourself) a sense of the
 distribution along with the medians (B).  Another elegant option is
 violin plots.  These are kind of like (exactly like?) mirrored density
 plots.  A measure of central tendency is not explicitly shown, but the
 *entire* distribution and range is shown (C).

 Cheers,

 Josh

 (P.S. I hit send too soon before and sent you an offlist message with
 PDF examples)

 ## Create your data
 DF - data.frame(
   Incidents = factor(rep(c(a, b, d, e), each = 25)),
  Months = factor(rep(1:2, each = 10)),
  Time = rnorm(100))

 ## Load required packages
 require(ggplot2)
 require(Hmisc)

 ## Option A
 ggplot(DF, aes(x = Incidents, y = Time, colour = Months)) +
  stat_summary(fun.y = mean, geom = point,
position = position_dodge(width = .90), size = 3) +
  stat_summary(fun.data = mean_cl_normal, geom = errorbar,
position = dodge)

 ## Option B
 ggplot(DF, aes(x = Incidents, y = Time, fill = Months)) +
  geom_boxplot(position = position_dodge(width = .8))

 ## Option C
 ggplot(DF, aes(x = Time, fill = Months)) +
  geom_ribbon(aes(ymax = ..density.., ymin = -..density..),
alpha = .2, stat = density) +
  facet_grid( ~ Incidents) +
  coord_flip()

 ## Option C altered
 ggplot(DF, aes(x = Time, fill = Months)) +
  geom_ribbon(aes(ymax = ..density.., ymin = -..density..),
alpha = .2, stat = density) +
  facet_grid( ~ Incidents + Months) +
  scale_y_continuous(name = density, breaks = NA, labels = NA) +
  coord_flip()

 On Fri, May 27, 2011 at 3:08 PM, steven mosher mosherste...@gmail.com
 wrote:
  Hi,
 
  I'm really struggling with barplot
 
  I have a data.frame with 3 columns. The first column represents an
  incident type
  The second column represents a month
  The third column represents a time
 
  Code for a sample data.frame
 
  incidents - rep(c('a','b','d','e'), each =25)
   months- rep(c(1,2), each =10)
   times -rnorm(100)
 
  #  make my sample data
 
   DF-
 
 data.frame(Incidents=as.factor(incidents),Months=as.factor(months),Time=times)
 
  # now calculate a mean for the  by groups of incident type and month
 
   pivot -
 
 aggregate(DF$Time,by=list(Incidents=DF$Incidents,Months=DF$Month),FUN=mean,simplify=TRUE)
 
  What I want to create is a bar plot where  I have groupings by incident
 type
  ( a,b,d,e) and within each group
  I have the months in order.
 
  So group 1 would  be  Type a; month 1,2;
  group 2 would  be  Type b; month 1,2;
  group 3 would  be  Type d; month 1,2;
 group 4 would  be  Type 3; month 1,2;
 
  I know barplot is probably the right function but I'm a bit lost on how
 to
  specify groupings etc
 
  TIA
 
 [[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.
 



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/


[[alternative HTML version deleted]]

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


Re: [R] help with barplot

2011-05-28 Thread steven mosher
Thanks Thomas.





On Sat, May 28, 2011 at 11:29 AM, Thomas Levine thomas.lev...@gmail.comwrote:

 You can do pretty well without ggplot actually.

 boxplot(Time~paste(Incidents,Months),data=DF,border=c('grey20','red'))

 On Sat, May 28, 2011 at 2:55 AM, steven mosher mosherste...@gmail.com
 wrote:
  Thanks,
 
   ggplot is on my list of things to learn before Hadley comes here to the
  bay area
   to give a session on interactive graphics in R
 
  On Fri, May 27, 2011 at 10:29 PM, Joshua Wiley jwiley.ps...@gmail.com
 wrote:
 
  Hi Steven,
 
  This is not, strictly speaking, the answer to your question (hopefully
  Tom already answered that).  Rather, it is the answer to questions you
  *might* have asked (and perhaps one of them will be one you wished you
  had asked).
 
  Barplots have a low data:ink ratio...you are using an entire plot to
  convey 8 means.  A variety of alternatives exist.  As a minimal first
  step, you could just use points to show the means and skip all the
  wasted bar space, and you might add error bars in (A).  You could also
  use boxplots to give your viewers (or just yourself) a sense of the
  distribution along with the medians (B).  Another elegant option is
  violin plots.  These are kind of like (exactly like?) mirrored density
  plots.  A measure of central tendency is not explicitly shown, but the
  *entire* distribution and range is shown (C).
 
  Cheers,
 
  Josh
 
  (P.S. I hit send too soon before and sent you an offlist message with
  PDF examples)
 
  ## Create your data
  DF - data.frame(
Incidents = factor(rep(c(a, b, d, e), each = 25)),
   Months = factor(rep(1:2, each = 10)),
   Time = rnorm(100))
 
  ## Load required packages
  require(ggplot2)
  require(Hmisc)
 
  ## Option A
  ggplot(DF, aes(x = Incidents, y = Time, colour = Months)) +
   stat_summary(fun.y = mean, geom = point,
 position = position_dodge(width = .90), size = 3) +
   stat_summary(fun.data = mean_cl_normal, geom = errorbar,
 position = dodge)
 
  ## Option B
  ggplot(DF, aes(x = Incidents, y = Time, fill = Months)) +
   geom_boxplot(position = position_dodge(width = .8))
 
  ## Option C
  ggplot(DF, aes(x = Time, fill = Months)) +
   geom_ribbon(aes(ymax = ..density.., ymin = -..density..),
 alpha = .2, stat = density) +
   facet_grid( ~ Incidents) +
   coord_flip()
 
  ## Option C altered
  ggplot(DF, aes(x = Time, fill = Months)) +
   geom_ribbon(aes(ymax = ..density.., ymin = -..density..),
 alpha = .2, stat = density) +
   facet_grid( ~ Incidents + Months) +
   scale_y_continuous(name = density, breaks = NA, labels = NA) +
   coord_flip()
 
  On Fri, May 27, 2011 at 3:08 PM, steven mosher mosherste...@gmail.com
  wrote:
   Hi,
  
   I'm really struggling with barplot
  
   I have a data.frame with 3 columns. The first column represents an
   incident type
   The second column represents a month
   The third column represents a time
  
   Code for a sample data.frame
  
   incidents - rep(c('a','b','d','e'), each =25)
months- rep(c(1,2), each =10)
times -rnorm(100)
  
   #  make my sample data
  
DF-
  
 
 data.frame(Incidents=as.factor(incidents),Months=as.factor(months),Time=times)
  
   # now calculate a mean for the  by groups of incident type and month
  
pivot -
  
 
 aggregate(DF$Time,by=list(Incidents=DF$Incidents,Months=DF$Month),FUN=mean,simplify=TRUE)
  
   What I want to create is a bar plot where  I have groupings by
 incident
  type
   ( a,b,d,e) and within each group
   I have the months in order.
  
   So group 1 would  be  Type a; month 1,2;
   group 2 would  be  Type b; month 1,2;
   group 3 would  be  Type d; month 1,2;
  group 4 would  be  Type 3; month 1,2;
  
   I know barplot is probably the right function but I'm a bit lost on
 how
  to
   specify groupings etc
  
   TIA
  
  [[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.
  
 
 
 
  --
  Joshua Wiley
  Ph.D. Student, Health Psychology
  University of California, Los Angeles
  http://www.joshuawiley.com/
 
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


[[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 with barplot

2011-05-27 Thread steven mosher
Hi,

I'm really struggling with barplot

I have a data.frame with 3 columns. The first column represents an
incident type
The second column represents a month
The third column represents a time

Code for a sample data.frame

incidents - rep(c('a','b','d','e'), each =25)
 months- rep(c(1,2), each =10)
 times -rnorm(100)

#  make my sample data

 DF-
data.frame(Incidents=as.factor(incidents),Months=as.factor(months),Time=times)

# now calculate a mean for the  by groups of incident type and month

 pivot -
aggregate(DF$Time,by=list(Incidents=DF$Incidents,Months=DF$Month),FUN=mean,simplify=TRUE)

What I want to create is a bar plot where  I have groupings by incident type
( a,b,d,e) and within each group
I have the months in order.

So group 1 would  be  Type a; month 1,2;
 group 2 would  be  Type b; month 1,2;
 group 3 would  be  Type d; month 1,2;
group 4 would  be  Type 3; month 1,2;

I know barplot is probably the right function but I'm a bit lost on how to
specify groupings etc

TIA

[[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] Understanding tryCatch

2011-03-18 Thread steven mosher
I've read the help and the archives on tryCatch but I'm still stuggling
trying to understand how it
works exactly and how I can use it to get the result I need.

I have a data.frame of urls which point to 11 .zip files. Basically I use
RCurl to get the list of
files from a ftp and then reduce that directory dump to the 11 zip files I
want to download.

Its easy enough to do that in a loop over the elements in data.frame.

The problem is that the site is very inconsistent. All 11 files will
download, but I will get random
warnings that the size of some of the files does not match what was
downloaded.
So at the end of the loop I may get 5 warnings about the file size not
matching.
These files, when tried a second or third time, will eventually download
properly.

What I want to do is record which files had this download warning.

[[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] Understanding tryCatch

2011-03-18 Thread steven mosher
 That works
# hydeUrls = vector of urls to file names
#destList   = vector of destination file names

for(files in 1:length(hydeUrls)){
filesFailed[files]- FALSE
filesFailed[files] -
tryCatch(download.file(url=hydeUrls[files],destfile=destList[files],quiet=FALSE,mode=wb),warning=function(m)
m-TRUE)
 print(filesFailed[files])
 }

And below I get the result I want which has flagged this file as improperly
downloaded.
note the difference between the file length and the amount downloaded.

trying URL 'ftp://ftp.mnp.nl/hyde/hyde31_final/1870ad_pop.zip'ftp data
connection made, file length 14394402 bytesopened URLdownloaded 2.8 Mb
[1] 1



And on successful download


trying URL 'ftp://ftp.mnp.nl/hyde/hyde31_final/1910ad_pop.zip'ftp data
connection made, file length 14694703 bytesopened URLdownloaded 14.0
Mb
[1] 0



On Fri, Mar 18, 2011 at 12:17 PM, Henrique Dallazuanna www...@gmail.comwrote:

 Try this:

 tryCatch(log(rnorm(10)), warning = function(m)deparse(m$call[[2]]))

 Where log(rnorm(10)) is your expr to evaluate.

 On Fri, Mar 18, 2011 at 4:04 PM, steven mosher mosherste...@gmail.com
 wrote:
  I've read the help and the archives on tryCatch but I'm still stuggling
  trying to understand how it
  works exactly and how I can use it to get the result I need.
 
  I have a data.frame of urls which point to 11 .zip files. Basically I use
  RCurl to get the list of
  files from a ftp and then reduce that directory dump to the 11 zip files
 I
  want to download.
 
  Its easy enough to do that in a loop over the elements in data.frame.
 
  The problem is that the site is very inconsistent. All 11 files will
  download, but I will get random
  warnings that the size of some of the files does not match what was
  downloaded.
  So at the end of the loop I may get 5 warnings about the file size not
  matching.
  These files, when tried a second or third time, will eventually download
  properly.
 
  What I want to do is record which files had this download warning.
 
 [[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.
 



 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O


[[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] s3 methods on S4 objects

2011-01-13 Thread steven mosher
On Thu, Jan 13, 2011 at 6:46 AM, Martin Morgan mtmor...@fhcrc.org wrote:

 On 01/12/2011 10:54 PM, steven mosher wrote:
  I have J Chambers wonderful text ( Software for data Analysis) and I've
 been
  trying
  my hand at some very routine S4 OOP development.
 
  One of the things I was trying to do was to create some very basic S4
  classes. The first
  was simply a class that had a data.frame as part of its representation.
 
  setClass(df,representation(dirframe=data.frame))
 
  The object basically contains a data.frame that represents a file
 directory
  listing
  with a column named filename, size, time, etc.
 
  And then I have methods for doing various things with this object.
 
  I then tried to tackle the problem of coercing this S4 object to a
  data.frame. Again just a learning exercise.
 
  The goal would be able to make a call like this
 
  testFrame - as.data.frame(x)
 
  where x, was an object of class  df
 
  If I try to define as.data.frame as a S4 method, then I can make it
 work,
  but I then destroy the S3 functionality
  of as.data.frame, so that if I were to try to coerce a matrix to a
  data.frame it would work.

 Hi Steven --

 This works for  me

 setClass(A, representation=representation(df=data.frame))

 setMethod(as.data.frame, A,
function(x, row.names=NULL, optional=FALSE, ...)
 {
## implementation, e.g.,
callGeneric(x@df, row.names=row.names, optional=optional, ...)
 })


this makes no sense to me.

Looking at this in the manual:
A call to callGeneric can only appear inside a method definition. It then
results in a call to the current generic function. The value of that call is
the value of callGeneric. While it can be called from any method, it is
useful and typically used in methods for group generic functions.

I'm further confused. what is the current generic function?


  as.data.frame(new(A))
 Object of class data.frame
 data frame with 0 columns and 0 rows
  as.data.frame(matrix(0, 3, 5))
  V1 V2 V3 V4 V5
 1  0  0  0  0  0
 2  0  0  0  0  0
 3  0  0  0  0  0


 Maybe you call setGeneric (no need to, setMethod will promote
 as.data.frame automatically) in a way that does not specify the default
 (arg useAsDefault) correctly?


  I think that may have been the mistake.. what do you mean by
no need to call setGeneric?

I really like chambers book, but there are certain parts where the lack of
simple examples
really makes it difficult to follow.


 Martin


 
 
  So, I guess my question is what do I do, write an s3 method for
  as.data.frame that takes  a df object as a paramter?
  The book wasn't exactly clear ( or I'm not that bright), or is there a
 way
  to make the S4 method I wrote as.data.frame
  call the S3 method if needed?
 
[[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.


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

 Location: M1-B861
 Telephone: 206 667-2793


[[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] s3 methods on S4 objects

2011-01-13 Thread steven mosher
Martin,  that helps. I

I made the mistake you outlined below

  setGeneric(as.data.frame,
 function(x) standardGeneric(as.data.frame))
Creating a generic for 'as.data.frame' in package '.GlobalEnv'
   (the supplied definition differs from and overrides the implicit generic
   in package 'base': Formal arguments differ: (x), (x, row.names,
optional, ...))
[1] as.data.frame

then I'm in trouble -- I've created a generic 'as.data.frame', but since
the signature of my generic differs from the signature of
base::as.data.frame, the default behavior does NOT create a
as.data.frame,ANY method.



this, as you note leads to trouble

And of course got in trouble.

setClass(Class=ftpdir,
 representation = list(dirframe=data.frame))


 if (!isGeneric(as.data.frame)) {
setGeneric(as.data.frame, function(dirlist )
 standardGeneric(as.data.frame))
}

setMethod(as.data.frame,
signature(dirlist = ftpdir ),
function (dirlist )
{
  return( dirlist@dirframe)
}
)

On Thu, Jan 13, 2011 at 10:33 AM, Martin Morgan mtmor...@fhcrc.org wrote:

 On 01/13/2011 09:49 AM, steven mosher wrote:
 
 
  On Thu, Jan 13, 2011 at 6:46 AM, Martin Morgan mtmor...@fhcrc.org
  mailto:mtmor...@fhcrc.org wrote:
 
  On 01/12/2011 10:54 PM, steven mosher wrote:
   I have J Chambers wonderful text ( Software for data Analysis) and
  I've been
   trying
   my hand at some very routine S4 OOP development.
  
   One of the things I was trying to do was to create some very basic
 S4
   classes. The first
   was simply a class that had a data.frame as part of its
  representation.
  
   setClass(df,representation(dirframe=data.frame))
  
   The object basically contains a data.frame that represents a file
  directory
   listing
   with a column named filename, size, time, etc.
  
   And then I have methods for doing various things with this object.
  
   I then tried to tackle the problem of coercing this S4 object to a
   data.frame. Again just a learning exercise.
  
   The goal would be able to make a call like this
  
   testFrame - as.data.frame(x)
  
   where x, was an object of class  df
  
   If I try to define as.data.frame as a S4 method, then I can make
  it work,
   but I then destroy the S3 functionality
   of as.data.frame, so that if I were to try to coerce a matrix to a
   data.frame it would work.
 
  Hi Steven --
 
  This works for  me
 
  setClass(A, representation=representation(df=data.frame))
 
  setMethod(as.data.frame, A,
 function(x, row.names=NULL, optional=FALSE, ...)
  {
 ## implementation, e.g.,
 callGeneric(x@df, row.names=row.names, optional=optional, ...)
  })
 
 
  this makes no sense to me.
 
  Looking at this in the manual:
  A call to callGeneric can only appear inside a method definition. It
  then results in a call to the current generic function. The value of
  that call is the value of callGeneric. While it can be called from any
  method, it is useful and typically used in methods for group generic
  functions.

 callGeneric is not necessary, and I should just have said

  as.data.frame(x@df, row.names=row.names, optional=optional, ...)

  I'm further confused. what is the current generic function?

 I think of a generic 'foo' as a function, and inside that function are
 functions foo,A-method, foo,B-method etc for classes A, B,  When in
 one of these methods, foo,A-method, the current generic is the function
 'foo'. For as.data.frame, the generic is unambiguous ('as.data.frame' !)
 and the interesting case are the group generics (?Logic, for instance),
 where a single method

  setMethod(Logic, function(e1, e2) callGeneric(YOUR CODE HERE))

 and you'll have in effect written 'methods' for all the operators
 defined in the 'Logic' group. Cool.

 
   as.data.frame(new(A))
  Object of class data.frame
  data frame with 0 columns and 0 rows
   as.data.frame(matrix(0, 3, 5))
   V1 V2 V3 V4 V5
  1  0  0  0  0  0
  2  0  0  0  0  0
  3  0  0  0  0  0
 
 
  Maybe you call setGeneric (no need to, setMethod will promote
  as.data.frame automatically) in a way that does not specify the
 default
  (arg useAsDefault) correctly?
 
 
I think that may have been the mistake.. what do you mean by
  no need to call setGeneric?

 The only code I had was what was written above -- setClass and
 setMethod. I could also have

  setGeneric(as.data.frame)

 and would have been ok -- the default behavior of setGeneric in this
 case is to make a generic function as.data.frame, AND a method
 as.data.frame,ANY-method. The as.data.frame,ANY-method is implemented as
 base::as.data.frame, and is where objects not handled by methods I
 implement might end up being dispatched to. In a new R session, try

  setGeneric(as.data.frame)
  showMethods(as.data.frame

[R] s3 methods on S4 objects

2011-01-12 Thread steven mosher
I have J Chambers wonderful text ( Software for data Analysis) and I've been
trying
my hand at some very routine S4 OOP development.

One of the things I was trying to do was to create some very basic S4
classes. The first
was simply a class that had a data.frame as part of its representation.

setClass(df,representation(dirframe=data.frame))

The object basically contains a data.frame that represents a file directory
listing
with a column named filename, size, time, etc.

And then I have methods for doing various things with this object.

I then tried to tackle the problem of coercing this S4 object to a
data.frame. Again just a learning exercise.

The goal would be able to make a call like this

testFrame - as.data.frame(x)

where x, was an object of class  df

If I try to define as.data.frame as a S4 method, then I can make it work,
but I then destroy the S3 functionality
of as.data.frame, so that if I were to try to coerce a matrix to a
data.frame it would work.


So, I guess my question is what do I do, write an s3 method for
as.data.frame that takes  a df object as a paramter?
The book wasn't exactly clear ( or I'm not that bright), or is there a way
to make the S4 method I wrote as.data.frame
call the S3 method if needed?

[[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] Accessing data via url

2011-01-06 Thread steven mosher
https

your second link is an https

that's not supported as I recall.

?url

On Thu, Jan 6, 2011 at 11:53 AM, John Kane jrkrid...@yahoo.ca wrote:

 #   Can anyone suggest why this works

 datafilename - 
 http://personality-project.org/r/datasets/maps.mixx.epi.bfi.data;
 person.data  - read.table(datafilename,header=TRUE)

 # but this does not?

 dd - 
 https://sites.google.com/site/jrkrideau/home/general-stores/trees.txt;
 treedata - read.table(dd, header=TRUE)

 ===

 Error in file(file, rt) : cannot open the connection
 In addition: Warning message:
 In file(file, rt) : unsupported URL scheme

 # I can access both through a hyperlink in OOO Calc. t
 #  Thanks

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


[[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] Accessing data via url

2011-01-06 Thread steven mosher
Here John,

from the manual

URLs

A note on file:// URLs. The most general form (from RFC1738) is
file://host/path/to/file, but R only accepts the form with an empty host
field referring to the local machine. This is then file:///path/to/file,
where path/to/file is relative to ‘/’. So although the third slash is
strictly part of the specification not part of the path, this can be
regarded as a way to specify the file ‘/path/to/file’. It is not possible to
specify a relative path using a file URL.

No attempt is made to decode an encoded URL: call URLdecode if necessary.

Note that https:// connections are not supported.

So, when you use a https Url as opposed to a http url the former is not
supported.

You might try RCurl package

getURL()

which has support for HTTPS, provided your libcurl has support for SSL ( as
I recall)


On Thu, Jan 6, 2011 at 11:53 AM, John Kane jrkrid...@yahoo.ca wrote:

 #   Can anyone suggest why this works

 datafilename - 
 http://personality-project.org/r/datasets/maps.mixx.epi.bfi.data;
 person.data  - read.table(datafilename,header=TRUE)

 # but this does not?

 dd - 
 https://sites.google.com/site/jrkrideau/home/general-stores/trees.txt;
 treedata - read.table(dd, header=TRUE)

 ===

 Error in file(file, rt) : cannot open the connection
 In addition: Warning message:
 In file(file, rt) : unsupported URL scheme

 # I can access both through a hyperlink in OOO Calc. t
 #  Thanks

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


[[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] Navigating web pages using R

2011-01-05 Thread steven mosher
Hmm,

Rcurl may be able to help you. Not sure I have not played with the query
abilities.

On Tue, Jan 4, 2011 at 10:54 AM, Erik Gregory egregory2...@yahoo.comwrote:

 R-Help,

 I'm trying to obtain some data from a webpage which masks the URL from the
 user,
 so an explicit URL will not work.  For example, when one navigates to the
 web
 page the URL looks something like:
 http://137.113.141.205/rpt34s.php?flags=1 (changed for privacy, but i'm
 not sure
 you could access it anyways since it's internal to the agency I work for).
 The site has three drop-down menus for Site, Month, and Year.  When a
 combination is selected of these, the resulting URL is
 always http://137.113.141.205/rpt34s (nothing changes, except flags=1 is
 dropped, so what I need to be able to do is write something that will
 navigate
 to the original URL, then select some combination of Site, Month, and
 Year, and then submit the query to the site to navigate to the page with
 the
 data.
 Is this a capability that R has as a language?  Unfortunately, I'm
 unfamiliar
 with html or php programming, so if this question belongs in a forum on
 that I
 apologize.  I'm trying to centralize all of my code for my analysis in R!

 Thank you,
 -Erik Gregory
 Student Assistant, California EPA
 CSU Sacramento, Mathematics

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


[[alternative HTML version deleted]]

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


[R] lm() on a matrix of zoo series

2010-12-21 Thread steven mosher
I have a matrix of zoo series. each series is in a column.
 x - as.yearmon(2000 + seq(0, 23)/12)
# 24 months of data, lets make 20 sets of random data
 testData - matrix(rnorm(480),ncol=20)
# make a zoo object and columns will hold the 20 series
TestZoo  - zoo(testData,order.by=x)
# now run lm for just one series.
 m - lm(TestZoo[,1]~time(TestZoo))$coeff[2]
 m
time(TestZoo)
0.3443124
 m2 - lm(TestZoo[,2]~time(TestZoo))$coeff[2]
 m2
time(TestZoo)
   -0.1192866

I've been struggling trying to use apply ( or something equally suitable) to
get a vector of m for this entire matrix
without resorting to a loop.

[[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] lm() on a matrix of zoo series

2010-12-21 Thread steven mosher
Thanks,

  I was trying apply(TestZoo,2,lm,TestZoo~time(TestZoo))

 which was throwing a formula error.

On Tue, Dec 21, 2010 at 12:21 PM, Gabor Grothendieck 
ggrothendi...@gmail.com wrote:

 On Tue, Dec 21, 2010 at 3:02 PM, steven mosher mosherste...@gmail.com
 wrote:
  I have a matrix of zoo series. each series is in a column.
   x - as.yearmon(2000 + seq(0, 23)/12)
  # 24 months of data, lets make 20 sets of random data
   testData - matrix(rnorm(480),ncol=20)
  # make a zoo object and columns will hold the 20 series
  TestZoo  - zoo(testData,order.by=x)
  # now run lm for just one series.
   m - lm(TestZoo[,1]~time(TestZoo))$coeff[2]
   m
  time(TestZoo)
 0.3443124
   m2 - lm(TestZoo[,2]~time(TestZoo))$coeff[2]
   m2
  time(TestZoo)
-0.1192866
 
  I've been struggling trying to use apply ( or something equally suitable)
 to
  get a vector of m for this entire matrix
  without resorting to a loop.
 

 Try this:

   lm(TestZoo ~ time(TestZoo))


 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com


[[alternative HTML version deleted]]

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


Re: [R] selecting certain rows from data frame

2010-12-14 Thread steven mosher
Hi,
Next time give folks code to produce a toy sample of your problem

 DF -data.frame(ID=rep(1:5,each=3),Data=rnorm(15),Stuff=seq(1:15))
  DF
   ID   Data Stuff
1   1  2.0628225 1
2   1  0.6599165 2
3   1  0.5672595 3
4   2 -0.5308823 4
5   2 -0.5358471 5
6   2 -0.1414992 6
7   3 -0.1679643 7
8   3  0.9220922 8
9   3  0.8863018 9
10  4 -0.725591610
11  4 -1.244675311
12  4  0.816556712
13  5  0.092500813
14  5 -0.853480314
15  5 -0.653501615

# now I want to select rows where ID = 2 or 5
# Assign DF2 to those elements of DF where the ID variable=2 or 5

 DF2 - DF[which(DF$ID==2 | DF$ID==5), ]
 DF2
   ID   Data Stuff
4   2 -0.5308823 4
5   2 -0.5358471 5
6   2 -0.1414992 6
13  5  0.092500813
14  5 -0.853480314
15  5 -0.653501615

On Tue, Dec 14, 2010 at 10:10 PM, Hrithik R rit...@yahoo.com wrote:

 Hi,
 if I have a dataframe such that

 ID Time  Earn
 1110
 1250
 1368
 2140
 2278
 24   88
 3150
 3260
 3398
 4133
 4248
 44   58
 .
 
 .

 Now if I have to select the all the rows from the data frame which does not
 include rows with certain IDs, say for example (prime) ID == 2  3, how do
 I do
 it


 Thanks

 Rith



[[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] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
 I would use RCurl.

 if you have, for example, the url of an ftp site you can merely do a
getURL() and the contents will be returned. That call will return data that
can be coerced into a data.frame that will look like a directory structure
listing the file names.

If you need code just ask, but the RCurl docs are pretty good.



On Tue, Nov 30, 2010 at 8:10 AM, Baoqiang Cao bqcaom...@gmail.com wrote:

 Hi,

 I'd like to download some data files from a remote server, the problem
 here is that some of the files actually don't exist, which I don't
 know before try. Just wondering if a function in R could tell me if a
 file exists on a remote server? I searched this mailing list and after
 read severals mails, still clueless.  Any help will be highly
 appreciated.

 B.C.

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


[[alternative HTML version deleted]]

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


Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
 using RCurl

getFtpList - function(ftp){

# the structure returned is dependent on the ftp site as there are
# various formats for directory listings dependent upon the server
# and the OS. you will need to play with this.
# have a look at the ftp with your browser first and adjust accordingly.
# some formats only return 4 columns.
# column 1= literal string first position mean file
# column 2= number 1
# column 3 =owner
# column 4 = group
# column 5 =file size
# colmn  6 =Month
# column 7 =Day
# column 8 =Time (year)
# column 9 =FileName
#
txt - getURL(ftp)

dir - read.table( textConnection(txt),as.is=TRUE)
out - data.frame(Dir=ftp,Filename=dir[, ncol(dir)],Size=dir[ ,5],
  Month=dir[ ,6],Day=dir[ ,7],Time=dir[
,8],stringsAsFactors=FALSE)
closeAllConnections()
return(out)
}

On Tue, Nov 30, 2010 at 8:10 AM, Baoqiang Cao bqcaom...@gmail.com wrote:

 Hi,

 I'd like to download some data files from a remote server, the problem
 here is that some of the files actually don't exist, which I don't
 know before try. Just wondering if a function in R could tell me if a
 file exists on a remote server? I searched this mailing list and after
 read severals mails, still clueless.  Any help will be highly
 appreciated.

 B.C.

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


[[alternative HTML version deleted]]

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


Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
No problem, you can also  get the directory with a curlOption of dirlistonly

see the example code in the package. This will depend on the version of
libcurl that you have.

If you have an older version, my code will get you the directory.

From the Rcurl examples:

the files within a directory.
url = '
ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/'
filenames = getURL(url, ftp.use.epsv = FALSE, dirlistonly = TRUE)

  # Deal with newlines as \n or \r\n. (BDR)
  # Or alternatively, instruct libcurl to change \n's to \r\n's for us with
crlf = TRUE
  # filenames = getURL(url, ftp.use.epsv = FALSE, ftplistonly = TRUE, crlf =
TRUE)
filenames = paste(url, strsplit(filenames, \r*\n)[[1]], sep = )
con = getCurlHandle( ftp.use.epsv = FALSE)
contents = sapply(filenames[1:5], getURL, curl = con)
names(contents) = filenames[1:length(contents)]


On Tue, Nov 30, 2010 at 9:56 AM, Baoqiang Cao bqcaom...@gmail.com wrote:

 Thanks Steven!
 It is excellent code indeed!

 On Tue, Nov 30, 2010 at 11:26 AM, steven mosher mosherste...@gmail.com
 wrote:
   I would use RCurl.
 
   if you have, for example, the url of an ftp site you can merely do a
  getURL() and the contents will be returned. That call will return data
 that
  can be coerced into a data.frame that will look like a directory
 structure
  listing the file names.
 
  If you need code just ask, but the RCurl docs are pretty good.
 
 
 
  On Tue, Nov 30, 2010 at 8:10 AM, Baoqiang Cao bqcaom...@gmail.com
 wrote:
 
  Hi,
 
  I'd like to download some data files from a remote server, the problem
  here is that some of the files actually don't exist, which I don't
  know before try. Just wondering if a function in R could tell me if a
  file exists on a remote server? I searched this mailing list and after
  read severals mails, still clueless.  Any help will be highly
  appreciated.
 
  B.C.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 


[[alternative HTML version deleted]]

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


Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
here:

getFtpList - function(ftp){
# column 1= literal string first position mean file
# column 2= number 1
 # column 3 =owner
# column 4 = group
# column 5 =file size
 # colmn  6 =Month
# column 7 =Day
# column 8 =Time (year)
 # column 9 =FileName
#
txt - getURL(ftp)

dir - read.table( textConnection(txt),as.is=TRUE)

if(ncol(dir)==9)out - data.frame(Dir=ftp,Filename=dir[,
ncol(dir)],Size=dir[ ,5],
  Month=dir[ ,6],Day=dir[ ,7],Time=dir[
,8],stringsAsFactors=FALSE)
if(ncol(dir)==4)out - data.frame(Dir=ftp,Filename=dir[,
ncol(dir)],Size=dir[ ,3],
  Month=dir[ ,1],Time=dir[ ,2],stringsAsFactors=FALSE)
closeAllConnections()
return(out)
}

On Tue, Nov 30, 2010 at 9:56 AM, Baoqiang Cao bqcaom...@gmail.com wrote:

 Thanks Steven!
 It is excellent code indeed!

 On Tue, Nov 30, 2010 at 11:26 AM, steven mosher mosherste...@gmail.com
 wrote:
   I would use RCurl.
 
   if you have, for example, the url of an ftp site you can merely do a
  getURL() and the contents will be returned. That call will return data
 that
  can be coerced into a data.frame that will look like a directory
 structure
  listing the file names.
 
  If you need code just ask, but the RCurl docs are pretty good.
 
 
 
  On Tue, Nov 30, 2010 at 8:10 AM, Baoqiang Cao bqcaom...@gmail.com
 wrote:
 
  Hi,
 
  I'd like to download some data files from a remote server, the problem
  here is that some of the files actually don't exist, which I don't
  know before try. Just wondering if a function in R could tell me if a
  file exists on a remote server? I searched this mailing list and after
  read severals mails, still clueless.  Any help will be highly
  appreciated.
 
  B.C.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 


[[alternative HTML version deleted]]

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


Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
 study  trycatch()

 also, be awre that even with RCurl, that you may find the file there and
then fail or lose
the connection.

worse still you may get a currupt file on download. So there is a lot of
checking to do
to make bullet proof code that downloads files.





On Tue, Nov 30, 2010 at 3:16 PM, Baoqiang Cao bqcaom...@gmail.com wrote:

 Hi Georg,

 Your code does work, I mean, it doesn't give me any error message,
 which is critical for me because I need use it in a loop and plus I
 don't know how to catch error message. Before your message, I was
 using download.file but the loop was stopped because of the error
 message when a file doesn't exist. So I guess, the option
 method=wget made the difference.

 To summarize (in case it is useful to others), there are (at least)
 two ways to download files:

 1) Georg Ruß:
  v = download.file(url,destf,method=wget)
 if(v!=0) {
 #download.file failed
 }
 #no error message though

 2)

 Henrique Dallazuanna and Steven Mosher both suggested using RCurl,
 here is an example code from Henrique for checking if a file exists on
 a server:
 
 library(RCurl)
 h = basicHeaderGatherer()
 Lines - getURI(http://www.pdb.org/pdb/files/2J0S.1001;,
 headerfunction = h$update)
 h$value()[['status']]

 If the status is 404, then not found. If exists then status should be 200.
 

 What a productive day!

 BC
 On Tue, Nov 30, 2010 at 1:34 PM, Georg Ruß resea...@georgruss.de wrote:
  On 30/11/10 10:10:07, Baoqiang Cao wrote:
  I'd like to download some data files from a remote server, the problem
  here is that some of the files actually don't exist, which I don't
  know before try. Just wondering if a function in R could tell me if a
  file exists on a remote server?
 
  Hi Baoqiang,
 
  try downloading the file with R's download.file() function. Then you
  should examine the returned value.
 
  Citing a part of ?download.file below:
 
  Value:
  An (invisible) integer code, ‘0’ for success and non-zero for
  failure.  For the ‘wget’ and ‘lynx’ methods this is the status
  code returned by the external program.  The ‘internal’ method can
  return ‘1’, but will in most cases throw an error.
 
  So if you call your download via
 
  v - download.file(url, destfile, method=wget)
 
  and v is not equal to zero, then the file is likely to be non-existent
 (at
  least the download failed). Note: the method internal doesn't really
  change the value of v, I just tried that. With wget it returns 0 for
  success and 2048 (or some other value) for non-success.
 
  Regards,
  Georg.
  --
  Research Assistant
  Otto-von-Guericke-Universität Magdeburg
  resea...@georgruss.de
  http://research.georgruss.de
 

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


[[alternative HTML version deleted]]

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


[R] Reverting to previous version

2010-11-12 Thread steven mosher
R 2.12 is not functioning for me On the MAC what the most painless way of
reverting

[[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] spliting first 10 words in a string

2010-11-02 Thread steven mosher
 Thanks david.

  Matevz, maybe I can help explain by doing a very simple and brute force
approach
as opposed to  the way david did it. But you should learn his methods.

I will just do a subset of your problem and if you understand how it works
then you should
be able to get something done and then make it more elegant.

First, I simplify the problem by separating out the sentence column.

You can do this with your data frame by simply doing this

MySentence -data.frame(sentence=yourbigDF$Opis,stringsAsFactors=FALSE)

so I take your original data.frame (yourbigDF) and I just create a copy of
that one column
 $Opis

Later we can merge the two back together after I add 10 columns for the
words


Lets make some dummy data with just 10 rows



 sentence- this is a sentence with ten words or maybe more than ten words
 sentV-rep(sentence,10)
# now I just made 10 rows of the same sentence
# NEXT because I am going to create 10 new colums of 10 rows I create
# 10 vectors each is named and each has 10 elements For the rows.
# they have NO DATA in them

 
first=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=10)

#Next I create a dataframe with Sentence in the first column and 10 blank
colums.
# NOTE I use stringsAsFactors=False

 DF
-data.frame(Sentence=sentence,first,second,third,fourth,fifth,sixth,seventh,eighth,ninth,tenth,stringsAsFactors=FALSE)

# This is what it would look like ( the first row)
DF[1,]

Sentence first second third fourth fifth sixth seventh eighth ninth tenth
1 this is a sentence with ten words or maybe more than ten words FALSE
 FALSE FALSE  FALSE FALSE FALSE   FALSE  FALSE FALSE FALSE

Next, I will show you how to assign the first ten words to the 10 blank
columns

DF[1,2:11]-strsplit(DF[1,1], )[[1]][1:10]

#DF[1,2:11]  selects the columns 2-11 of the first row
#strsplit  returns the first 10 words [1:10] and place them in the
columsn2-11

If you want to do this the slow way you can just loop through your dataframe
row by row
or you can probably use apply.

Make more sense?
 DF[1,2:11]-strsplit(DF[1,1], )[[1]][1:10]
 DF[1,]
Sentence first
second third   fourth fifth sixth seventh eighth ninth tenth
1 this is a sentence with ten words or maybe more than ten words  this
is a sentence  with   ten   words or maybe  more
 DF[1,first]
[1] this

On Tue, Nov 2, 2010 at 12:22 PM, David Winsemius dwinsem...@comcast.netwrote:


 On Nov 2, 2010, at 3:01 PM, Matevž Pavlič wrote:

  Hi all,

 Thanks for all the help. I managed to do it with what Gaj suggested (Excel
 :().

 The last solution from David is also freat i just don't undestand why R
  put the words in 14 columns and thre rows?


 Because the maximum number of words was 14 and the fill argument was TRUE.
 There were three rows because there were three items in the supplied
 character vector.


  I would like it to put just the first 10 words in source field to 10
 diefferent destiantion fields, but the same row. And so on...is that
 possible?


 I don't know what a destination field might be. Those are not R data types.

 This would trim the extra columns (in this example set to those greater
 than 8) by adding a lot of NULL's to the end of a colClasses specification
  at the expense of a warning message which can be ignored:

  read.table(textConnection(words), fill=T, colClasses = c(rep(character,
 8), rep(NULL, 30) ) , stringsAsFactors=FALSE )

   V1V2V3  V4V5V6V7  V8
 1   I  have a columnn  with  text  that has
 2   I would  like  to split these words  in
 3 but  just first ten wordsin   the string.
 Warning message:
 In read.table(textConnection(words), fill = T, colClasses =
 c(rep(character,  :
  cols = 14 != length(data) = 38


 If you want to assign the first column to a variable then just:
  first8 - read.table(textConnection(words), fill=T, colClasses =
 c(rep(character, 8), rep(NULL, 30) ) , stringsAsFactors=FALSE)
  var1 - first8[[1]]
  var1
 [1] I   I   but

 --
 David.



 Thank you, m
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of David Winsemius
 Sent: Tuesday, November 02, 2010 3:47 PM
 To: Gaj Vidmar
 Cc: r-h...@stat.math.ethz.ch
 Subject: Re: [R] spliting first 10 words in a string


 On Nov 2, 2010, at 6:24 AM, Gaj Vidmar wrote:

  Though forbidden in this list, in Excel it's just (literally!)
 five clicks
 away!
 (with the column in question selected)
 Data - Text to Columns - Delimited - tick Space - Finish
 Pa je! (~Voila in Slovenian)
 (then import back to R, keeping only the first 10 columns if so
 desired)


 You could do the same thing without needing to leave R. Just
 read.table( textConnection(..), header=FALSE, fill=TRUE)

  read.table(textConnection(words), fill=T)

   V1V2V3  V4V5V6V7  V8   V9
 V10  V11   V12 V13 V14
 1   I  have a columnn  with  text  that   

Re: [R] splitting First 10 words in a string

2010-11-02 Thread steven mosher
 That's easy you are confusing the dummy code I sent.

 Do this:

 lit-read.csv(litologija.csv, sep=;, dec=.)
sent -data.frame(sentence=lit$Opis,stringsAsFactors=FALSE)
irst=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=nrow(
sent)

I put the length of the vector to 10 just to do a dummy problem.

Then do this:

for(j in 1:nrow(sent) {

  sent[j,2:11]-strsplit(sent[j,1], )[[1]][1:10]

}


That will get you a result the crude brute force way.

try that.

Then you can learn sapply way. but first you need to learn R data
structures.





On Tue, Nov 2, 2010 at 1:47 PM, Matevž Pavlič matevz.pav...@gi-zrmk.siwrote:

 Hi Steven,



 Thank you for the help. I get an error though when i do this :



 lit-read.csv(litologija.csv, sep=;, dec=.)

 sent -data.frame(sentence=lit$Opis,stringsAsFactors=FALSE)

 str(sent)

 sentV-rep(sent,10)

 str(sentV)




 first=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=10)

 DF
 -data.frame(Sentence=sent,first,second,third,fourth,fifth,sixth,seventh,eighth,ninth,tenth,stringsAsFactors=FALSE)



 »Error in data.frame(Sentence = sent, first, second, third, fourth, fifth,
 :

 arguments imply differing number of rows: 22928, 10«



 What am I doing wrong?



 Thnks, m







 *From:* steven mosher [mailto:mosherste...@gmail.com]
 *Sent:* Tuesday, November 02, 2010 8:45 PM
 *To:* David Winsemius
 *Cc:* Matevž Pavlič; Gaj Vidmar; r-h...@stat.math.ethz.ch
 *Subject:* Re: [R] spliting first 10 words in a string



  Thanks david.



   Matevz, maybe I can help explain by doing a very simple and brute force
 approach

 as opposed to  the way david did it. But you should learn his methods.



 I will just do a subset of your problem and if you understand how it works
 then you should

 be able to get something done and then make it more elegant.



 First, I simplify the problem by separating out the sentence column.



 You can do this with your data frame by simply doing this



 MySentence -data.frame(sentence=yourbigDF$Opis,stringsAsFactors=FALSE)



 so I take your original data.frame (yourbigDF) and I just create a copy of
 that one column

  $Opis



 Later we can merge the two back together after I add 10 columns for the
 words





 Lets make some dummy data with just 10 rows







  sentence- this is a sentence with ten words or maybe more than ten
 words

  sentV-rep(sentence,10)

 # now I just made 10 rows of the same sentence

 # NEXT because I am going to create 10 new colums of 10 rows I create

 # 10 vectors each is named and each has 10 elements For the rows.

 # they have NO DATA in them




  
 first=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=10)



 #Next I create a dataframe with Sentence in the first column and 10 blank
 colums.

 # NOTE I use stringsAsFactors=False



  DF
 -data.frame(Sentence=sentence,first,second,third,fourth,fifth,sixth,seventh,eighth,ninth,tenth,stringsAsFactors=FALSE)



 # This is what it would look like ( the first row)

 DF[1,]



 Sentence first second third fourth fifth sixth seventh eighth ninth tenth

 1 this is a sentence with ten words or maybe more than ten words FALSE
  FALSE FALSE  FALSE FALSE FALSE   FALSE  FALSE FALSE FALSE



 Next, I will show you how to assign the first ten words to the 10 blank
 columns



 DF[1,2:11]-strsplit(DF[1,1], )[[1]][1:10]



 #DF[1,2:11]  selects the columns 2-11 of the first row

 #strsplit  returns the first 10 words [1:10] and place them in the
 columsn2-11



 If you want to do this the slow way you can just loop through your
 dataframe row by row

 or you can probably use apply.



 Make more sense?

  DF[1,2:11]-strsplit(DF[1,1], )[[1]][1:10]

  DF[1,]

 Sentence first
 second third   fourth fifth sixth seventh eighth ninth tenth

 1 this is a sentence with ten words or maybe more than ten words  this
 is a sentence  with   ten   words or maybe  more

  DF[1,first]

 [1] this



 On Tue, Nov 2, 2010 at 12:22 PM, David Winsemius dwinsem...@comcast.net
 wrote:


 On Nov 2, 2010, at 3:01 PM, Matevž Pavlič wrote:

 Hi all,

 Thanks for all the help. I managed to do it with what Gaj suggested (Excel
 :().

 The last solution from David is also freat i just don't undestand why R
  put the words in 14 columns and thre rows?



 Because the maximum number of words was 14 and the fill argument was TRUE.
 There were three rows because there were three items in the supplied
 character vector.



 I would like it to put just the first 10 words in source field to 10
 diefferent destiantion fields, but the same row. And so on...is that
 possible?



 I don't know what a destination field might be. Those are not R data types.

 This would trim the extra columns (in this example set to those greater
 than 8) by adding a lot of NULL's to the end of a colClasses specification
  at the expense of a warning message which can be ignored:

  read.table

Re: [R] splitting First 10 words in a string

2010-11-02 Thread steven mosher
Line should be:

first=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=nrow(
sent))

sorry cut and past error

On Tue, Nov 2, 2010 at 3:32 PM, steven mosher mosherste...@gmail.comwrote:

  That's easy you are confusing the dummy code I sent.

  Do this:

  lit-read.csv(litologija.csv, sep=;, dec=.)
 sent -data.frame(sentence=lit$Opis,stringsAsFactors=FALSE)

 first=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=nrow(
 sent)

 I put the length of the vector to 10 just to do a dummy problem.

 Then do this:

 for(j in 1:nrow(sent) {

   sent[j,2:11]-strsplit(sent[j,1], )[[1]][1:10]

 }


 That will get you a result the crude brute force way.

 try that.

 Then you can learn sapply way. but first you need to learn R data
 structures.





 On Tue, Nov 2, 2010 at 1:47 PM, Matevž Pavlič 
 matevz.pav...@gi-zrmk.siwrote:

 Hi Steven,



 Thank you for the help. I get an error though when i do this :



 lit-read.csv(litologija.csv, sep=;, dec=.)

 sent -data.frame(sentence=lit$Opis,stringsAsFactors=FALSE)

 str(sent)

 sentV-rep(sent,10)

 str(sentV)




 first=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=10)

 DF
 -data.frame(Sentence=sent,first,second,third,fourth,fifth,sixth,seventh,eighth,ninth,tenth,stringsAsFactors=FALSE)



 »Error in data.frame(Sentence = sent, first, second, third, fourth,
 fifth,  :

 arguments imply differing number of rows: 22928, 10«



 What am I doing wrong?



 Thnks, m







 *From:* steven mosher [mailto:mosherste...@gmail.com]
 *Sent:* Tuesday, November 02, 2010 8:45 PM
 *To:* David Winsemius
 *Cc:* Matevž Pavlič; Gaj Vidmar; r-h...@stat.math.ethz.ch
 *Subject:* Re: [R] spliting first 10 words in a string



  Thanks david.



   Matevz, maybe I can help explain by doing a very simple and brute force
 approach

 as opposed to  the way david did it. But you should learn his methods.



 I will just do a subset of your problem and if you understand how it works
 then you should

 be able to get something done and then make it more elegant.



 First, I simplify the problem by separating out the sentence column.



 You can do this with your data frame by simply doing this



 MySentence -data.frame(sentence=yourbigDF$Opis,stringsAsFactors=FALSE)



 so I take your original data.frame (yourbigDF) and I just create a copy of
 that one column

  $Opis



 Later we can merge the two back together after I add 10 columns for the
 words





 Lets make some dummy data with just 10 rows







  sentence- this is a sentence with ten words or maybe more than ten
 words

  sentV-rep(sentence,10)

 # now I just made 10 rows of the same sentence

 # NEXT because I am going to create 10 new colums of 10 rows I create

 # 10 vectors each is named and each has 10 elements For the rows.

 # they have NO DATA in them




  
 first=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=10)



 #Next I create a dataframe with Sentence in the first column and 10 blank
 colums.

 # NOTE I use stringsAsFactors=False



  DF
 -data.frame(Sentence=sentence,first,second,third,fourth,fifth,sixth,seventh,eighth,ninth,tenth,stringsAsFactors=FALSE)



 # This is what it would look like ( the first row)

 DF[1,]



 Sentence first second third fourth fifth sixth seventh eighth ninth tenth

 1 this is a sentence with ten words or maybe more than ten words FALSE
  FALSE FALSE  FALSE FALSE FALSE   FALSE  FALSE FALSE FALSE



 Next, I will show you how to assign the first ten words to the 10 blank
 columns



 DF[1,2:11]-strsplit(DF[1,1], )[[1]][1:10]



 #DF[1,2:11]  selects the columns 2-11 of the first row

 #strsplit  returns the first 10 words [1:10] and place them in the
 columsn2-11



 If you want to do this the slow way you can just loop through your
 dataframe row by row

 or you can probably use apply.



 Make more sense?

  DF[1,2:11]-strsplit(DF[1,1], )[[1]][1:10]

  DF[1,]

 Sentence first
 second third   fourth fifth sixth seventh eighth ninth tenth

 1 this is a sentence with ten words or maybe more than ten words  this
 is a sentence  with   ten   words or maybe  more

  DF[1,first]

 [1] this



 On Tue, Nov 2, 2010 at 12:22 PM, David Winsemius dwinsem...@comcast.net
 wrote:


 On Nov 2, 2010, at 3:01 PM, Matevž Pavlič wrote:

 Hi all,

 Thanks for all the help. I managed to do it with what Gaj suggested (Excel
 :().

 The last solution from David is also freat i just don't undestand why R
  put the words in 14 columns and thre rows?



 Because the maximum number of words was 14 and the fill argument was TRUE.
 There were three rows because there were three items in the supplied
 character vector.



 I would like it to put just the first 10 words in source field to 10
 diefferent destiantion fields, but the same row. And so on...is that
 possible?



 I don't know what a destination field might be. Those are not R data

Re: [R] spliting first 10 words in a string

2010-11-02 Thread steven mosher
just merge the data.frames back together.

use merge or cbind()

cbind will be easier

DF1 - data.frame(x,y,z)
DF2 -data.frame(DF1$x) # copy a column
then you added columns to DF2

just put them back together

DF3 -cbind(DF2,DF1$y,DF$z)

if you spend more time with R you will be able to do things like this
elegantly, but for
now This way will work and you will learn a bit about R.

As for counting instances of a string, I might suggest looking at the table
command

k - c( all, but,all)
 table(k)
k
all but
  2   1

So you can do a table for each column in your dataframe

On Tue, Nov 2, 2010 at 12:53 PM, Matevž Pavlič 
matevz.pav...@gi-zrmk.siwrote:

 Hi,

 Ok, i got this now. At least i think so. I got a data.frame with 15 fields,
 all other words have bee truncated. Which is what i want. But ia have that
 in a seperate data.frame from that one it was before (would be nice if it
 would be in the same ...)

 'data.frame':   22801 obs. of  15 variables:
  $ V1 : chr  HUMUS SLABO MALO SLABO ...
  $ V2 : chr  IN GRANULIRAN PREPEREL VEZAN ...
  $ V3 : chr  HUMUSNA PEŠČEN MELJAST ,KONGLOMERAT, ...
  $ V4 : chr  GLINA PROD PROD P0ROZEN, ...
  $ V5 : chr  Z DO DO S ...
  $ V6 : chr  MALO r r PLASTMI ...
  $ V7 : chr  PODA, = = GFs, ...
  $ V8 : chr  LAHKO 8Q 60mm, SIVORJAV ...
  $ V9 : chr  GNETNA, mm, S  ...
  $ V10: chr  RJAVA S PRODNIKI,  ...
  $ V11: chr   PRODNIKI MALO  ...
  $ V12: chr   DO PEŠČEN  ...
  $ V13: chr   R S  ...
  $ V14: chr   = TANKIMI  ...

 Now, i have another problem. Is it possible to count which word occours
 most often each field (V1, V2, V3, ...) and which one is the second and so
 on. Ideally to create a table for each field (V1, V2, V3, ...) with the word
 and thenumber of occuraces in that field (column) .
 I suppose it could be done in SQL, but what since i saw what R can do i
 guess this can be done here to?

 Thanks, m

 -Original Message-
 From: David Winsemius [mailto:dwinsem...@comcast.net]
 Sent: Tuesday, November 02, 2010 8:23 PM
 To: Matevž Pavlič
 Cc: Gaj Vidmar; r-h...@stat.math.ethz.ch
 Subject: Re: [R] spliting first 10 words in a string


 On Nov 2, 2010, at 3:01 PM, Matevž Pavlič wrote:

  Hi all,
 
  Thanks for all the help. I managed to do it with what Gaj suggested
  (Excel :().
 
  The last solution from David is also freat i just don't undestand why
  R  put the words in 14 columns and thre rows?

 Because the maximum number of words was 14 and the fill argument was TRUE.
 There were three rows because there were three items in the supplied
 character vector.

  I would like it to put just the first 10 words in source field to 10
  diefferent destiantion fields, but the same row. And so on...is that
  possible?

 I don't know what a destination field might be. Those are not R data types.

 This would trim the extra columns (in this example set to those greater
 than 8) by adding a lot of NULL's to the end of a colClasses specification
  at the expense of a warning message which can be
 ignored:

   read.table(textConnection(words), fill=T, colClasses =
 c(rep(character, 8), rep(NULL, 30) ) , stringsAsFactors=FALSE )
V1V2V3  V4V5V6V7  V8
 1   I  have a columnn  with  text  that has
 2   I would  like  to split these words  in
 3 but  just first ten wordsin   the string.
 Warning message:
 In read.table(textConnection(words), fill = T, colClasses =
 c(rep(character,  :
   cols = 14 != length(data) = 38


 If you want to assign the first column to a variable then just:
   first8 - read.table(textConnection(words), fill=T, colClasses =
 c(rep(character, 8), rep(NULL, 30) ) , stringsAsFactors=FALSE)   var1
 - first8[[1]]   var1
 [1] I   I   but

 --
 David.

 
  Thank you, m
  -Original Message-
  From: r-help-boun...@r-project.org
  [mailto:r-help-boun...@r-project.org
  ] On Behalf Of David Winsemius
  Sent: Tuesday, November 02, 2010 3:47 PM
  To: Gaj Vidmar
  Cc: r-h...@stat.math.ethz.ch
  Subject: Re: [R] spliting first 10 words in a string
 
 
  On Nov 2, 2010, at 6:24 AM, Gaj Vidmar wrote:
 
  Though forbidden in this list, in Excel it's just (literally!) five
  clicks away!
  (with the column in question selected) Data - Text to Columns -
  Delimited - tick Space - Finish Pa je! (~Voila in Slovenian) (then
  import back to R, keeping only the first 10 columns if so
  desired)
 
  You could do the same thing without needing to leave R. Just
  read.table( textConnection(..), header=FALSE, fill=TRUE)
 
  read.table(textConnection(words), fill=T)
 V1V2V3  V4V5V6V7  V8   V9
  V10  V11   V12 V13 V14
  1   I  have a columnn  with  text  that hasquite
  a  few words  in it.
  2   I would  like  to split these words  in separate columns
  3 but  just first ten wordsin   the string.   Isthat
  possiblein  R?
 
 
  Regards,
  Assist. Prof. Gaj Vidmar, PhD
  University Rehabilitattion Institute, Republic 

[R] Strings from different locale

2010-11-01 Thread steven mosher
I'm doing some test processing of a cvs file that appears to use a different
locale
from my machine.

I get the following warning:

 input string 1 is invalid in this locale

My locale is US. Is this simply a matter of changing my locale to 'all;
locales?

I don't know what locale the string is in, is there a way to detect this or
translate

[[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] doubt in climate variability analysis in R! - code

2010-10-31 Thread steven mosher
Ok I downloaded it and showed you how to get your data out. How to read it
into a raster brick,
how to plot the data, how to get the mean rainfall of every day.lots more
you can do.

there is a  bad bit of data in the last time step.

check my blog.

In the future what you should do is write code to emulate your problem. for
example, in your problem you had created a ncdf file with a 3D matrix of
65,69,2192.
You should just do a subset of that, show the code to create a ncdf with
random numbers in it.

creating working code that emulates your problem is key if you want help.

Off list for the rest.

On Sun, Oct 31, 2010 at 10:21 AM, govin...@msu.edu wrote:



 I am sorry, i think the link was broken..! here is the correct one!!!

 http://www.4shared.com/file/4zV0g3JR/RF_80-85.html


[[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] Reading in a tab delimitated file

2010-10-27 Thread steven mosher
if your data for the rest of the file looks like this then  read.fwf will
work.
depending which vars you want to pull)

widths= c(18,32,41)

E-CBIL-28-raw-cel-1435145228.cel1

would pull 3 vars, E-CBIL-28-raw-cel-; 1435145228.cel;1

widths -c(32,41)
E-CBIL-28-raw-cel-1435145228.cel;1


you can set it differently, assign colnames and column classes as well

But the feilds must be fixed width.





On Tue, Oct 26, 2010 at 5:35 AM, amindlessbrain
jillianrowe91...@gmail.comwrote:


 Hi all,

 I have a total newbie question, but I could really use some help.

 I need to read in this file:

 SampleIDDisease
 E-CBIL-28-raw-cel-1435145228.cel1
 E-CBIL-28-raw-cel-1435145451.cel2
 E-CBIL-28-raw-cel-1435145479.cel2
 E-CBIL-28-raw-cel-1435145132.cel3
 E-CBIL-28-raw-cel-1435145417.cel3
 E-CBIL-28-raw-cel-1435145301.cel2
 E-CBIL-28-raw-cel-1435145558.cel1
 E-CBIL-28-raw-cel-1435145073.cel3
 E-CBIL-28-raw-cel-1435145196.cel2
 E-CBIL-28-raw-cel-1435145511.cel1
 E-CBIL-28-raw-cel-1435145336.cel3
 E-CBIL-28-raw-cel-1435145260.cel2
 E-CBIL-28-raw-cel-1435145167.cel2
 E-CBIL-28-raw-cel-1435145387.cel3
 E-CBIL-28-raw-cel-1435145099.cel3

 (I'm not sure why the disease column isn't showing up as a tab here, but it
 is sep by \t in my file.

 I've tried several variations on these:

 pd - read.AnnotatedDataFrame (new_treat.txt , header = TRUE ,  sep=\t,
 row.names = SampleID, colClasses = c(Disease = character))

 And I keep on getting this error:

 Error in read.table(filename, sep = sep, header = header, quote = quote,  :
  more columns than column names

 Any help would be very very very appreciated!

 Thanks!



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Reading-in-a-tab-delimitated-file-tp3013620p3013620.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] Best IDE for R

2010-10-27 Thread steven mosher
Thanks for the pointer,

After looking at the many folders of R code I have I decided it was time to
start working in an IDE and also getting my stuff under version control (
for my own sanity)

I'll have a look at Geany.. for version control.. not so sure.

On Wed, Oct 27, 2010 at 12:14 PM, Liviu Andronic landronim...@gmail.comwrote:

 On Wed, Oct 27, 2010 at 9:05 PM, Jonathan P Daily jda...@usgs.gov wrote:
  I can second using Geany as an IDE.
 
 Great, finally a soulmate! :) More seriously, I think Geany is
 under-appreciated and virtually unkonwn in the R community.


  Another large plus for it is that it is cross platform (I work in both
 Windows and Linux), cross environment (I also code in Python/Sage), very
 customizable, and even has a version on PortableApps for windows so you can
 take a customized version around on a USB stick with ease.
 
 One important feature that teh Windows version of Geany lacks is the
 integrated virtual terminal emulator. This is mainly because the VTE
 port to Windows was never finalised (although the patch is well in
 their bugtracker). One possibility is to use Geany in a VMware virtual
 Linux machine on Windows.

 Regards
 Liviu


  --
  Jonathan P. Daily
  Technician - USGS Leetown Science Center
  11649 Leetown Road
  Kearneysville WV, 25430
  (304) 724-4480
  Is the room still a room when its empty? Does the room,
  the thing itself have purpose? Or do we, what's the word... imbue it.
  - Jubal Early, Firefly
 
 
  From: Liviu Andronic landronim...@gmail.com
  To:
  Lee Hachadoorian 
  lee.hachadooria...@gmail.comlee.hachadoorian%...@gmail.com
 
  Cc: r-h...@stat.math.ethz.ch
  Date: 10/27/2010 02:45 PM
  Subject: Re: [R] Best IDE for R
  Sent by: r-help-boun...@r-project.org
  
 
 
  On Wed, Oct 27, 2010 at 4:05 PM, Lee Hachadoorian
  lee.hachadooria...@gmail.com lee.hachadoorian%...@gmail.com wrote:
   For an R-enabled text editor, I would suggest Tinn-R for Windows or
 RGedit
   (a gedit plugin) for Linux/Gnome-desktop. Since both are just text
   editors, they will work with whatever version R you have installed
   (criteria 1).
  
   RGedit is pretty spare: basically just console integration and keyboard
   shortcuts to send code (current line, selection, defined blocks) to the
   console. Criteria 1 Y 2 basic 3 N 4 N
  
  For Linux and Mac, I usually suggest Geany [1] as an alternative to
  Gedit. Geany is an intuitive IDE that can send commands to rterm in
  the integrated virtual terminal emulator. It provides various features
  for project management, source highlighting, code folding, etc.
 
  Regards
  Liviu
 
  [1] http://www.r-bloggers.com/integrating-r-with-geany/
 
  __
  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.
 
 



 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mailhttp://garbl.home.comcast.net/%7Egarbl/stylemanual/e.htm#e-mail

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


[[alternative HTML version deleted]]

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


[R] Overlaying two png?

2010-10-15 Thread steven mosher
I have a program that creates a Png file using Rgooglemap with an extent
(lonmin,lonmax,latmin,latmax)
I also have a contour plot of the same location, same extent, same sized
(height/width) png file.

I'm looking for a way to make the contour semi transparent and overlay it on
the google map ( hybrid map)

Since I have 7000 of these to do an automated process is desired ( grin)

Any pointers in the right direction ?

[[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] Beginner question on bar plot

2010-10-15 Thread steven mosher
I've read a number of examples on doing a multiple bar plot, but cant seem
to grasp
how they work or how to get my data into the proper form.

I have two  variable holding the same factor

The variables were created using a cut command, The following simulates that

A - 1:100
B - 1:100
 A[30:60] - 43
 Acut - cut(A,breaks=c(0,10,45,120),labels=c(low,med,high))
 Bcut - cut(B,breaks=c(0,10,45,120),labels=c(low,med,high))

What I want to do is create a barplot with  3 groups of side by side bars

group 1, = low and the two bars would be the count for Acut, and the count
for Bcut
group 2 = med and the two bars again would be the counts for  this factor
level in Acut and Bcut
group 3 = high  and like the above two.

[[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] Read from a website

2010-10-12 Thread steven mosher
Hmm,

RCurl might have something on this.

otherwise pull you can figure out their scheme and just construct the url
from scratch.

when you finish filling in the form, look at the url they construct. do it a
few times
and you can just emulate that. I've done that in the past without problems.
depends on the site.


On Tue, Oct 12, 2010 at 2:32 AM, Santosh Srinivas 
santosh.srini...@gmail.com wrote:

 Something similar to this was discussed recently, but I'm unable to find
 the
 thread.



 I want to read from a site where I need to enter the date into a form
 before
 I am presented with the CSV link. E.g. like reading ticker data from yahoo
 (but assuming you HAVE to enter the dates and click on request).



 How do I simulate this from R?



 Thanks for the help.




[[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


[R] Loss of precision in read.csv.

2010-10-09 Thread steven mosher
Given a csv file from this location

Airports-http://www.ourairports.com/data/airports.csv;

download.file(Airports,basename(Airports))


airports -read.csv(airports.csv,encoding=UTF-8)

 airports[1,]

id ident type  name latitude_deg longitude_deg
elevation_ft continent iso_country iso_region municipality scheduled_service

1 6523   00A heliport Total Rf Heliport  *40.0708  -74.9336 *
  11  NA  US  US-PA Bensalemno

  gps_code iata_code local_code home_link wikipedia_link keywords

1  00A  00A


And the precision is lost which we can show by using readLines:


fred-readLines(airports.csv)

 fred[2]
[1] 6523,\00A\,\heliport\,\Total Rf Heliport\,*
40.07080078125,-74.9336013793945*
,11,\NA\,\US\,\US-PA\,\Bensalem\,\no\,\00A\,,\00A\,,,


I tried various approaches, using colClasses, switching to read.tables,
specifying dec=.


I tested read.csv and it does preserve precision on my test case, but not on
this data.


Ideas?

[[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] Loss of precision in read.csv.

2010-10-09 Thread steven mosher
Ha Thanks,

  That was it.

On Sat, Oct 9, 2010 at 2:38 PM, Joshua Wiley jwiley.ps...@gmail.com wrote:

 Hi Steven,

 As near as I can tell, no precision is lost.  R is just being
 courteous and not excessively filling our consoles.  Try:

 print(airports[1,latitude_deg], digits = 22)

 which is the most digits R will print (although internally it can
 store more I believe).

 Alternately, you can convert it to character class:

 as.character(airports[1, ])

 So in short, this is just a cosmetic feature of presenting the data,
 not its actual storage.

 Cheers,

 Josh

 On Sat, Oct 9, 2010 at 1:33 PM, steven mosher mosherste...@gmail.com
 wrote:
  Given a csv file from this location
 
  Airports-http://www.ourairports.com/data/airports.csv;
 
  download.file(Airports,basename(Airports))
 
 
  airports -read.csv(airports.csv,encoding=UTF-8)
 
  airports[1,]
 
 id ident type  name latitude_deg longitude_deg
  elevation_ft continent iso_country iso_region municipality
 scheduled_service
 
  1 6523   00A heliport Total Rf Heliport  *40.0708  -74.9336 *
   11  NA  US  US-PA Bensalemno
 
   gps_code iata_code local_code home_link wikipedia_link keywords
 
  1  00A  00A
 
 
  And the precision is lost which we can show by using readLines:
 
 
  fred-readLines(airports.csv)
 
  fred[2]
  [1] 6523,\00A\,\heliport\,\Total Rf Heliport\,*
  40.07080078125,-74.9336013793945*
  ,11,\NA\,\US\,\US-PA\,\Bensalem\,\no\,\00A\,,\00A\,,,
 
 
  I tried various approaches, using colClasses, switching to read.tables,
  specifying dec=.
 
 
  I tested read.csv and it does preserve precision on my test case, but not
 on
  this data.
 
 
  Ideas?
 
 [[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.
 



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/


[[alternative HTML version deleted]]

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


Re: [R] RE : R getting slower until it breaks...

2010-10-06 Thread steven mosher
I know its no consolation, but I have a similar issue with R on a MAC, also
ploting
out large numbers of raster layers.  sometimes the problem lingers even
after I clear the workspace, do gc() etc.  Almost as if R wont ask for
processor resources.

weird.

On Wed, Oct 6, 2010 at 12:06 PM, Bastien Ferland-Raymond 
bastien.ferland-raymon...@ulaval.ca wrote:

 Thanks a lot for your quick answer.  Here is my answer to your questions:

 Have you looked to see how fast your memory might be growing?
 BFR- Yes I did, it's not to bad, it's starts around 60 000ko, rise up to
 120 000 at the most, so not too scary.

 Are you leaving around any large objects that should be removed?
 BFR- I was carefull making sure the function doesn't create anything that
 would be visible with objects().  Could it be creating other type (hidden)
 objects?  Maybe, but I'm not very familliar with that stuff.

 Have you looked to see if you are paging?
 BFR- I just red the wiki about paging, didn't know that term before.  If I
 look at perfmon, its looks like keeping steady at 6000 pages/s with rare
 peaks as high as 900 000. Does it sounds normal?  How can it affect R?

 Is it your CPU time that is increasing, or your wall clock time?
 BFR- If I go to the task manager - performance.  R is initially using
 around 40% of the processor (so around 80% of 1 core) but with (real) time
 passing, it gets lower and lower to get as low as 6% (12% of one core).  I
 was surprized to see that as usually my simulation in R use one whole core.

 It sounds like there might be some memory leak that might be causing your
 process size to grow and possibly causing paging.  You will need to gather
 some of the performance data that perfmon can provide and look at the memory
 usage, CPU time and I/O rates over time to see if there are any changes.
 BFR- The term Memory leak feels right with my problem.  Is there ways I
 can control/detect/prevent this kind of problem in R.  Also, how can I check
 the I/O, i never looked at that before.

 Thanks again

 Bastien



 On Wed, Oct 6, 2010 at 2:11 PM, Bastien Ferland-Raymond
 bastien.ferland-raymon...@ulaval.ca wrote:
  Hello R-users,
 
  I'm currently facing a pretty hard problem which I'm hopping you'll be
 able to help me with.  I'm using R to create images.  That alone is not the
 problem, the problem is that I'm using R to create 168 000 images...  My
 code (which is given below) use different package (raster and rgdal) to
 import a image (size 20gig) and divide it into 168 000 pictures that are 100
 pixel x 100 pixel.  The code works fine for making the images, but if I ask
 it to run all 168 000, it always breaks around 15 000.
 
  It starts with the code being able to make around 2 pictures per second,
 but then it slows down and after around 2000 pictures it's only 1 picture
 per second.  Later on it's getting closer to 1 pictures every 3 seconds etc.
  until it bugs.  I have no error message, only Windows that tells me that R
 encounter a problem and most be close...  Initially I though it was a
 Windows problem, that I couldn't put too many file into a folder and it was
 slowering it down.  Then I divided my batch process into smaller (5000
 files) folder but it didn't help, still breaks at 15 000.  I also try to do
 gc() after each 5000 pictures to save memory but it didn't help either.  I
 removed every loops from the code because I thought it was the problem, but
 it was just faster at bugging... After the bug, I need to restart the
 computer if I want to go back to the initial speed.
 
  I'm pretty much running out of options.  It's there limitation in R as
 the number of files it can create in one session?  Is it a windows problem?
  Is there better way to clear the memory than gc()? Any thought on that?
 
  I'm using R 2.11.1, win XP, my hard drive is NTSF, computer: intel core2
 duo E6750 32 bit with 2 gig of Ram.
 
  Here is my code, but I doubt it would help much with my problem:
 
  
  # It made of 4 functions (sorry, it's french):
 
 
 ##
 
 ##
  ###  Ensemble des fonctions pour faire les images NDVI rouge et verte
  ###
 
 ##
  ##  Bastien Ferland-Raymond, 5 oct 2010
  #
 
 ##
 
  
  ## Simplement rouler le script au complet
  
  ### Library nécessaire:
  library(raster)
  library(rgdal)
  library(shapefiles)
 
 
 #
  ## Fonction 1  -  NDVI a partir de coordonnee Pixel et largeur #
   calculate_NDVI- function(Type, object, VALUE) {
redorgreen - ifelse(Type==red,2,3)
list1 - unstack(object)
rast1 - list1[[1]]
rast2 - list1[[redorgreen]]
NAvalue(rast1)- 

Re: [R] RE : R getting slower until it breaks...

2010-10-06 Thread steven mosher
Thanks,

 haven't used valgrind in years, this should be fun.

Steve

On Wed, Oct 6, 2010 at 1:55 PM, Ben Bolker bbol...@gmail.com wrote:

 steven mosher moshersteven at gmail.com writes:

 
  I know its no consolation, but I have a similar issue with R on a MAC,
 also
  ploting
  out large numbers of raster layers.  sometimes the problem lingers even
  after I clear the workspace, do gc() etc.  Almost as if R wont ask for
  processor resources.
 

   If it is a memory leak, it might be worth reading up on the use of
 valgrind (section 4.3.2 in the 'R extensions' manual).  The information
 provided by valgrind might not be immediately interpretable, but it could
 help others track down a problem ...

 __
 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] Script auto-detecting its own path

2010-10-04 Thread steven mosher
  in the package R.utils

  getAbsolutePath()

  or you can do a file.list(.. full.names=TRUE,
recursive=TRUE,pattern=(.R))

 the rest will require grep and pulling the file name and directory path
apart

 If its not evident just ask and I'll write something for you.

 basically you want a call that returns the full path of a R script?





On Mon, Oct 4, 2010 at 12:13 PM, Hadley Wickham had...@rice.edu wrote:

  I'm not sure this will solve the issue because if I move the script, I
 would
  still have to go into the script and edit the /path/to/my/script.r, or
 do
  I misunderstand your workaround?
  I'm looking for something like:
  file.path.is.here(myscript.r)
  and which would return something like:
  [1] c:/user/Desktop/
  so that regardless of where the script is, as long as the accompanying
  scripts are in the same directory, they can be easily sourced with
 something
  like:
  dirX - file.path.is.here(MasterScript.r)
  source(paste(dirX, AuxillaryFile.r, sep=))

 If you use relative paths like so:

 # master.r
 source(AuxillaryFile.r)

 Then source(path/to/master.r, chdir = T) will work.  Mastering
 working directories is a much better idea than coming up with your own
 workarounds.

 Hadley

 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/

 __
 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] get absolute file path

2010-09-26 Thread steven mosher
The package R.utils has a function to get absolutepath

On Sun, Sep 26, 2010 at 1:00 AM, Sebastian Gibb li...@sebastiangibb.dewrote:

 Hello,

 I get a value which stores a relative file name. (I get it from another
 function, which I don't want to change.)
 e.g.
  fileName - ../data/2010-08.csv;

 Is it possible to get the absolute file path out of this value?
 (e.g. /home/sebastian/documents/data/2010-08.csv)

 Kind regards,

 Sebastian

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


[[alternative HTML version deleted]]

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


[R] diagnosing download.file() problems

2010-09-21 Thread steven mosher
I'm accessing around 95 tar files on an FTP server ranging in size between
10 and 40MB a piece.

while certainly can click on them and download them outside of R, I'd like
to have my script do it.

Retrieving the ftp directory with RCurl works fine (about 90% of the time)

but downloading the files by looping through all the files is a random
process.

I may get 1-8 files download and then it throws an error

cannot open URL 

sometimes I only can get 1 file before this error. with tryCatch() I've been
able to do some clean up
after the crash, but automating this whole download process has turned into
a bit of a circus.

The parameters (url, destfile, mode) are all correct in the download.file
call as the second attempt at a url will often succeed.

Is there anyway to get a deeper look at the cause of the problem? I've tried
closing all connections
in between each download. any pointers would be welcomed.

[[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] diagnosing download.file() problems

2010-09-21 Thread steven mosher
That is what I feared. I know other people on slow connections have done
this without issue ( at least they didnt report an issue ) I had a similar
issue with geonames.org  who at least published their terms
of service (requests per second or sumptin like that.. so  could program
around it) I'll hunt around
on their ftp and then write the admin a note.. i really don't want to brute
force the matter

 it's government data made available for the public so I expect the admin
will be helpful.

 Thanks for confirming what I suspected, for a minute [ .ed: for two days] I
thought I had taken crazy pills.

 i did note, however, some odd behavior with tryCatch, where statements
after the finally={} were executed. Not sure if that deserves a bug report.

On Tue, Sep 21, 2010 at 2:33 AM, Barry Rowlingson 
b.rowling...@lancaster.ac.uk wrote:

 On Tue, Sep 21, 2010 at 9:39 AM, steven mosher mosherste...@gmail.com
 wrote:
  I'm accessing around 95 tar files on an FTP server ranging in size
 between
  10 and 40MB a piece.
 
  while certainly can click on them and download them outside of R, I'd
 like
  to have my script do it.
 
  Retrieving the ftp directory with RCurl works fine (about 90% of the
 time)
 
  but downloading the files by looping through all the files is a random
  process.
 
  I may get 1-8 files download and then it throws an error
 
  cannot open URL 
 
  sometimes I only can get 1 file before this error. with tryCatch() I've
 been
  able to do some clean up
  after the crash, but automating this whole download process has turned
 into
  a bit of a circus.
 
  The parameters (url, destfile, mode) are all correct in the download.file
  call as the second attempt at a url will often succeed.
 
  Is there anyway to get a deeper look at the cause of the problem? I've
 tried
  closing all connections
  in between each download. any pointers would be welcomed.

 Sounds to me like the FTP server is operating some kind of rate
 limiting. Do you have access to the server log files, or the server
 administrator, or perhaps the server's terms and conditions to see if
 its so :)

 Barry


[[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] Substitute NAs by zero

2010-09-20 Thread steven mosher
 v-c(1,2,3,4,5,6,7,8,97,6,5,4,NA,NA)

 b-zoo(v)
 b
 1  2  3  4  5  6  7  8  9 10 11 12 13 14
 1  2  3  4  5  6  7  8 97  6  5  4 NA NA
 b[is.na(b)]-0
 b
 1  2  3  4  5  6  7  8  9 10 11 12 13 14
 1  2  3  4  5  6  7  8 97  6  5  4  0  0
 is.zoo(b)
[1] TRUE


On Mon, Sep 20, 2010 at 2:37 AM, skan juanp...@gmail.com wrote:


 Hello

 How can I substitute all NA values by zero in a R zoo series?
 I've been reading about na.locf and na.omit  but I think none of them do
 what I need.

 thanks.
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Substitute-NAs-by-zero-tp2546715p2546715.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


Re: [R] How to uncompress a gz file in R

2010-09-16 Thread steven mosher
you are welcome. Henrik's package  is an great piece of work. It is worth
the time to read through the whole thing and see how you can improve your
programs by using other features as well.

On Thu, Sep 16, 2010 at 2:16 AM, Wonsang You y...@ifn-magdeburg.de wrote:

 Dear Henrik and Steven,

 Thank you for your kind help and guidance even though it is a basic
 question. I misunderstood that gunzip is a part of not R.utils but
 utils. I could find out the function in R.utils. Then, it was successful
 to decompress any gz file as follows.

 library(R.utils)
 gunzip(foo.gz)

 Best Regards,
 Wonsang



[[alternative HTML version deleted]]

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


Re: [R] How to uncompress a gz file in R

2010-09-15 Thread steven mosher
 Wongsang,

 Just to be clear  R.utils is different than utils

 As Henrik notes gunzip has been in R.utils ( see http://cran.r-project.org/)
for some time. It works
like a champ. R.utils is a great package.

On Wed, Sep 15, 2010 at 9:30 AM, Wonsang You y...@ifn-magdeburg.de wrote:

 Dear Henrik,

 Thank you so much for your kind help. Unfortunately, I could not find out
 any function such as 'gunzip' in R.utils package. Instead, I could be
 successful by using the following command.

 system(gunzip filename)

 On the other hand, the function 'gzfile' supports the compression as gz
 format, but I still do not know how to decompress gz file by using the
 function 'gzfile'.

 Best Regards,
 Wonsang


 On 14 September 2010 15:23, Henrik Bengtsson h...@stat.berkeley.edu wrote:

  To uncompress an *.gz file into another file on disk, see also ?gunzip
  in the R.utils package.
 
  /Henrik
 
  2010/9/14 Uwe Ligges lig...@statistik.tu-dortmund.de:
   See ?gzfile
  
   Uwe Ligges
  
  
   On 14.09.2010 11:02, Wonsang You wrote:
  
   Dear Fellows,
  
   I would like to know how to uncompress a gz file at the R console. I
  could
   not find out any help from the R-help archive.
   Thanks for your great help.
  
   Best Regards,
   Wonsang You
  
  
   -
   --
   Wonsang You
   Special Lab Non-Invasive Brain Imaging
   Leibniz Institute for Neurobiology
   http://www.ifn-magdeburg.de
  
   __
   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.


[[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] Get File Names in Folder, Read Files, Update, and Write

2010-09-15 Thread steven mosher
you are welcomed.

Steve

On Wed, Sep 15, 2010 at 6:11 PM, Suphajak Ngamlak 
supha...@phatrasecurities.com wrote:

  Thank you so much. It works well



 Best Regards,

 Suphajak Ngamlak
 Equity and Derivatives Trading
 Phatra Securities Public Company Limited
 Tel: +662-305-9179
 Email: supha...@phatrasecurities.com

 *From:* steven mosher [mailto:mosherste...@gmail.com]
 *Sent:* Thursday, September 16, 2010 2:29 AM
 *To:* Suphajak Ngamlak
 *Subject:* Re: [R] Get File Names in Folder, Read Files, Update, and Write




 Import-C:/A0810.RSK

 Table-read.table(file= Import, sep = ,, head=TRUE, na.strings = NA)

 Table$VALUE -0

 Export-C:/A_XVal0810.RSK

 write.table(Table, file= Export, sep = ,, col.names = TRUE)


 As uwe, suggests list.files() or you can use dir()

 A robust way to do this would use R.utils package ( see Cran)
 but this is only necessary if you want to move the folder and still
 have the code work. it makes the code work regardless of your working
 directory

 assuming you know the name of the folder and its unique.

 insertString   - _XVal
 targetFolder  - yourfoldername



  folderPath  -  getAbsolutePath(targetFolder) #see R.utils
  outputFolder -  folderpath  # you could create a different output folder
 name

 # only grab the .RSK files using a regular expression

 fullFilenames -  list.files(path=folderPath,
 full.names=TRUE,pattern=(.RSK))

 # get only the file names for modification
 filenames   -  list.files(path=folderPath,
 full.names=FALSE,pattern=(.RSK))

 for(filenumber in 1:length(fullFilenames)) {
  Table-read.table(file= fullFilenames[filenumber], sep = ,,
  head=TRUE, na.strings = NA)
  Table$VALUE -0
  outfileName   -  paste(substr(filenames[filenumber]1,1),
   insertString,

 substr(filenames[filenumber],2,nchar(filenames[filenumber]),
   sep=)
  outFilePath
 -file.path(outputFolder,outfileName,fsep=.Platform$file.sep)
  write.table(Table, file= outFilePath, sep = ,, col.names = TRUE)

 }



  On Wed, Sep 15, 2010 at 1:55 AM, Suphajak Ngamlak 
 supha...@phatrasecurities.com wrote:

 Dear All,



 Could you please recommend how I can do this?



 I have several text files in one folder. Let's name them A0801.RSK,
 A0802.RSK, 

 I would like R to

 1)  Know all file names in this folder

 2)  Update value in one column of these files

 3)  Write results in another text file with _xval in the file names



 Below is R code for read, update, and write one file



 Import-C:/A0810.RSK

 Table-read.table(file= Import, sep = ,, head=TRUE, na.strings = NA)

 Table$VALUE -0

 Export-C:/A_XVal0810.RSK

 write.table(Table, file= Export, sep = ,, col.names = TRUE)



 Thank you

 Best Regards,

 Suphajak Ngamlak
 Equity and Derivatives Trading
 Phatra Securities Public Company Limited
 Tel: +662-305-9179
 Email: supha...@phatrasecurities.com


[[alternative HTML version deleted]]

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




[[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] If then else with command for

2010-09-14 Thread steven mosher
not sure how you wanted sampling of x


 R-142

color-rep(0,142)

for(i in 1:R){

y-sample(x,142,replace=FALSE)

onebit- as.numeric(3471 %in% y)

twobit-as.numeric(6720 %in% y)*2

fourbit-as.numeric(6263 %in% y)*4

colorbit-onebit+twobit+fourbit+1

color[i]-colorbit

}

On Tue, Sep 14, 2010 at 10:29 AM, Mestat mes...@pop.com.br wrote:


 Hey listers,
 I am trying to do something simple... Check the program below...
 I would like to create a variable named COLOR according to the conditions
 that I stablished... But the problem is that it seems that my variable
 COLOR
 is checking just on sample, may be last in the loop... Certainly, I am
 missing something...
 Thanks in advance,
 Marcio


 x-c(288,139,196,159,536,134,623,517,96,467,277,155,386,241,422,6263,612,532,250,412,339,55,290,249,164,97,74,144,1277,240,163,63,488,111,128,230,720,179,37,24,65,37,89,187,60,939,1008,81,310,58,169,38,68,190,78,807,220,226,69,179129,119,73,59,92,127,104,75,505,183,49,41,76,113,90,79,408,140,200,284,103,58,654,118,431,192,233,102,97,56,69,73,86,53,105,81,77,472,129,194,299,81,122,113,186,91,145,133,114,78,78,72,70,3471,641,275,815,149,185,172,240,67,526,122,229,298,317,179,233,66,129,87,82,63,65,72,6720,381,240,118,396,66,35,43,166,216,53,82,90,62,77,207,68,52,277,396,220,751,146,95,37,35,39,46,59,44,105,87,66,62,175,252,128,330,57,83,208,74,63,109,37,105,38,82,76,63,86,603,209,100,121,191,130,63,128,90,79,50,1025,121,87,309,75,189,36,82,84,60,132,46,965,155,132,219,112,53,90,66,100,77,52,60,100,153,418,392,76,130,197,262,49,105,87,70,147,720,342,233,203,249,92,134,231,782,184,182,432,49,63,94,124,69,53,91,451,53,21,42,50,40,32,58,26,28,61,60,35,764,105,592,55,28,46,34,123!
 ,4!
  1,54,207,64,562,295,226,63,233)
 R-142
 color-rep(0,142)
 for(i in 1:R){
 x-sample(x,142,replace=FALSE)
 if (!3471 %in% x  !6263 %in% x  !6720 %in% x){color[i]-1} else
 if (3471 %in% x  !6263 %in% x  !6720 %in% x){color[i]-2} else
 if (!3471 %in% x  6263 %in% x  !6720 %in% x){color[i]-3} else
 if (!3471 %in% x  !6263 %in% x  6720 %in% x){color[i]-4} else
 if (3471 %in% x  6263 %in% x  !6720 %in% x){color[i]-5} else
 if (3471 %in% x  !6263 %in% x  6720 %in% x){color[i]-6} else
 if (!3471 %in% x  6263 %in% x  6720 %in% x){color[i]-7} else
 if (3471 %in% x  6263 %in% x  6720 %in% x){color[i]-8} else{color[i]-0}
 }

 --
 View this message in context:
 http://r.789695.n4.nabble.com/If-then-else-with-command-for-tp2539341p2539341.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[alternative HTML version deleted]]

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


[R] merging two maxtrices

2010-09-05 Thread steven mosher
  j-matrix(nrow=10,ncol=10)
  k-matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
  j
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [2,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [4,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [6,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [8,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
[10,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  k
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
2 16   11   16   21   26   31   36   4146
4 27   12   17   22   27   32   37   4247
6 38   13   18   23   28   33   38   4348
8 49   14   19   24   29   34   39   4449
105   10   15   20   25   30   35   40   4550

is there a simple way to merge j and k By the row.names in k

so that row named '2' is placed in the 2nd row of j.. and so forth through
4,6,8,10

the actual example has a sparse k.. not evenly spaced

so this should also be mergeable

 row.names(k) - c(1,2,5,6,9)
 k
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
116   11   16   21   26   31   36   4146
227   12   17   22   27   32   37   4247
538   13   18   23   28   33   38   4348
649   14   19   24   29   34   39   4449
95   10   15   20   25   30   35   40   4550

[[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] merging two maxtrices

2010-09-05 Thread steven mosher
weird, I tried that but it didnt appear to work.. hmm. Thanks I try it again

On Sun, Sep 5, 2010 at 12:21 AM, bill.venab...@csiro.au wrote:

 Is this all you want?

  j - matrix(nrow=10,ncol=10)
  k - matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
 
  row.names(j) - 1:10
  j[row.names(k), ] - k
 
  j
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 1NA   NA   NA   NA   NA   NA   NA   NA   NANA
 2 16   11   16   21   26   31   36   4146
 3NA   NA   NA   NA   NA   NA   NA   NA   NANA
 4 27   12   17   22   27   32   37   4247
 5NA   NA   NA   NA   NA   NA   NA   NA   NANA
 6 38   13   18   23   28   33   38   4348
 7NA   NA   NA   NA   NA   NA   NA   NA   NANA
 8 49   14   19   24   29   34   39   4449
 9NA   NA   NA   NA   NA   NA   NA   NA   NANA
 105   10   15   20   25   30   35   40   4550
 



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of steven mosher
 Sent: Sunday, 5 September 2010 5:10 PM
 To: r-help
 Subject: [R] merging two maxtrices

  j-matrix(nrow=10,ncol=10)
  k-matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
  j
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [2,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [4,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [6,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [8,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [10,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  k
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 2 16   11   16   21   26   31   36   4146
 4 27   12   17   22   27   32   37   4247
 6 38   13   18   23   28   33   38   4348
 8 49   14   19   24   29   34   39   4449
 105   10   15   20   25   30   35   40   4550

 is there a simple way to merge j and k By the row.names in k

 so that row named '2' is placed in the 2nd row of j.. and so forth through
 4,6,8,10

 the actual example has a sparse k.. not evenly spaced

 so this should also be mergeable

  row.names(k) - c(1,2,5,6,9)
  k
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 116   11   16   21   26   31   36   4146
 227   12   17   22   27   32   37   4247
 538   13   18   23   28   33   38   4348
 649   14   19   24   29   34   39   4449
 95   10   15   20   25   30   35   40   4550

 [[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] merging two maxtrices

2010-09-05 Thread steven mosher
ya, unfortunately  k was actually a dataframe and not a matrix when it was
returned
from the function, which explains why I got unexpected results

On Sun, Sep 5, 2010 at 12:21 AM, bill.venab...@csiro.au wrote:

 Is this all you want?

  j - matrix(nrow=10,ncol=10)
  k - matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
 
  row.names(j) - 1:10
  j[row.names(k), ] - k
 
  j
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 1NA   NA   NA   NA   NA   NA   NA   NA   NANA
 2 16   11   16   21   26   31   36   4146
 3NA   NA   NA   NA   NA   NA   NA   NA   NANA
 4 27   12   17   22   27   32   37   4247
 5NA   NA   NA   NA   NA   NA   NA   NA   NANA
 6 38   13   18   23   28   33   38   4348
 7NA   NA   NA   NA   NA   NA   NA   NA   NANA
 8 49   14   19   24   29   34   39   4449
 9NA   NA   NA   NA   NA   NA   NA   NA   NANA
 105   10   15   20   25   30   35   40   4550
 



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of steven mosher
 Sent: Sunday, 5 September 2010 5:10 PM
 To: r-help
 Subject: [R] merging two maxtrices

  j-matrix(nrow=10,ncol=10)
  k-matrix(seq(1:50), ncol=10)
  row.names(k) - seq(2,10,by=2)
  j
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
  [1,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [2,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [3,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [4,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [5,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [6,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [7,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [8,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  [9,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
 [10,]   NA   NA   NA   NA   NA   NA   NA   NA   NANA
  k
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 2 16   11   16   21   26   31   36   4146
 4 27   12   17   22   27   32   37   4247
 6 38   13   18   23   28   33   38   4348
 8 49   14   19   24   29   34   39   4449
 105   10   15   20   25   30   35   40   4550

 is there a simple way to merge j and k By the row.names in k

 so that row named '2' is placed in the 2nd row of j.. and so forth through
 4,6,8,10

 the actual example has a sparse k.. not evenly spaced

 so this should also be mergeable

  row.names(k) - c(1,2,5,6,9)
  k
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 116   11   16   21   26   31   36   4146
 227   12   17   22   27   32   37   4247
 538   13   18   23   28   33   38   4348
 649   14   19   24   29   34   39   4449
 95   10   15   20   25   30   35   40   4550

 [[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


[R] differecing a zoo series

2010-08-20 Thread steven mosher
A quick question

 x - as.yearmon(2000 + seq(0, 23)/12)
 x
 [1] Jan 2000 Feb 2000 Mar 2000 Apr 2000 May 2000 Jun 2000 Jul
2000 Aug 2000 Sep 2000 Oct 2000 Nov 2000 Dec 2000 Jan 2001
[14] Feb 2001 Mar 2001 Apr 2001 May 2001 Jun 2001 Jul 2001 Aug
2001 Sep 2001 Oct 2001 Nov 2001 Dec 2001
 data-seq(1,24,by=1)
 testzoo-zoo(data,order.by=x)

The operation I ant to perform on the zoo series is this. I will illustrate
with a small example and formula:

the coredata of the zoo series is  1,2,3,4,5,6,7,8)
I want to calculate Result- zoo[x]-zoo[x-1]  (NA,1,1,1,1,1...NA)
The first element of course is undefined(NA). is there any method to do this
elegantly, padding NAs at the
start  works but its ugly. if I get a simple function I can apply it to a
matrix of zoo series

[[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] Trouble loading saved Rdata

2010-08-15 Thread steven mosher
The typos were just transcription errors I'' report out the session info

On Sat, Aug 14, 2010 at 5:35 PM, Joshua Wiley jwiley.ps...@gmail.comwrote:

 That worked for me once I properly quoted test.RData on

  sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-pc-mingw32

 locale:
 [1] LC_COLLATE=English_United States.1252
 [2] LC_CTYPE=English_United States.1252
 [3] LC_MONETARY=English_United States.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

 If correcting the quoting does not help you, perhaps you can report
 the results of sessionInfo()

 Cheers,

 Josh

 On Sat, Aug 14, 2010 at 5:14 PM, steven mosher mosherste...@gmail.com
 wrote:
  In the particular application I have I save test.Rdata to a sub
 directory
  dir-Example
  dir.create(dir)
  test-data.frame(a=c(1,2,3),b=c(3,4,5)
 
  full-file.path(dir,test.Rdata,fsep=.Platform$file.sep)
  save(test,file=full)
  load(full)
  returns NULL
 
  it works fine when the object is saved to the working directory, but
 fails
  when saved to a sub directory.
  The Rdata is there. Bytes are in it. but loading it doesnt work.
 
 [[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.
 



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/


[[alternative HTML version deleted]]

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


Re: [R] Trouble loading saved Rdata

2010-08-15 Thread steven mosher
Did you exit R and then return?

fname-test.Rdata
full-file.path(Example,fname,fsep=.Platform$file.sep)
full
[1] Example/test.Rdata
 load(full)
 test
NULL
 sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

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

On Sat, Aug 14, 2010 at 5:35 PM, Joshua Wiley jwiley.ps...@gmail.comwrote:

 That worked for me once I properly quoted test.RData on

  sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-pc-mingw32

 locale:
 [1] LC_COLLATE=English_United States.1252
 [2] LC_CTYPE=English_United States.1252
 [3] LC_MONETARY=English_United States.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

 If correcting the quoting does not help you, perhaps you can report
 the results of sessionInfo()

 Cheers,

 Josh

 On Sat, Aug 14, 2010 at 5:14 PM, steven mosher mosherste...@gmail.com
 wrote:
  In the particular application I have I save test.Rdata to a sub
 directory
  dir-Example
  dir.create(dir)
  test-data.frame(a=c(1,2,3),b=c(3,4,5)
 
  full-file.path(dir,test.Rdata,fsep=.Platform$file.sep)
  save(test,file=full)
  load(full)
  returns NULL
 
  it works fine when the object is saved to the working directory, but
 fails
  when saved to a sub directory.
  The Rdata is there. Bytes are in it. but loading it doesnt work.
 
 [[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.
 



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/


[[alternative HTML version deleted]]

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


Re: [R] Trouble loading saved Rdata

2010-08-15 Thread steven mosher
I think it came down to my actual program having a function that saved the
objects it was passed with a .RData extension as opposed to .Rdata

Rechecking the whole thing.

On Sun, Aug 15, 2010 at 11:05 AM, Joshua Wiley jwiley.ps...@gmail.comwrote:

 Steven,

 I have exited my R session and restarted and I can load the file
 without issue.  I have also tried loading the saved data on some older
 versions of R (2.10.1 and 2.11.0) and Windows (XP).  Have you tried
 recreating the test object, ensuring that it is not NULL itself,
 resaving it, and then see if loading it works better?

 Josh

 On Sun, Aug 15, 2010 at 12:06 AM, steven mosher mosherste...@gmail.com
 wrote:
  Did you exit R and then return?
  fname-test.Rdata
  full-file.path(Example,fname,fsep=.Platform$file.sep)
  full
  [1] Example/test.Rdata
   load(full)
   test
  NULL
  sessionInfo()
  R version 2.11.1 (2010-05-31)
  x86_64-apple-darwin9.8.0
  locale:
  [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
  attached base packages:
  [1] stats graphics  grDevices utils datasets  methods   base
  loaded via a namespace (and not attached):
  [1] tools_2.11.1
  On Sat, Aug 14, 2010 at 5:35 PM, Joshua Wiley jwiley.ps...@gmail.com
  wrote:
 
  That worked for me once I properly quoted test.RData on
 
   sessionInfo()
  R version 2.11.1 (2010-05-31)
  x86_64-pc-mingw32
 
  locale:
  [1] LC_COLLATE=English_United States.1252
  [2] LC_CTYPE=English_United States.1252
  [3] LC_MONETARY=English_United States.1252
  [4] LC_NUMERIC=C
  [5] LC_TIME=English_United States.1252
 
  If correcting the quoting does not help you, perhaps you can report
  the results of sessionInfo()
 
  Cheers,
 
  Josh
 
  On Sat, Aug 14, 2010 at 5:14 PM, steven mosher mosherste...@gmail.com
  wrote:
   In the particular application I have I save test.Rdata to a sub
   directory
   dir-Example
   dir.create(dir)
   test-data.frame(a=c(1,2,3),b=c(3,4,5)
  
   full-file.path(dir,test.Rdata,fsep=.Platform$file.sep)
   save(test,file=full)
   load(full)
   returns NULL
  
   it works fine when the object is saved to the working directory, but
   fails
   when saved to a sub directory.
   The Rdata is there. Bytes are in it. but loading it doesnt work.
  
  [[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.
  
 
 
 
  --
  Joshua Wiley
  Ph.D. Student, Health Psychology
  University of California, Los Angeles
  http://www.joshuawiley.com/
 
 



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/


[[alternative HTML version deleted]]

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


Re: [R] Trouble loading saved Rdata

2010-08-15 Thread steven mosher
  During my session I write several .Rdata  objects to a variety of
subdirectories
so replicating the exact problem wasnt very easy.

In the actual program all the files get written.
all the files have sizes that fit the amount of data in them.


It looks like the problem was naming the files .RData as opposed to .Rdata
since there was one function that named all the files before saving, it
kinda messed up
the program and my ability to replicate the problem.

Seems to be working now

Thanks



On Sun, Aug 15, 2010 at 6:44 AM, David Winsemius dwinsem...@comcast.netwrote:


 On Aug 15, 2010, at 3:06 AM, steven mosher wrote:

  Did you exit R and then return?

 fname-test.Rdata
 full-file.path(Example,fname,fsep=.Platform$file.sep)
 full
 [1] Example/test.Rdata
 load(full)
 test
 NULL


 I am unable to reproduce the problem (after correcting two different
 syntactic errors in the initial posting that should have thrown errors and
 prevented the creation of both test and full . I didn't exit my session
 and return but I did remove the test object after saving it. My guess is
 that the test object was not correctly formed at the time it was saved.

  test-data.frame(a=c(1,2,3),b=c(3,4,5))
   save(test,file=full)
  test
  a b
 1 1 3
 2 2 4
 3 3 5

  full
 [1] Example/test.Rdata
   rm(test)
  load(file=full)
  test
  a b
 1 1 3
 2 2 4
 3 3 5

 (I pretty much have the same setup that is indicated below running on MacOS
 10.5.8.)

 --
 David.




  sessionInfo()

 R version 2.11.1 (2010-05-31)
 x86_64-apple-darwin9.8.0

 locale:
 [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

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

 On Sat, Aug 14, 2010 at 5:35 PM, Joshua Wiley jwiley.ps...@gmail.com
 wrote:

  That worked for me once I properly quoted test.RData on

  sessionInfo()

 R version 2.11.1 (2010-05-31)
 x86_64-pc-mingw32

 locale:
 [1] LC_COLLATE=English_United States.1252
 [2] LC_CTYPE=English_United States.1252
 [3] LC_MONETARY=English_United States.1252
 [4] LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

 If correcting the quoting does not help you, perhaps you can report
 the results of sessionInfo()

 Cheers,

 Josh

 On Sat, Aug 14, 2010 at 5:14 PM, steven mosher mosherste...@gmail.com
 wrote:

 In the particular application I have I save test.Rdata to a sub

 directory

 dir-Example
 dir.create(dir)
 test-data.frame(a=c(1,2,3),b=c(3,4,5)

 full-file.path(dir,test.Rdata,fsep=.Platform$file.sep)
 save(test,file=full)
 load(full)
 returns NULL

 it works fine when the object is saved to the working directory, but

 fails

 when saved to a sub directory.
 The Rdata is there. Bytes are in it. but loading it doesnt work.

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




 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/


[[alternative HTML version deleted]]

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


 David Winsemius, MD
 West Hartford, CT



[[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] Creating list from a long vector

2010-08-14 Thread steven mosher
Stupid question, but its been a long night.

If I have a long vector how can I turn it into a list of the same length

x-rep(seq(1,100,by=1),each=10)

[[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] Creating list from a long vector

2010-08-14 Thread steven mosher
Thx, I see my problem. more sleep required

On Sat, Aug 14, 2010 at 9:25 AM, Romain Francois romain.franc...@dbmail.com
 wrote:


 Le 14/08/10 18:22, steven mosher a écrit :


 Stupid question, but its been a long night.

 If I have a long vector how can I turn it into a list of the same length

 x-rep(seq(1,100,by=1),each=10)


 Perhaps as.list ?

 --
 Romain Francois
 Professional R Enthusiast
 +33(0) 6 28 91 30 30
 http://romainfrancois.blog.free.fr
 |- http://bit.ly/bzoWrs : Rcpp svn revision 2000
 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th
 `- http://bit.ly/aAyra4 : highlight 0.2-2




[[alternative HTML version deleted]]

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


[R] Trouble loading saved Rdata

2010-08-14 Thread steven mosher
In the particular application I have I save test.Rdata to a sub directory
dir-Example
dir.create(dir)
test-data.frame(a=c(1,2,3),b=c(3,4,5)

full-file.path(dir,test.Rdata,fsep=.Platform$file.sep)
save(test,file=full)
load(full)
returns NULL

it works fine when the object is saved to the working directory, but fails
when saved to a sub directory.
The Rdata is there. Bytes are in it. but loading it doesnt work.

[[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] sweep and zoo objects

2010-08-11 Thread steven mosher
rc-list(c(
123,321,234,543,654,768,986,987,246,284),c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec))

# the matrix has rownames that are used as identifiers and columns
# of time. 1 years worth of data. Thats the native format

 test-matrix(seq(1,120, by=1), nrow=10,dimnames=rc)
 test
  Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
123   1  11  21  31  41  51  61  71  81  91 101 111
321   2  12  22  32  42  52  62  72  82  92 102 112
234   3  13  23  33  43  53  63  73  83  93 103 113
543   4  14  24  34  44  54  64  74  84  94 104 114
654   5  15  25  35  45  55  65  75  85  95 105 115
768   6  16  26  36  46  56  66  76  86  96 106 116
986   7  17  27  37  47  57  67  77  87  97 107 117
987   8  18  28  38  48  58  68  78  88  98 108 118
246   9  19  29  39  49  59  69  79  89  99 109 119
284  10  20  30  40  50  60  70  80  90 100 110 120

#The desired result would be a merged zoo object with the row names used as
the colnames of the multiple zoo series

test2-matrix(test,nrow=12,  byrow=F)
g-zoo(test2[,1],frequency=12)
 MYZOO -merge(g,test2[,2:10])

# the result MYZOO is a zoo object, but we've lost the row names in the
transformation of the matrix

#So
colnames(MYZOO)-row.names(test)

#Fixes that problem. Is there a more elegant way to do this???

# now this zoo object needs to be swept out of a much longer zoo object
# with the same column names.. The 'sweep' function is -

Sweep works normally by sweeping out a vector from an array (by column or by
row


sweep(x, MARGIN, STATS, FUN=-, check.margin=TRUE, ...)


 so in my example  x would be a  long yearmon zoo object with the same
column names
as MYZOO above, but decades of data. MARGIN would be rows and the STATS
to sweep out would be the values in MYZOO.


test3-matrix(seq(1,720, by=1), ncol=10)
p-zoo(test3[,1], freq=12)
longzoo-merge(p,test3[,2:10])
colnames(longzoo)-row.names(test)

what we want to do is to sweep out MYZOO from longzoo. I could just repeat
the data in MYZOO 6 times and then subtract MYZOO from longzoo, but thats
a potential memory buster in this situation

[[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] Sweeping a zoo series

2010-08-11 Thread steven mosher
Given a long zoo matrix, the goal is to sweep out a statistic from the
entire length of the
sequences.

 
longzoomatrix-zoo(matrix(rnorm(720),ncol=6),as.yearmon(outer(1900,seq(0,length=120)/12,+)))
 cnames-c(12345,23456,34567,45678,56789,67890)
 colnames(longzoomatrix)-cnames
 longzoomatrix[1:24,]
   12345   23456   34567   45678   56789
 67890
Jan 1900 -0.17123165  1.02087086  0.79514870 -0.54519494 -0.13025459
-0.009980402
Feb 1900  1.21729926 -0.74541038 -0.08138406 -2.01180775  0.19256998
 0.551965871
Mar 1900  1.13222481 -1.25315703  0.01013473  0.08366155 -0.84246010
-1.405959298
Apr 1900 -0.02352559 -1.25001473 -1.53570550 -0.17945324  0.33368133
 2.045125104
May 1900  2.08204920  1.28091067 -0.80888146  0.31796730  0.83248551
 1.439049603
Jun 1900  0.62209570 -0.66189249 -0.57923119 -0.04346112 -2.71353384
-0.346826902
Jul 1900 -1.39758918 -0.54525469 -0.05230070 -0.36725079  1.28281798
 1.391174712
Aug 1900  0.12594069  0.09303970  0.69916411 -1.01902352 -0.82720898
-0.208113626
Sep 1900 -0.34310543  0.41718435  0.79455765  1.13234707  0.14652667
-0.551426097
Oct 1900  1.70634123 -1.20073104 -1.08771551 -0.01715296  0.24931996
-0.753481196
Nov 1900  0.15224070 -0.05108370 -0.97410069  0.51130170  0.13880814
-2.160811186
Dec 1900  0.34726817  0.61830719  0.84429979 -0.26253635  0.95243068
-0.533562966
Jan 1901  0.28647563 -0.40650198 -1.19640622  0.70267162  0.18867804
 0.098855045
Feb 1901  1.27269836  0.31797472 -1.13038040  1.33654480  0.08885501
-0.134690872
Mar 1901 -1.36934330 -0.17244539  0.81705554 -0.09113888  0.90241413
 0.473939164
Apr 1901 -0.89768498  0.82497595  0.15684387  2.25294476 -1.72886103
-0.104769411
May 1901 -0.27898445 -1.24348285  1.36203180  0.02422083 -1.33745980
 1.098856752
Jun 1901 -0.67968801  0.42082064  0.47056133 -0.12981223  0.19445803
-0.284638114
Jul 1901  0.03791761 -0.22118130  1.96044737 -1.18280989  0.90075205
 0.055720535
Aug 1901  1.12904079  0.57177055  0.64300572 -0.16284983  0.07951656
-0.159396821
Sep 1901 -1.43513934  0.03036697  1.09039400  0.99201776  0.98744827
-0.057234838
Oct 1901  0.73828382  0.53967835  2.16608282 -0.82929778 -1.9987
 0.352778450
Nov 1901  0.06561583 -1.20126258  0.67427027  0.15493106  0.08867697
 1.223073528
Dec 1901 -1.23347027 -1.09699304  0.59398031 -0.22269292 -0.21569543
 1.389667825

The statistic to be swept out is itself a zoo series with matching column
names.
There are twelve valies for each column representing an monthly average for
that
series.

The average is to be subtracted

 sweepzoo-zoo(matrix(rnorm(72),ncol=6), frequency=12)
 colnames(sweepzoo)-cnames
 sweepzoo
   12345  23456  34567  45678   56789  67890
1(1)  -2.5569706 -0.4375741 -0.1803866 -0.6303760 -0.08995198  2.7293244
2(1)   1.4154202  0.2559212  0.2104513  0.7439446  0.84897905 -0.4144865
3(1)  -1.3709275  1.0472759  1.5975148  0.3190503  1.10430959 -1.8285194
4(1)  -1.1436430  2.2071763 -0.2637954 -0.4915366 -0.03925020  1.3311624
5(1)  -0.8003656  1.6421541 -1.4603128  0.4493069  0.28194066 -0.4728086
6(1)   0.9236015  0.3780122 -1.3848196  0.4263684  0.99584590 -1.4536475
7(1)   0.8810281  0.0381152  0.3810457 -0.6884233 -0.11018089  0.4221188
8(1)   0.3819421 -0.8431364  1.9876901  0.7072257  0.45524929  2.7013515
9(1)  -1.1247988  1.3083178 -0.3438442  0.3300832  0.67013503  1.2912443
10(1) -0.3643043  1.0756782 -1.2026318  0.4477054  0.54486700 -0.3369889
11(1)  0.8294049  1.8170357  0.5691249  1.9213791 -0.29295754 -0.2617228
12(1) -1.0085265 -0.7556545 -1.4033321 -0.4646647 -0.14984913 -0.4848657

A brute force way to do this is to repeat the 12 values for each column so
that
the number of rows in the  sweepzoo is equal to the nmber of rows on the
long zoo, object and then just subtract them. longzoomatrix-sweepzoo

As a function sweep() wont work because it expects a  vector whose
dimensions
matches the dimension of the MARGIN.

Is there a elegant way to do this short of creating a sweep zoo that
matches
the row dimension of longzoo?  ( would be a nice addition to sweep)

[[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] Sweeping a zoo series

2010-08-11 Thread steven mosher
The colMeans comes closest,

for a single series the assume you have 100 years of monthly data.

The mean you want to scale by is the mean for a restricted period in the
center
of the series.. say 1950-1960

for this period you have the average jan (1950-1960) average feb, ect.

your final series would be

jan 1900 - average jan(1950-60)
feb 1990 - average feb

jan 2000 - average jan(1950-60)

Which gives you a scaling that is not relative to the mean of the whole, but
relative to a base period which is selctable.

BTW switching to zoo has greatly simplified the code.

On Wed, Aug 11, 2010 at 11:21 AM, Gabor Grothendieck 
ggrothendi...@gmail.com wrote:

 On Wed, Aug 11, 2010 at 12:22 PM, steven mosher mosherste...@gmail.com
 wrote:
  Given a long zoo matrix, the goal is to sweep out a statistic from the
  entire length of the
  sequences.
 
 
  
 longzoomatrix-zoo(matrix(rnorm(720),ncol=6),as.yearmon(outer(1900,seq(0,length=120)/12,+)))
   cnames-c(12345,23456,34567,45678,56789,67890)
   colnames(longzoomatrix)-cnames
   longzoomatrix[1:24,]
12345   23456   34567   45678   56789
   67890
  Jan 1900 -0.17123165  1.02087086  0.79514870 -0.54519494 -0.13025459
  -0.009980402
  Feb 1900  1.21729926 -0.74541038 -0.08138406 -2.01180775  0.19256998
   0.551965871
  Mar 1900  1.13222481 -1.25315703  0.01013473  0.08366155 -0.84246010
  -1.405959298
  Apr 1900 -0.02352559 -1.25001473 -1.53570550 -0.17945324  0.33368133
   2.045125104
  May 1900  2.08204920  1.28091067 -0.80888146  0.31796730  0.83248551
   1.439049603
  Jun 1900  0.62209570 -0.66189249 -0.57923119 -0.04346112 -2.71353384
  -0.346826902
  Jul 1900 -1.39758918 -0.54525469 -0.05230070 -0.36725079  1.28281798
   1.391174712
  Aug 1900  0.12594069  0.09303970  0.69916411 -1.01902352 -0.82720898
  -0.208113626
  Sep 1900 -0.34310543  0.41718435  0.79455765  1.13234707  0.14652667
  -0.551426097
  Oct 1900  1.70634123 -1.20073104 -1.08771551 -0.01715296  0.24931996
  -0.753481196
  Nov 1900  0.15224070 -0.05108370 -0.97410069  0.51130170  0.13880814
  -2.160811186
  Dec 1900  0.34726817  0.61830719  0.84429979 -0.26253635  0.95243068
  -0.533562966
  Jan 1901  0.28647563 -0.40650198 -1.19640622  0.70267162  0.18867804
   0.098855045
  Feb 1901  1.27269836  0.31797472 -1.13038040  1.33654480  0.08885501
  -0.134690872
  Mar 1901 -1.36934330 -0.17244539  0.81705554 -0.09113888  0.90241413
   0.473939164
  Apr 1901 -0.89768498  0.82497595  0.15684387  2.25294476 -1.72886103
  -0.104769411
  May 1901 -0.27898445 -1.24348285  1.36203180  0.02422083 -1.33745980
   1.098856752
  Jun 1901 -0.67968801  0.42082064  0.47056133 -0.12981223  0.19445803
  -0.284638114
  Jul 1901  0.03791761 -0.22118130  1.96044737 -1.18280989  0.90075205
   0.055720535
  Aug 1901  1.12904079  0.57177055  0.64300572 -0.16284983  0.07951656
  -0.159396821
  Sep 1901 -1.43513934  0.03036697  1.09039400  0.99201776  0.98744827
  -0.057234838
  Oct 1901  0.73828382  0.53967835  2.16608282 -0.82929778 -1.9987
   0.352778450
  Nov 1901  0.06561583 -1.20126258  0.67427027  0.15493106  0.08867697
   1.223073528
  Dec 1901 -1.23347027 -1.09699304  0.59398031 -0.22269292 -0.21569543
   1.389667825
 
  The statistic to be swept out is itself a zoo series with matching column
  names.
  There are twelve valies for each column representing an monthly average
 for
  that
  series.
 
  The average is to be subtracted
 
   sweepzoo-zoo(matrix(rnorm(72),ncol=6), frequency=12)
   colnames(sweepzoo)-cnames
   sweepzoo
12345  23456  34567  45678   56789  67890
  1(1)  -2.5569706 -0.4375741 -0.1803866 -0.6303760 -0.08995198  2.7293244
  2(1)   1.4154202  0.2559212  0.2104513  0.7439446  0.84897905 -0.4144865
  3(1)  -1.3709275  1.0472759  1.5975148  0.3190503  1.10430959 -1.8285194
  4(1)  -1.1436430  2.2071763 -0.2637954 -0.4915366 -0.03925020  1.3311624
  5(1)  -0.8003656  1.6421541 -1.4603128  0.4493069  0.28194066 -0.4728086
  6(1)   0.9236015  0.3780122 -1.3848196  0.4263684  0.99584590 -1.4536475
  7(1)   0.8810281  0.0381152  0.3810457 -0.6884233 -0.11018089  0.4221188
  8(1)   0.3819421 -0.8431364  1.9876901  0.7072257  0.45524929  2.7013515
  9(1)  -1.1247988  1.3083178 -0.3438442  0.3300832  0.67013503  1.2912443
  10(1) -0.3643043  1.0756782 -1.2026318  0.4477054  0.54486700 -0.3369889
  11(1)  0.8294049  1.8170357  0.5691249  1.9213791 -0.29295754 -0.2617228
  12(1) -1.0085265 -0.7556545 -1.4033321 -0.4646647 -0.14984913 -0.4848657
 
  A brute force way to do this is to repeat the 12 values for each column
 so
  that
  the number of rows in the  sweepzoo is equal to the nmber of rows on
 the
  long zoo, object and then just subtract them. longzoomatrix-sweepzoo
 
  As a function sweep() wont work because it expects a  vector whose
  dimensions
  matches the dimension of the MARGIN.
 
  Is there a elegant way to do this short of creating a sweep zoo that
  matches
  the row dimension of longzoo?  ( would be a nice addition

[R] nested 'by'

2010-08-09 Thread steven mosher
Assuming a data frame or matrix with two columns representing variable that
you want to aggregate over.
you want to calculate column means, by year, for each Id



example-data.frame(id=c(rep(12345,5),rep(54321,6),rep(45678,7)),Year=rep(seq(1900,1902,by=1),6),
x=seq(1,18,by=1),y=seq(18,1,by=-1))
 example
  id Year  x  y
1  12345 1900  1 18
2  12345 1901  2 17
3  12345 1902  3 16
4  12345 1900  4 15
5  12345 1901  5 14
6  54321 1902  6 13
7  54321 1900  7 12
8  54321 1901  8 11
9  54321 1902  9 10
10 54321 1900 10  9
11 54321 1901 11  8
12 45678 1902 12  7
13 45678 1900 13  6
14 45678 1901 14  5
15 45678 1902 15  4
16 45678 1900 16  3
17 45678 1901 17  2
18 45678 1902 18  1

 result-by(example[,3:4], example$id, by(example[,3:4],
example$Year,colMeans, na.rm=T))
Error in FUN(X[[1L]], ...) : could not find function FUN


desired result should look like:
 id  Year  meanx mean y
1  12345 1900   ......
2  12345 1901   ...
3  12345 1902   ...
4  54321 1900
5  54321 1901
6  54321 1902
7 45678 1900
8 45678 1901
9 45678 1902

[[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] nested 'by'

2010-08-09 Thread steven mosher
That works.

Thanks

On Mon, Aug 9, 2010 at 7:55 AM, Henrique Dallazuanna www...@gmail.comwrote:

 Try this:

 aggregate(example[c('x', 'y')], example[c('id', 'Year')], 'mean')


 On Mon, Aug 9, 2010 at 11:46 AM, steven mosher mosherste...@gmail.comwrote:

 Assuming a data frame or matrix with two columns representing variable
 that
 you want to aggregate over.
 you want to calculate column means, by year, for each Id




 example-data.frame(id=c(rep(12345,5),rep(54321,6),rep(45678,7)),Year=rep(seq(1900,1902,by=1),6),
 x=seq(1,18,by=1),y=seq(18,1,by=-1))
  example
  id Year  x  y
 1  12345 1900  1 18
 2  12345 1901  2 17
 3  12345 1902  3 16
 4  12345 1900  4 15
 5  12345 1901  5 14
 6  54321 1902  6 13
 7  54321 1900  7 12
 8  54321 1901  8 11
 9  54321 1902  9 10
 10 54321 1900 10  9
 11 54321 1901 11  8
 12 45678 1902 12  7
 13 45678 1900 13  6
 14 45678 1901 14  5
 15 45678 1902 15  4
 16 45678 1900 16  3
 17 45678 1901 17  2
 18 45678 1902 18  1

  result-by(example[,3:4], example$id, by(example[,3:4],
 example$Year,colMeans, na.rm=T))
 Error in FUN(X[[1L]], ...) : could not find function FUN


 desired result should look like:
  id  Year  meanx mean y
 1  12345 1900   ......
 2  12345 1901   ...
 3  12345 1902   ...
 4  54321 1900
 5  54321 1901
 6  54321 1902
 7 45678 1900
 8 45678 1901
 9 45678 1902

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




 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O


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


  1   2   >