Re: [R] How can I make my functions run faster

2013-08-19 Thread Heramb Gadgil
Greetings,

I am a newbie too. I will share what I do normally for speeding up the code.

1. Restrict defining too many variables (Global/ Local)
2. Use apply functions (apply,sapply,lapply,tapply, etc.) whenever feasible
3. Having multiple user defined functions doesn't help. Try to compact
everything in minimum number of functions
4. The in-memory of R is just 10% of your total RAM (Correct me if wrong).
Make sure most of it is used for processing and not storing

Hope this will help. Kindly suggest if I have misunderstood anything.

Thanks and Regards,

Heramb Gadgil


2013/8/19 Laz lmra...@ufl.edu

 Yes Bert, I am a beginner in writing R functions. I just don't know what
 to avoid or what to use in order to make the R functions faster.

 When I run the individual functions, they run quite well.
 However, calling all of them using the final function it becomes too slow.

 So I don't know how to make it faster.
 I used system.time()

 Regards,
 Laz


 On 8/19/2013 10:13 AM, Bert Gunter wrote:

 ... and read the R Language Definition manual. I noticed unnecessary
 constructs
 (e.g., z - f(something); return(z)) that suggest you have more basics
 to learn to write efficient, well-structured R code.

 -- Bert

 On Mon, Aug 19, 2013 at 3:55 AM, Michael Dewey i...@aghmed.fsnet.co.uk
 wrote:

 At 10:28 19/08/2013, Laz wrote:

 Dear R users,

 I have written a couple of R functions, some are through the help of
 the R
 group members. However, running them takes days instead of minutes or a
 few
 hours. I am wondering whether there is a quick way of doing that.


 Your example code is rather long for humans to profile. Have you thought
 of
 getting R to tell where it is spending most time? The R extensions manual
 tells you how to do this.


  Here are all my R functions. The last one calls almost all of the
 previous
 functions. It is the one I am interested in most. It gives me the
 correct
 output but it takes several days to run only 1000 or 2000 simulations!
 e.g. system.time(test1-finalF(**designs=5,swaps=20));test1
 will take about 20 minutes to run but
 system.time(test1-finalF(**designs=5,swaps=50));test1 takes about 10
 hours
 and system.time(test1-finalF(**designs=25,swaps=2000));test1 takes
 about 3
 days to run

 Here are my functions


 ##**##**
 #

 ls() # list all existing objects
 rm(list = ls()) # remove them all
 rm(list = ls()[!grepl(global.var.A, ls())])
 # refresh memory
 gc()
 ls()

 ### Define a function that requires useful input from the user
 #b=4;g=seq(1,20,1);rb=5;cb=4;**s2e=1; r=10;c=8

 ##**###
 ##**##
 # function to calculate heritability
 herit-function(varG,varR=1)
 {
h-4*varG/(varG+varR)
return(c(heritability=h))
 }

 ##**#
 # function to calculate random error
 varR-function(varG,h2)
 {
varR- varG*(4-h2)/h2
return(c(random_error=varR))
 }

 ##**
 # function to calculate treatment variance
 varG-function(varR=1,h2)
 {
varG-varR*h2/(4-h2)
return(c(treatment_variance=**varG))
 }


 ##**#

 # calculating R inverse from spatial data
 rspat-function(rhox=0.6,rhoy=**0.6)
 {
s2e-1
R-s2e*eye(N)
for(i in 1:N) {
  for (j in i:N){
y1-y[i]
y2-y[j]
x1-x[i]
x2-x[j]
R[i,j]-s2e*(rhox^abs(x2-x1))***(rhoy^abs(y2-y1)) # Core
 AR(1)*AR(1)
R[j,i]-R[i,j]
  }
}
IR-solve(R)
IR
 }

 ped-read.table(ped2new.txt**,header=FALSE)
 # Now work on the pedigree
 ## A function to return Zinverse from pedigree

 ZGped-function(ped)
 {
ped2-data.frame(ped)
lenp2-length(unique(ped2$V1))**;lenp2 # how many Genotypes in
 total in
 the pedigree =40
ln2-length(g);ln2#ln2=nrow(**matdf)=30
# calculate the new Z
Zped-model.matrix(~ matdf$genotypes -1)# has order N*t = 180 by 30
dif-(lenp2-ln2);dif # 40-30=10
#print(c(lenp2,ln2,dif))
zeromatrix-zeros(nrow(matdf),**dif);zeromatrix # 180 by 10
Z-cbind(zeromatrix,Zped) # Design Matrix for random effect
 (Genotypes):
 180 by 40
# calculate the new G
M-matrix(0,lenp2,lenp2) # 40 by 40
for (i in 1:nrow(ped2)) { M[ped2[i, 1], ped2[i, 2]] - ped2[i, 3]  }
G-s2g*M # Genetic Variance covariance matrix for pedigree 2: 40 by
 40
IG-solve(G)
return(list(IG=IG, Z=Z))
 }

 ##
 ##Required packages#
 
 library(gmp)
 library(knitr) # load this packages for publishing results
 library(matlab)
 library(Matrix)
 library(psych)
 library(foreach)
 library(epicalc)
 library(ggplot2)
 library(xtable)
 library(gdata)
 library(gplots)

 #b=6;g=seq(1,30,1);rb=5;cb=6;**r=15;c=12;h2=0.3;rhox=0.6;**
 rhoy=0.6;ped=0

 setup-function(b,g,rb,cb,r,c,**h2,rhox=0.6,rhoy=0.6,ped=F)
{
  # where
  # b   = number of blocks
  # t   = number of treatments

Re: [R] How can I make my functions run faster

2013-08-19 Thread Heramb Gadgil
Greetings,

Thanks Jeff. I appreciate your 'to the point' explanation. Will read into
it more.

Best,
Heramb Gadgil


2013/8/19 Jeff Newmiller jdnew...@dcn.davis.ca.us

 1. Keeping the number of variables down encourages you to structure your
 data, which allows you to re-use code more efficiently. However, I don't
 believe that the number of variables intrinsically slows down your code
 significantly.. e.g. storing a computed value in a local variable is almost
 always better than repeating the calculation.

 2. Apply functions are not primarily intended for performance
 optimization; they are effective for compactly expressing the idea of your
 algorithms. Using vectorization and indexing is much more effective for
 enhancing performance (and in my mind is even better at expressing
 algorithms than using apply functions).

 3. Agree that too many functions can slow things down, but that is
 normally less the fault of the functions than of the way some programmers
 handle data. It is more productive to focus on the positive idea of using
 vectors to compute as much as possible rather than the negative idea of
 eliminating functions.

 4. I don't think I agree that this statement about memory usage generally
 applies to all uses of R. However, it can be crucial to learn to avoid
 mixing input/output with data processing if you are interested in
 performance.

 To the OP: I will pass on trying to analyse your large code base... it is
 requested in the Posting Guide that you isolate your issues and ask
 specific questions.
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
 Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 Heramb Gadgil heramb.gad...@gmail.com wrote:
 Greetings,
 
 I am a newbie too. I will share what I do normally for speeding up the
 code.
 
 1. Restrict defining too many variables (Global/ Local)
 2. Use apply functions (apply,sapply,lapply,tapply, etc.) whenever
 feasible
 3. Having multiple user defined functions doesn't help. Try to compact
 everything in minimum number of functions
 4. The in-memory of R is just 10% of your total RAM (Correct me if
 wrong).
 Make sure most of it is used for processing and not storing
 
 Hope this will help. Kindly suggest if I have misunderstood anything.
 
 Thanks and Regards,
 
 Heramb Gadgil
 
 
 2013/8/19 Laz lmra...@ufl.edu
 
  Yes Bert, I am a beginner in writing R functions. I just don't know
 what
  to avoid or what to use in order to make the R functions faster.
 
  When I run the individual functions, they run quite well.
  However, calling all of them using the final function it becomes too
 slow.
 
  So I don't know how to make it faster.
  I used system.time()
 
  Regards,
  Laz
 
 
  On 8/19/2013 10:13 AM, Bert Gunter wrote:
 
  ... and read the R Language Definition manual. I noticed
 unnecessary
  constructs
  (e.g., z - f(something); return(z)) that suggest you have more
 basics
  to learn to write efficient, well-structured R code.
 
  -- Bert
 
  On Mon, Aug 19, 2013 at 3:55 AM, Michael Dewey
 i...@aghmed.fsnet.co.uk
  wrote:
 
  At 10:28 19/08/2013, Laz wrote:
 
  Dear R users,
 
  I have written a couple of R functions, some are through the help
 of
  the R
  group members. However, running them takes days instead of minutes
 or a
  few
  hours. I am wondering whether there is a quick way of doing that.
 
 
  Your example code is rather long for humans to profile. Have you
 thought
  of
  getting R to tell where it is spending most time? The R extensions
 manual
  tells you how to do this.
 
 
   Here are all my R functions. The last one calls almost all of the
  previous
  functions. It is the one I am interested in most. It gives me the
  correct
  output but it takes several days to run only 1000 or 2000
 simulations!
  e.g. system.time(test1-finalF(**designs=5,swaps=20));test1
  will take about 20 minutes to run but
  system.time(test1-finalF(**designs=5,swaps=50));test1 takes about
 10
  hours
  and system.time(test1-finalF(**designs=25,swaps=2000));test1
 takes
  about 3
  days to run
 
  Here are my functions
 
 
  ##**##**
  #
 
  ls() # list all existing objects
  rm(list = ls()) # remove them all
  rm(list = ls()[!grepl(global.var.A, ls())])
  # refresh memory
  gc()
  ls()
 
  ### Define a function that requires useful input from the user
  #b=4;g=seq(1,20,1);rb=5;cb=4;**s2e=1; r=10;c=8
 
  ##**###
  ##**##
  # function

Re: [R] how to get a value from a list (using paste function)?

2012-12-27 Thread Heramb Gadgil
I am not sure why Never ever!

Can you please elaborate. What are the negatives about the method

Warm Regards,
Heramb M. Gadgil


On Thu, Dec 27, 2012 at 3:50 PM, Uwe Ligges lig...@statistik.tu-dortmund.de
 wrote:



 On 27.12.2012 08:09, Heramb Gadgil wrote:

 eval(parse(text=paste0(**cvtest$,lambda.rule)))


 No, never ever!

 There is an R idiom made for it:

 cvtest[[lambda.rule]]

 Uwe Ligges







  I hope this works.

 On Wed, Dec 19, 2012 at 12:57 AM, Thomas Stewart
 tgs.public.m...@gmail.com**wrote:

  Soyeon-

 A possible solution:

 get(lambda.rule,envir=**list2env(cvtest))


 On Tue, Dec 18, 2012 at 12:34 PM, Soyeon Kim yunni0...@gmail.com
 wrote:

  Dear my R friends,

 I want to get a number from a list using paste function.
 In my example,
 lambda.rule - lambda.1se
 cvtest is a list (result from cv.glmnet)
 and
 cvtest$lambda.1se
 [1] 1.308973

 I want to call the value using paste function.
 I used get function but there was an error.
 test -  get(paste(cvtest$,lambda.**rule, sep=))
 Error in get(paste(cvtest$, lambda.rule, sep = )) :
object 'cvtest$lambda.1se' not found

 Do you guys know how to solve this issue?

 Thank you so much in advance and merry Christmas!

 Soyeon

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




  [[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.htmlhttp://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-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 get a value from a list (using paste function)?

2012-12-27 Thread Heramb Gadgil
Agreed.

But the initial question was to get the output with paste function. That is
the reason why I went for eval.

Please let me know in case I am going the wrong way

On Thu, Dec 27, 2012 at 4:34 PM, Jessica Streicher j.streic...@micromata.de
 wrote:

 Well for one, if ever someone looks at your code, cvtest[[lambda.rule]] is
 much easier to read and understand than
 eval(parse(text=paste0(cvtest$,lambda.rule)))


 On 27.12.2012, at 11:44, Heramb Gadgil wrote:

  I am not sure why Never ever!
 
  Can you please elaborate. What are the negatives about the method
 
  Warm Regards,
  Heramb M. Gadgil
 
 
  On Thu, Dec 27, 2012 at 3:50 PM, Uwe Ligges 
 lig...@statistik.tu-dortmund.de
  wrote:
 
 
 
  On 27.12.2012 08:09, Heramb Gadgil wrote:
 
  eval(parse(text=paste0(**cvtest$,lambda.rule)))
 
 
  No, never ever!
 
  There is an R idiom made for it:
 
  cvtest[[lambda.rule]]
 
  Uwe Ligges
 
 
 
 
 
 
 
  I hope this works.
 
  On Wed, Dec 19, 2012 at 12:57 AM, Thomas Stewart
  tgs.public.m...@gmail.com**wrote:
 
  Soyeon-
 
  A possible solution:
 
  get(lambda.rule,envir=**list2env(cvtest))
 
 
  On Tue, Dec 18, 2012 at 12:34 PM, Soyeon Kim yunni0...@gmail.com
  wrote:
 
  Dear my R friends,
 
  I want to get a number from a list using paste function.
  In my example,
  lambda.rule - lambda.1se
  cvtest is a list (result from cv.glmnet)
  and
  cvtest$lambda.1se
  [1] 1.308973
 
  I want to call the value using paste function.
  I used get function but there was an error.
  test -  get(paste(cvtest$,lambda.**rule, sep=))
  Error in get(paste(cvtest$, lambda.rule, sep = )) :
object 'cvtest$lambda.1se' not found
 
  Do you guys know how to solve this issue?
 
  Thank you so much in advance and merry Christmas!
 
  Soyeon
 
  __**
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/**listinfo/r-help
 https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/**posting-guide.html
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 
  [[alternative HTML version deleted]]
 
  __**
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/**listinfo/r-help
 https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/**posting-guide.html
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 [[alternative HTML version deleted]]
 
  __**
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/**listinfo/r-help
 https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/**
  posting-guide.html http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
[[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 get a value from a list (using paste function)?

2012-12-27 Thread Heramb Gadgil
Thanks a lot for the explaination. Much appreciated. :-)

On Thu, Dec 27, 2012 at 10:31 PM, William Dunlap wdun...@tibco.com wrote:

  Can you please elaborate. What are the negatives about the method

 Here are a few examples of eval(parse(text=paste())) failing:
cvtest - list(Test-1=1, Bozo=2, Joe's Test=3)
   
lambda.rule - Test-1
eval(parse(text=paste0(cvtest$, lambda.rule))) # want 1
   [1] 0
   
lambda.rule - Joe's Test
eval(parse(text=paste0(cvtest$, lambda.rule))) # want 3
   Error in parse(text = paste0(cvtest$, lambda.rule)) :
 text:1:11: unexpected INCOMPLETE_STRING
   1: cvtest$Joe's Test
  ^

 and here is an example of $ giving a suboptimal result:
cvtest$B # want NULL (there is no component named B)
   [1] 2

 [[ gives the correct result in all cases:
lambda.rule - Test-1
cvtest[[lambda.rule]]
   [1] 1
lambda.rule - B
cvtest[[lambda.rule]]
   NULL
lambda.rule - Bozo
cvtest[[lambda.rule]]
   [1] 2
lambda.rule - Joe's Test
cvtest[[lambda.rule]]
   [1] 3

 Also, I find it hard to read code involving eval(parse(text=paste(...))).

 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com


  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf
  Of Heramb Gadgil
  Sent: Thursday, December 27, 2012 2:44 AM
  To: Uwe Ligges
  Cc: Thomas Stewart; r-help
  Subject: Re: [R] how to get a value from a list (using paste function)?
 
  I am not sure why Never ever!
 
  Can you please elaborate. What are the negatives about the method
 
  Warm Regards,
  Heramb M. Gadgil
 
 
  On Thu, Dec 27, 2012 at 3:50 PM, Uwe Ligges 
 lig...@statistik.tu-dortmund.de
   wrote:
 
  
  
   On 27.12.2012 08:09, Heramb Gadgil wrote:
 
   eval(parse(text=paste0(**cvtest$,lambda.rule)))
  
  
   No, never ever!
  
   There is an R idiom made for it:
  
   cvtest[[lambda.rule]]
  
   Uwe Ligges
  
  
  
  
  
  
  
I hope this works.
  
   On Wed, Dec 19, 2012 at 12:57 AM, Thomas Stewart
   tgs.public.m...@gmail.com**wrote:
  
Soyeon-
  
   A possible solution:
  
   get(lambda.rule,envir=**list2env(cvtest))
  
  
   On Tue, Dec 18, 2012 at 12:34 PM, Soyeon Kim yunni0...@gmail.com
   wrote:
  
Dear my R friends,
  
   I want to get a number from a list using paste function.
   In my example,
   lambda.rule - lambda.1se
   cvtest is a list (result from cv.glmnet)
   and
   cvtest$lambda.1se
   [1] 1.308973
  
   I want to call the value using paste function.
   I used get function but there was an error.
   test -  get(paste(cvtest$,lambda.**rule, sep=))
   Error in get(paste(cvtest$, lambda.rule, sep = )) :
  object 'cvtest$lambda.1se' not found
  
   Do you guys know how to solve this issue?
  
   Thank you so much in advance and merry Christmas!
  
   Soyeon
  
   __**
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/**listinfo/r-
  helphttps://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
   http://www.R-project.org/**posting-guide.htmlhttp://www.R-
  project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
  
  
  
[[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.htmlhttp://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-
  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.


[[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] Renaming column names according to another dataframe

2012-12-26 Thread Heramb Gadgil
try this:
colnames(df)-df_names[1:ncol(df),name]

On Sun, Dec 23, 2012 at 8:41 PM, radhi radhikum...@yahoo.in wrote:

 Hi, I've got a dataframe having a code as column name. Addtionally I have
 another dataframe with a two columns (and lots of rows), the first
 containing the code and the second some Text (real name). Now I'd like to
 use the information (pairs of code and name) of the second dataframe to
 rename all the columnnames in the first dataframe. How is it possible to
 achieve that? Here a small example of the two dataframes: df -
 data.frame(A=(1:10),B=(1:10),C=(1:10)) df_names -
 data.frame(code=c(A,B,C,D,E),name=c(Col A,Col B,Col C,Col
 D,Col E))  click here http://totalltelugumovies.blogspot.in



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Renaming-column-names-according-to-another-dataframe-tp4653824.html
 Sent from the R help mailing list archive at Nabble.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] how to read different files into different objects in one time?

2012-12-26 Thread Heramb Gadgil
You can try this one too.

#Set the directory to a path where all the files to be read are stored

TabletoRead=list.files(pattern=.txt)
I_Step=unlist(lapply(TabletoRead,function(tab){
 srno-ifelse(exists(srno),(1+srno),1)
 Temp=read.table(tab,header=T,sep=#Seperator)
 makeActiveBinding(paste(Table,srno,sep=_),
function() Temp, .GlobalEnv)
   }))
rm(I_Step)
Ref_Table=cbind(Orignial=TabletoRead,Stored_As=paste(Table,1:length(TabletoRead),sep=_))

#When required you can check the Ref_Table to get the required table

On Thu, Dec 20, 2012 at 10:41 AM, Jeff Newmiller
jdnew...@dcn.davis.ca.uswrote:

 The short answer is: don't try. You really don't want dozens of different
 objects in memory that you didn't name yourself.

 What you want instead is a list of objects. You can start with a vector of
 filenames and use lapply to create another list containing the data frames.
 For convenience you can then set the list element names to the names of the
 files.

 fnames - list.files()
 dta - lapply( fnames, function(i){read.table(i, header= TRUE) })
 names(dta) - fnames

 You can access these data frames using the $ or [[ operators.

 dta$G1.txt
 dta[[G1.txt]]
 or
 dta[[2]]

 Read more about it in the Introduction to R document supplied with R.
 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
 Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 Yao He yao.h.1...@gmail.com wrote:

 Dear All
 
 I have a lot of files in a directory as follows:
 02-03.txt   03-04.txt   04-05.txt   05-06.txt   06-07.txt
 07-08.txt   08-09.txt
  09-10.txt   G0.txt  G1.txt  raw_ped.txt
 ..
 
 I want to read them into different objects according to their
 filenames,such as:
 02-03-read.table(02-03.txt,header=T)
 03-04-read.table(03-04.txt,header=T)
 I don't want to type hundreds of read.table(),so how I read it in one
 time?
 I think the core problem is that I can't create different objects'
 name in the use of loop or sapply() ,but there may be a better way to
 do what I want.
 
 Thanks a lot
 
 Yao He
 
 Yao He

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 get a value from a list (using paste function)?

2012-12-26 Thread Heramb Gadgil
eval(parse(text=paste0(cvtest$,lambda.rule)))

I hope this works.

On Wed, Dec 19, 2012 at 12:57 AM, Thomas Stewart
tgs.public.m...@gmail.comwrote:

 Soyeon-

 A possible solution:

 get(lambda.rule,envir=list2env(cvtest))


 On Tue, Dec 18, 2012 at 12:34 PM, Soyeon Kim yunni0...@gmail.com wrote:

  Dear my R friends,
 
  I want to get a number from a list using paste function.
  In my example,
  lambda.rule - lambda.1se
  cvtest is a list (result from cv.glmnet)
  and
  cvtest$lambda.1se
  [1] 1.308973
 
  I want to call the value using paste function.
  I used get function but there was an error.
  test -  get(paste(cvtest$,lambda.rule, sep=))
  Error in get(paste(cvtest$, lambda.rule, sep = )) :
object 'cvtest$lambda.1se' not found
 
  Do you guys know how to solve this issue?
 
  Thank you so much in advance and merry Christmas!
 
  Soyeon
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/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] install.packages on windows

2012-10-01 Thread Heramb Gadgil
You can look for different versions of that package and try manually
installing the lower version.

On Fri, Sep 28, 2012 at 11:25 PM, Uwe Ligges 
lig...@statistik.tu-dortmund.de wrote:



 On 28.09.2012 00:32, Duncan Murdoch wrote:

 On 12-09-27 2:53 PM, Anju R wrote:

 Sometimes when I try to install certain packages I get a warning message.
 For example, I tried to install the package Imtest on windows R version
 2.15.1 and got the following message:

 Warning message:
 package ‘Imtest’ is not available (for R version 2.15.1)

 How can I install the above package? Why do I get the above Warning
 message?


 It probably means exactly what it says, except that the information is
 about the mirror you are using.

 I would try another mirror.  If that doesn't solve it, then it probably
 means that the package is really not available for 2.15.1.

 You can look on the cran.r-project.org website for information about it,
 and probably download the source from there, but you will probably need
 to fix whatever is wrong with it before it will work.



 Or in other words:

 There is no such package Imtest on CRAN, perhaps you are looking for
 lmtest?

 Uwe Ligges




  Duncan Murdoch

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


 __**
 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] mapping data from table to .csv template

2012-09-25 Thread Heramb Gadgil
Try the following code.
It is basic but effective;

 *setwd(/home/user2/Documents)*

*Test_matrix=read.csv(Trial.csv,header=T) # The 1st table that you have
considered
*

*Test_matrix=as.matrix(Test_matrix)*

*Writer=function(mat){u=unique(mat[,Subject])*

*l=length(u)*

*dummy=lapply(1:l,FUN=function(x){string=u[x]*

*step1=unlist(strsplit(string,))*

*file_name=substring(string,(which(step1==[)+1),(which(step1==])-1))*

*m=mat[which(mat[,Subject]==string),]*

*dummy_matrix=matrix(rep(0,11*11),nrow=11)*

*colnames(dummy_matrix)=#Names of all the 11 ppl.*

*rownames(dummy_matrix)=#Names of all the 11 ppl.*

*for(i in 1:11)*

*{for(j in 1:11)*

*
{index=which(m[,Receiver]==rownames(dummy)[i]m[,Sender]==colnames(dummy)[j])
*

*count=length(index)*

*dummy_matrix[i,j]=count}}*

*
write.csv(dummy_matrix,paste('/home/hduser/',file_name,'_counts','.csv',sep=''))
*

*write.csv(m,paste('/home/hduser/',file_name,.csv,sep=))*

*})}*


*I hope this helps,*


*Best,*

*Heramb
*


On Tue, Sep 25, 2012 at 12:29 PM, PIKAL Petr petr.pi...@precheza.cz wrote:

 Hi

 your data are difficult to read so I make my own

 set.seed(111)
 sender-sample(letters[1:5], 20, replace=T)
 receiver-sample(letters[1:5], 20, replace=T)
 xtabs(~sender+receiver)
   receiver
 sender a b c d e
  a 1 1 3 1 0
  b 0 1 0 1 1
  c 1 3 2 2 0
  d 0 1 0 0 1
  e 0 0 0 1 0

 If you want such result from each subject of your table }presumably
 data.frame just split and lapply it

 untested
 lapply(split(your.data, by a column), function (x)
 xtabs(~x$sender+x$receiver))

 Regards

 Petr


  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
  project.org] On Behalf Of s.s.m. fauzi
  Sent: Tuesday, September 25, 2012 4:06 AM
  To: r-help@r-project.org
  Subject: [R] mapping data from table to .csv template
 
  I have a .csv table named mailing.csv as below. It consist a receiver,
  subject and sender.
 
Receiversubject   sender
  1   Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  2   Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  3   Adrian ColeRE: [WHIRR-117] Composable services  Adrian Cole
  4   Adrian ColeRE: [WHIRR-117] Composable services  Adrian Cole
  5   Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  6   Adrian ColeRE: [WHIRR-117] Composable services  Adrian Cole
  7   Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  8   Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  9   Adrian ColeRE: [WHIRR-117] Composable services  Adrian Cole
  10  Adrian ColeRE: [WHIRR-117] Composable services  Adrian Cole
  11  Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  12  Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  13  Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  14  Adrian ColeRE: [WHIRR-117] Composable servicesTom White
  15 Patrick Hunt RE: [WHIRR-123] Cassandra integration Tom White
  16 Patrick Hunt RE: [WHIRR-123] Cassandra integration   Andrei Savu
  17 Patrick Hunt RE: [WHIRR-123] Cassandra integration   Andrei Savu
  18 Patrick Hunt RE: [WHIRR-123] Cassandra integration Tom White
  19 Patrick Hunt RE: [WHIRR-123] Cassandra integration Tom White
  20 Patrick Hunt RE: [WHIRR-123] Cassandra integration   Adrian Cole
  21 Patrick Hunt RE: [WHIRR-123] Cassandra integration Tom White22
  Patrick Hunt RE: [WHIRR-123] Cassandra integration  Patrick Hunt
 
  What I would like to do is to update/map the information from table
  above to .csv template (namedAC_template.csv), and save it in a
  separate file using subject details in backet as file name (for
  instance AC_WHIRR-117). As for table above, it should create two new
  files name as AC_WHIRR-117and AC_WHIRR-123.
 
  sample .csv template (AC_template.csv) is as below:
 
  Adrian.Cole Patrick.Hunt Andrei.Savu Bruno.Dumon
  Edward.J..Yoon Eugene.Koontz Jakob.Homan Kelvin.Kakugawa Tom.White
  Adrian Cole   00   0   0
 0 0   0   0 0
  Patrick Hunt  00   0   0
 0 0   0   0 0
  Andrei Savu   00   0   0
 0 0   0   0 0
  Bruno Dumon   00   0   0
 0 0   0   0 0
  Edward J. Yoon00   0   0
 0 0   0   0 0
  Eugene Koontz 00   0   0
 0 0   0   0 0
  Jakob Homan   00   0   0
 0 0   0   0 0
  Kelvin Kakugawa  

Re: [R] Script to count unique values from two linked matricies

2012-09-25 Thread Heramb Gadgil
We can have something like this;

*Data1-data.frame(Site1=c(5,NA,4),Site2=c(3,2,4),Site3=c(NA,5,NA))
Data2-data.frame(TraitType1=c(1,2,3),TraitType2=c(2,4,2),TraitType3=c(5,1,1))
*

*rownames(Data1)-paste(Species,1:3)*

*rownames(Data2)-paste(Species,1:3)*

 *User_Defined=function(dat1,dat2){c1=ncol(dat1)*

*out=NULL*

*dummy=lapply(1:c1,function(x){step1=dat1[,x]*

*step2=dat2[which(is.na(step1)==F),]*

*step3=length(unlist(apply(step2,2,unique)))*

*out-c(out,step3)*

*})*

*Final-data.frame(TraitRichness=out)*

*rownames(Final)-paste('Site',1:3)*

 *Final_Table-Final*

*}*

 *User_Defined(Data1,Data2)*

*Final_Table*


I hope this is what you need.

Best,
Heramb

On Tue, Sep 25, 2012 at 1:41 PM, Benjamin Gillespie gy...@leeds.ac.ukwrote:

 Hi,

 Thanks for helping me with this one.

 To save you time, the following is the code for the tables I uploaded as
 jpegs that you may not have received:


 dat1-data.frame(Species=paste(Species,1:3),Site1=c(5,NA,4),Site2=c(3,2,4),Site3=c(NA,5,NA))

 dat2-data.frame(Species=paste(Species,1:3),TraitType1=c(1,2,3),TraitType2=c(2,4,2),TraitType3=c(5,1,1))
 dat3-data.frame(Site=paste(Site,1:3),Trait_Richness=c(5,7,3))

 So,

 I have two matricies, dat1 and dat2.

 Dat1 is a species abundance matrix. Dat2 is a species trait matrix.

 I want to create dat3 through use of a script.

 Dat 3 is a count of unique traits observed at each site. i.e. at site 1,
 species 1 and 3 are present (ass seen in dat1). Species 1 has traits: 1, 2
 and 5 for trait types 1, 2 and 3 respectively. Species 3 has traits: 3, 2
 and 1 for trait types 1, 2 and 3 respectively.

 So, at site 1:

 For trait type 1, 2 unique traits were observed. For trait type 2, 1
 unique trait was observed (both species 1 and 3 were classed as 1) and
 for trait type 3, 2 unique traits (trait richness) were observed; thus,
 2+1+2=5.

 and so on... so at site 2, all three species were observed...

 For trait type 1, 3 unique traits were observed (1, 2, 3), for trait type
 2, 2 unique traits were observed (2, 4, 2) and for trait type 3, 2 unique
 traits were observed (5, 1, 1). So, for site 2, trait richness is 7 (3+2+2)
 traits.

 I hope this helps to explain, please let me know if you need any further
 information,

 Ben Gillespie
 Research Postgraduate

 School of Geography
 University of Leeds
 Leeds
 LS2 9JT

 Tel: +44(0)113 34 33345
 Mob: +44(0)770 868 7641
 http://www.geog.leeds.ac.uk/
 
 From: arun [smartpink...@yahoo.com]
 Sent: 24 September 2012 19:36
 To: Benjamin Gillespie
 Subject: Re: [R] Script to count unique values from two linked matricies

 HI Ben,

 Sorry,I couldn't understand how you counted the trait richness.  Could you
 elaborate?
 A.K.


 - Original Message -
 From: benrgillespie gy...@leeds.ac.uk
 To: r-help@r-project.org
 Cc:
 Sent: Monday, September 24, 2012 7:47 AM
 Subject: [R] Script to count unique values from two linked matricies

 I hope you can help with this one.

 I have two matricies:

 1. A species abundance matrix:

 http://r.789695.n4.nabble.com/file/n4643979/2species_matrix.jpg

 2. A species trait score matrix:

 http://r.789695.n4.nabble.com/file/n4643979/2trait_matrix.jpg

 The trait matrix lists trait scores for each species as listed in the
 species abundance matrix.

 I would like to create a script that would effectively count the unique
 traits (trait richness) for each site and produce an output like this:

 http://r.789695.n4.nabble.com/file/n4643979/trait_richness.jpg

 Firstly, is this possible in R? Secondly, if so, how would you go about
 writing a script to achieve my aim?

 Many thanks in advance, please let me know if you need further information.

 Ben Gillespie (Research Postgraduate)



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Script-to-count-unique-values-from-two-linked-matricies-tp4643979.html
 Sent from the R help mailing list archive at Nabble.com.

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

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


[[alternative HTML version deleted]]

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


Re: [R] scraping with session cookies

2012-09-23 Thread Heramb Gadgil
This may be because connection to the site via R is taking a lot of time. I
too faced this problem for the site Social-Mention.

I tried very primitive approach. I put the 'if' condition in the loop.

if(length(output)==0){getURL(site)
}else{continue with the code}

It might help you.

Best,
Heramb

On Fri, Sep 21, 2012 at 8:45 PM, CPV ceal...@gmail.com wrote:

 Thanks for your suggestion,
 The issue was resolved by Duncan's recommendation.

 Now I am trying to obtain data from different pages from the same site
 through a loop, however, the getURLContent keeps timing out, the odd part
 is that I can access to the link through a browser with no issues at all!!
 Any ideas why it keeps timing out? Also how can I keep the loop running
 after this error?

 Thanks again for your help!


 On Wed, Sep 19, 2012 at 11:36 PM, Heramb Gadgil 
 heramb.gad...@gmail.comwrote:

 Try this,


 library(RCurl)
 library(XML)

 site-
 http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18
 

 URL-getURL(site)

 Text=htmlParse(URL,asText=T)

 This will give you all the web dat in an HTML-Text format.

 You can use getNodeSet function to extract whatever links or texts that
 you want from that page.


 I hope this helps.

 Best,
 Heramb



 On Wed, Sep 19, 2012 at 10:26 PM, CPV ceal...@gmail.com wrote:

 Thanks again,

 I run the script with the postForm(site, disclaimer_action=I Agree) and
 it does not seem to do anything,
 the webpage is still the disclaimer page thus I am getting the error
 below
 Error in function (classes, fdef, mtable)  :
   unable to find an inherited method for function readHTMLTable, for
 signature NULL


 I also downloaded the latest version of RHTMLForms
 (omegahat-RHTMLForms-251743f.zip)
 and it does not seem to install correctly.. I used the code

 install.packages(C:/Users/cess/Downloads/omegahat-RHTMLForms-251743f.zip,
 type=win.binary, repos=NULL)

 Any suggestion of what could be causing these problems?


 On Wed, Sep 19, 2012 at 9:49 AM, Duncan Temple Lang 
 dtemplel...@ucdavis.edu
  wrote:

   You don't need to use the  getHTMLFormDescription() and
 createFunction().
  Instead, you can use the postForm() call.  However,
  getHTMLFormDescription(),
  etc. is more general. But you need the very latest version of the
 package
  to deal with degenerate forms that have no inputs (other than button
  clicks).
 
   You can get the latest version of the RHTMLForms package
   from github
 
git clone g...@github.com:omegahat/RHTMLForms.git
 
   and that has the fixes for handling the degenerate forms with
   no arguments.
 
 D.
 
  On 9/19/12 7:51 AM, CPV wrote:
   Thank you for your help Duncan,
  
   I have been trying what you suggested however  I am getting an error
 when
   trying to create the function fun- createFunction(forms[[1]])
   it says Error in isHidden I hasDefault :
   operations are possible only for numeric, logical or complex types
  
   On Wed, Sep 19, 2012 at 12:15 AM, Duncan Temple Lang 
   dtemplel...@ucdavis.edu wrote:
  
   Hi ?
  
   The key is that you want to use the same curl handle
   for both the postForm() and for getting the data document.
  
   site = u =
   
  
 
 http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18
   
  
   library(RCurl)
   curl = getCurlHandle(cookiefile = , verbose = TRUE)
  
   postForm(site, disclaimer_action=I Agree)
  
   Now we have the cookie in the curl handle so we can use that same
 curl
   handle
   to request the data document:
  
   txt = getURLContent(u, curl = curl)
  
   Now we can use readHTMLTable() on the local document content:
  
   library(XML)
   tt = readHTMLTable(txt, asText = TRUE, which = 1, stringsAsFactors =
  FALSE)
  
  
  
   Rather than knowing how to post the form, I like to read
   the form programmatically and generate an R function to do the
  submission
   for me. The RHTMLForms package can do this.
  
   library(RHTMLForms)
   forms = getHTMLFormDescription(u, FALSE)
   fun = createFunction(forms[[1]])
  
   Then we can use
  
fun(.curl = curl)
  
   instead of
  
 postForm(site, disclaimer_action=I Agree)
  
   This helps to abstract the details of the form.
  
 D.
  
   On 9/18/12 5:57 PM, CPV wrote:
   Hi, I am starting coding in r and one of the things that i want to
 do
  is
   to
   scrape some data from the web.
   The problem that I am having is that I cannot get passed the
 disclaimer
   page (which produces a session cookie). I have been able to collect
  some
   ideas and combine them in the code below but I dont get passed the
   disclaimer page.
   I am trying to agree the disclaimer with the postForm and write the
   cookie
   to a file, but I cannot do it succesfully
   The webpage cookies are written to the file but the value is
 FALSE...
  So
   any ideas of what I should do or what I am doing wrong with?
   Thank you for your help

Re: [R] (no subject)

2012-09-21 Thread Heramb Gadgil
Hi,

Another way of doing may be like this;

 a - c(d, d, j, f, e, g, f, f, i, g)
b - c(a, g, d, f, g, a, f, a, b, g)
ta - table(a)
tb - table(b)

Function-function(Tab1,Tab2){elements=sort(unique(c(names(ta),names(tb
OP=lapply(1:length(elements),FUN=function(x){a=which(elements[x]==names(Tab1))


b=which(elements[x]==names(Tab2))

if(length(a)0length(b)0){Tab1[a]+Tab2[b]

}else if (length(a)0){Tab1[a]

}else{Tab2[b]}

})

return(unlist(OP))

}

 Function(ta,tb)


Best,

Heramb


On Thu, Sep 20, 2012 at 10:40 PM, arun smartpink...@yahoo.com wrote:

 HI Stefan,
 Thanks for the solutions.

 Just to add 1 more:
 f.a-table(a); f.b-table(b)

 c(f.a[!names(f.a)%in%names(f.b)],f.b[!names(f.b)%in%names(f.a)],xtabs(f.a[names(f.a)%in%names(f.b)]+f.b[names(f.b)%in%names(f.a)]~
 names(f.a[names(f.a)%in%names(f.b)])))

 #e i j a b d f g
 #1 1 1 3 1 3 5 5

 A.K.



 - Original Message -
 From: Stefan Th. Gries stgr...@gmail.com
 To: mce...@lightminersystems.com
 Cc: r-help@r-project.org
 Sent: Thursday, September 20, 2012 10:57 AM
 Subject: [R] (no subject)

 From my book on corpus linguistics with R:

 # (10)   Imagine you have two vectors a and b such that
 a-c(d, d, j, f, e, g, f, f, i, g)
 b-c(a, g, d, f, g, a, f, a, b, g)

 # Of these vectors, you can create frequency lists by writing
 freq.list.a-table(a); freq.list.b-table(b)
 rm(a); rm(b)

 # How do you merge these two frequency lists without merging the two
 vectors first? More specifically, if I delete a and b from your
 memory,
 rm(a); rm(b)
 # how do you generate the following table only from freq.list.a and
 freq.list.b, i.e., without any reference to a and b themselves? Before
 you complain about this question as being unrealistic, consider the
 possibility that you generated the frequency lists of two corpora
 (here, a and b) that are so large that you cannot combine them into
 one (a.and.b-c(a, b)) and generate a frequency list of that combined
 vector (table(a.and.b)) ...
 joint.freqs
 a b d e f g i j
 3 1 3 1 5 5 1 1

 joint.freqs-vector(length=length(sort(unique(c(names(freq.list.a),
 names(freq.list.b)) # You generate an empty vector joint.freqs (i)
 that is as long as there are different types in both a and b (but note
 that, as requested, this information is not taken from a or b, but
 from their frequency lists) ...
 names(joint.freqs)-sort(unique(c(names(freq.list.a),
 names(freq.list.b # ... and (ii) whose elements have these
 different types as names.
 joint.freqs[names(freq.list.a)]-freq.list.a # The elements of the new
 vector joint.freqs that have the same names as the frequencies in the
 first frequency list are assigned the respective frequencies.

 joint.freqs[names(freq.list.b)]-joint.freqs[names(freq.list.b)]+freq.list.b
 # The elements of the new vector joint.freqs that have the same names
 as the frequencies in the second frequency list are assigned the sum
 of the values they already have (either the ones from the first
 frequency list or just zeroes) and the respective frequencies.
 joint.freqs # look at the result

 # Another shorter and more elegant solution was proposed by Claire
 Crawford (but uses a function which will only be introduced later in
 the book)
 freq.list.a.b-c(freq.list.a, freq.list.b) # first the two frequency
 lists are merged into a single vector ...
 joint.freqs-as.table(tapply(freq.list.a.b, names(freq.list.a.b),
 sum)) # ... and then the sums of all numbers that share the same names
 are computed
 joint.freqs # look at the result

 # The shortest, but certainly not memory-efficient way to do this
 involves just using the frequency lists to create one big vector with
 all elements and tabulate that.
 table(c(rep(names(freq.list.a), freq.list.a), rep(names(freq.list.b),
 freq.list.b))) # kind of cheating but possible with short vectors ...

 HTH,
 STG
 --
 Stefan Th. Gries
 ---
 University of California, Santa Barbara
 http://www.linguistics.ucsb.edu/faculty/stgries

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] SQL query with Multicore option on R -linux

2012-09-21 Thread Heramb Gadgil
This is what I think;

Hive internally distributes the data. If you have set up Hive on single
core it will fetch the query results from that core. If you have multi-core
system on which you have setup the Hive, it will search all the cores for
the query submitted and results would be compiled together for final
output. The query would remain the same no matter whther you have a single
core or multiple cores or a cluster of machines.

Please correct me if I am going the wrong way.

Best,
Heramb

On Thu, Sep 20, 2012 at 11:34 PM, Madana_Babu madana_b...@infosys.comwrote:

 Hi all,

 I have the following sql query that I am executing on a machine with single
 core. I want to know how can I execute the same sqery on a maching that is
 running with 4 cores. Please provide me the code.

 NEW_TABLE - rhive.query(SELECT A, B, COUNT(C) FROM TABLE_A WHERE
 A='01-01-2012')

 Also let me know how can I leverage only 2 / 3 cores of the machine.

 Regards,
 Madana



 --
 View this message in context:
 http://r.789695.n4.nabble.com/SQL-query-with-Multicore-option-on-R-linux-tp4643771.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] VarBrul in R

2012-09-21 Thread Heramb Gadgil
I do not know about the packages that you mentioned. I am trying to answer
your query based on the term socio-linguistic analytics.

There are packages like OpenNLP,OpenNLP.en,tm (Text Mining) that
might be of your interest.

Best,
Heramb

On Fri, Sep 21, 2012 at 1:04 AM, Trevor Jenkins bslwann...@gmail.comwrote:

 Several years ago there were R implementations of a socio-linguistics
 analysis method called Variable Rule Analysis namely rbrul and r-varb. Both
 neither of the sites listed (in the method's WikiPedia page
 http://en.wikipedia.org/wiki/Variable_rules_analysis ) appear to be online
 any more (one was at UPenn and the other at Indiana). Does anyone know a)
 whether the code for either or both of these implementations survives out
 there and b) is anyone maintaining these implementations?

 There are no listings for either of them at R Forge. And no listing for
 varbrul, which is the name for the original Fortran program. (Even that
 Fortran source can't be found online anymore.)

 Regards, Trevor.

  Re: deemed!

 [[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] issue accessing help files

2012-09-20 Thread Heramb Gadgil
Try this;

help(anova)

I have used this in R-2.14.1

It has worked fine for me. Hope it works for you as well.

Best,
Heramb

On Thu, Sep 20, 2012 at 1:40 AM, Rui Barradas ruipbarra...@sapo.pt wrote:

 Hello,

 I had a problem seeing the help pages with R 2.14.(0 or 1? I don't
 remember) on Windows 7.
 Then I realized that after a command like print, Rgui would first display
 an error message saying that the temp directory used by help didn't exist.
 The solution I've found was to manually create it whenever this happened.
 And to issue a print statement after a missed ?function one. Apparently the
 error message was waiting to be displayed somewhere.

 The problem was corrected with R 2.15.0 so I recommened you update your
 installation of R.

 Hope this helps,

 Rui Barradas
 Em 19-09-2012 19:19, Basil Iannone escreveu:

  Dear R-help community,

 I am unable to access help files when using the typical
 ?function.of.interest command.

 For example, if I type ?anova, Internet Explorer opens, but I am never
 connected to the usual page describing the nuances of the anova function.

 This is a new problem (just started occurring a few days ago). I am
 currently using R 2.14.1 on a Windows XP machine. As suggested by someone
 else on another list serve I have placed the session info below for a
 brief
 session where this occurred. NOTE: I am not trying to access any functions
 for libraries that are not active (for example, anova is in the default
 Stats package).

 Any suggestions on how to resolve this issue or any insights on why this
 may be occurring are greatly appreciated. Thanks in advance for your help.

  sessionInfo()

 R version 2.14.1 (2011-12-22)
 Platform: i386-pc-mingw32/i386 (32-bit)

 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

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

 loaded via a namespace (and not attached):
 [1] tools_2.14.1



 __**
 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] Importing a CSV file

2012-09-19 Thread Heramb Gadgil
Hi All,

I have used windows R.

We can also write like this:

A - read.csv(C:/Users/Anthi/Desktop/R/A.csv,header=TRUE)



On Wed, Sep 19, 2012 at 8:09 PM, Marc Schwartz marc_schwa...@me.com wrote:


 On Sep 19, 2012, at 9:26 AM, Rui Barradas ruipbarra...@sapo.pt wrote:

 
  Em 19-09-2012 15:01, Sarah Goslee escreveu:
  On Wed, Sep 19, 2012 at 9:53 AM, Frans Marcelissen
  frans.marcelis...@digipsy.nl wrote:
  Hi,
  Should'nt it be A - read.csv(C:Users\\Anthi\\Desktop\\R\\A.csv,
  header=TRUE)
  (c:\\ becomes c:\ In general I think it is better to use / and //)
  Frans
  No idea; I was copying the original poster's version. In this case, it
  would definitely be better to take advice on path construction from
  someone who uses Windows!
 
  I use Windows and the answer is no, the four backslashes don't make
 sense, because like Frans said, c:\\ becomes c:\
  (There is no such thing as c: --- c:\\).
 
  Rui Barradas

 Ahoy Mateys,

 Not to mention, creating file paths on Windows is an A FAQ:


 http://cran.r-project.org/bin/windows/base/rw-FAQ.html#R-can_0027t-find-my-file

 Savvy?

 Marc Schwartz

 P.S. It's International Talk Like a Pirate Day, which of course fits with
 a certain language we all hold dear. Somebody had to do it... ;-)


  Sarah
 
  -Oorspronkelijk bericht-
  Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org
 ]
  Namens Sarah Goslee
  Verzonden: woensdag 19 september 2012 15:44
  Aan: Anthi Oikonomou
  CC: r-h...@stat.math.ethz.ch
  Onderwerp: Re: [R] Importing a CSV file
 
  Hi,
 
  load() is for R's binary data files. You need to use read.csv(), as you
  tried, but probably with the complete path.
 
  A - read.csv(C:\\Users\\Anthi\\Desktop\\R\\A.csv, header=TRUE)
 
  Sarah
 
  On Wed, Sep 19, 2012 at 4:54 AM, Anthi Oikonomou 
 anthi.oi...@gmail.com
  wrote:
  Hi,
  I am trying to import csv file in R console I have saved my data in a
  file on the desktop named R and here is my problematic script
 
  load(C:\\Users\\Anthi\\Desktop\\R\\A.csv)
  Error: bad restore file magic number (file may be corrupted) -- no
  data loaded In addition: Warning message:
  file 'A.csv' has magic number ';Abra'
 Use of save versions prior to 2 is deprecated when I don t load and
  I ask to read here is the answer
  A -read.csv(A.csv,header=TRUE)
  Error in file(file, rt) : cannot open the connection In addition:
  Warning message:
  In file(file, rt) : cannot open file 'A.csv': No such file or
  directory
 
 
  Do you know what should I do?
  Thank you in advance

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

2012-09-19 Thread Heramb Gadgil
Try this,

library(RCurl)
library(XML)

site-
http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18


URL-getURL(site)

Text=htmlParse(URL,asText=T)

This will give you all the web dat in an HTML-Text format.

You can use getNodeSet function to extract whatever links or texts that
you want from that page.


I hope this helps.

Best,
Heramb


On Wed, Sep 19, 2012 at 10:26 PM, CPV ceal...@gmail.com wrote:

 Thanks again,

 I run the script with the postForm(site, disclaimer_action=I Agree) and
 it does not seem to do anything,
 the webpage is still the disclaimer page thus I am getting the error below
 Error in function (classes, fdef, mtable)  :
   unable to find an inherited method for function readHTMLTable, for
 signature NULL


 I also downloaded the latest version of RHTMLForms
 (omegahat-RHTMLForms-251743f.zip)
 and it does not seem to install correctly.. I used the code
 install.packages(C:/Users/cess/Downloads/omegahat-RHTMLForms-251743f.zip,
 type=win.binary, repos=NULL)

 Any suggestion of what could be causing these problems?


 On Wed, Sep 19, 2012 at 9:49 AM, Duncan Temple Lang 
 dtemplel...@ucdavis.edu
  wrote:

   You don't need to use the  getHTMLFormDescription() and
 createFunction().
  Instead, you can use the postForm() call.  However,
  getHTMLFormDescription(),
  etc. is more general. But you need the very latest version of the package
  to deal with degenerate forms that have no inputs (other than button
  clicks).
 
   You can get the latest version of the RHTMLForms package
   from github
 
git clone g...@github.com:omegahat/RHTMLForms.git
 
   and that has the fixes for handling the degenerate forms with
   no arguments.
 
 D.
 
  On 9/19/12 7:51 AM, CPV wrote:
   Thank you for your help Duncan,
  
   I have been trying what you suggested however  I am getting an error
 when
   trying to create the function fun- createFunction(forms[[1]])
   it says Error in isHidden I hasDefault :
   operations are possible only for numeric, logical or complex types
  
   On Wed, Sep 19, 2012 at 12:15 AM, Duncan Temple Lang 
   dtemplel...@ucdavis.edu wrote:
  
   Hi ?
  
   The key is that you want to use the same curl handle
   for both the postForm() and for getting the data document.
  
   site = u =
   
  
 
 http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18
   
  
   library(RCurl)
   curl = getCurlHandle(cookiefile = , verbose = TRUE)
  
   postForm(site, disclaimer_action=I Agree)
  
   Now we have the cookie in the curl handle so we can use that same curl
   handle
   to request the data document:
  
   txt = getURLContent(u, curl = curl)
  
   Now we can use readHTMLTable() on the local document content:
  
   library(XML)
   tt = readHTMLTable(txt, asText = TRUE, which = 1, stringsAsFactors =
  FALSE)
  
  
  
   Rather than knowing how to post the form, I like to read
   the form programmatically and generate an R function to do the
  submission
   for me. The RHTMLForms package can do this.
  
   library(RHTMLForms)
   forms = getHTMLFormDescription(u, FALSE)
   fun = createFunction(forms[[1]])
  
   Then we can use
  
fun(.curl = curl)
  
   instead of
  
 postForm(site, disclaimer_action=I Agree)
  
   This helps to abstract the details of the form.
  
 D.
  
   On 9/18/12 5:57 PM, CPV wrote:
   Hi, I am starting coding in r and one of the things that i want to do
  is
   to
   scrape some data from the web.
   The problem that I am having is that I cannot get passed the
 disclaimer
   page (which produces a session cookie). I have been able to collect
  some
   ideas and combine them in the code below but I dont get passed the
   disclaimer page.
   I am trying to agree the disclaimer with the postForm and write the
   cookie
   to a file, but I cannot do it succesfully
   The webpage cookies are written to the file but the value is FALSE...
  So
   any ideas of what I should do or what I am doing wrong with?
   Thank you for your help,
  
   library(RCurl)
   library(XML)
  
   site - 
  
  
 
 http://www.wateroffice.ec.gc.ca/graph/graph_e.html?mode=textstn=05ND012prm1=3syr=2012smo=09sday=15eyr=2012emo=09eday=18
   
  
   postForm(site, disclaimer_action=I Agree)
  
   cf - cookies.txt
  
   no_cookie - function() {
   curlHandle - getCurlHandle(cookiefile=cf, cookiejar=cf)
   getURL(site, curl=curlHandle)
  
   rm(curlHandle)
   gc()
   }
  
   if ( file.exists(cf) == TRUE ) {
   file.create(cf)
   no_cookie()
   }
   allTables - readHTMLTable(site)
   allTables
  
 [[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, 

Re: [R] eval(parse(...)) only once in a function

2012-09-17 Thread Heramb Gadgil
If you have a data frame df with a column JT

Try this one:
str - df$JT == 12

fun-function(str){b-eval(parse(text=str))
return(b)}

fun(str)

On Mon, Sep 17, 2012 at 11:57 AM, Christof Kluß ckl...@email.uni-kiel.dewrote:

 Hi

 I would like to have something like

 str - df$JT == 12

 fun - function(df) {

   b - eval(parse(str))

   return(b)
 }

 but for performance eval(parse(a)) should not be evaluated at each
 function call, but should work as

 fun - function(df) {

   b - df$JT == 12

   return(b)
 }

 Do you have an idea how I can implement this?

 Thx
 Christof

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] I want to send the vector a into the Object A.......

2012-09-17 Thread Heramb Gadgil
 A- get(a)

This will work fine

Best,
Heramb

On Mon, Sep 17, 2012 at 5:43 PM, Sri krishna Devarayalu Balanagu 
balanagudevaray...@gvkbio.com wrote:

 a=c(1,2,3)
 b=c(23, 24, 25)
 x=c(a, b)
 #if (length(x[1]) == 0) {cat(x[1] is having 3 elements)}

 Suppose I want to send the vector a into the Object A,
 um getting only a as the ouput for Object A but not getting required
 output as the vector with the elements 1, 2, 3 with  the following code

 A- x[1]

 How to code it?
 Can anyone help?
 Notice: The information contained in this electronic mail message is
 intended only for the use of the designated recipient. This message is
 privileged and confidential. and the property of GVK BIO or its affiliates
 and subsidiaries. If the reader of this message is not the intended
 recipient or an agent responsible for delivering it to the intended
 recipient, you are hereby notified that you have received this message in
 error and that any review, dissemination, distribution, or copying of this
 message is strictly prohibited. If you have received this communication in
 error, please notify us immediately by telephone
 +91-40-6692tel:+91-40-6692 and destroy any and all copies of this
 message in your possession (whether hard copies or electronically stored
 copies).

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