[R] Rscript silent failures with unmatched brackets

2015-02-26 Thread Luke Moryl
Hi all,

I’ve noticed that a script with unmatched brackets of any sort will fail
silently in Rscript—neither logging nor any output in the shell indicates
that anything went wrong. Example file to run in Rscript:

sink('/tmp/exampleoutfile')
a - 0
{
  print(a)

Replacing the ‘{‘ with any other symbol that must be matched (quotes,
parens, etc.) results in the same kind of silent failure. One workaround is
to use

echo source('myscript.R') | R --no-save --no-restore

from the command line but that’s a kludge. My apologies if this has been
brought up before, but doing a quick search I didn’t find anything, and to
me this seems like a significant bug.

Thanks  best,
Luke
​

[[alternative HTML version deleted]]

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

Re: [R] integrate with vector arguments

2015-02-26 Thread JS Huang
Hi,

  The following works.

 f2
function(z)
{
  f1 - function(t)
  {
z*t + z*t^2
  }
  return(f1)
}
 sapply(1:5,function(x)integrate(f2(x),0,1)$value)
[1] 0.83 1.67 2.50 3.33 4.17



--
View this message in context: 
http://r.789695.n4.nabble.com/integrate-with-vector-arguments-tp4703906p4703925.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] lmerTest - difflsmeans: LS means for Post-hoc analysis

2015-02-26 Thread Grigorios Georgolopoulos

Dear fellow R users,

I am trying to calculate the difference of the least square means from a 
lmer model which has a pretty much standard form of  Y ~ A*B + (1|C/D)


I am using the difflsmeans command from the lmerTest package but it 
returns the following error line:


Error in as.data.frame.default(VarCorr(model)) :
  cannot coerce class VarCorr.merMod to a data.frame

I also tried to do it manually but apparently to no avail.

I am using the lme4 v. 1.0-6 package on Linux  (if that helps).

Any suggestions how to override this?



Thanks in advance!
Grigorios

--
__
Grigorios Georgolopoulos
Research Assistant
Animal Ecology
Department of Ecology and Genetics (IEG)
Evolutionary Biology Centre (EBC)
Uppsala University
Norbyvägen 18d, SE-752 36
Uppsala, Sweden
Email: georgolopoulosgg...@hotmail.com, grigorios.georgolopou...@ebc.uu.se

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


[R] mle

2015-02-26 Thread pari hesabi
Hello,
I am going to estimate the parameter of the count model: pr(N=n)= 
integration{B(x, alpha)-C(x,alpha)} by maximum likelihood estimation. 
n-c(0,1,2,3)   and   F- (0,3,4,5) are the vectors of values and observed 
frequency respectively. The function C(x,alpha) is not defined for n=0, but 
suppose C(x,alpha)=1 when n=0.  When I want to insert this exception in the 
following loop, I don't receive reasonable estimate.
pari (alpha){
nloglik- function(alpha){
B-function(x,k){}
C-function(x,k){}
A-function(x){
s-rep(0,length(x))
s-s+ C(x,k) 
s- s+B(x,k) 
}
s
}
d-0
for (n in seq(along=F)){
 lik-integrate(A,0,1)$value
d- d - F[n]*log(lik)}}
d }
F-  (0,3,4,5)
n-length(F)
mle (nloglik, start=list(alpha=alpha)
}     
This program gives the answer when n= 1,2,3. But for n=0 I get error, I have to 
consider the exception : C(x,alpha)=1.  
Does anybody know where I need to put the exception in the program? ( For 'if' 
loops, I don't get reasonable results) 
I would appreciate any help
Best Regards,  
    

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

Re: [R] Saving Mean Relative Difference from all.equal()

2015-02-26 Thread David Winsemius

 On Feb 26, 2015, at 2:02 PM, Scott Colwell scolw...@uoguelph.ca wrote:
 
 I think I have one solution. Not very pretty though. Relies on the text not
 changing at all.
 
 as.numeric(gsub(Mean relative difference: , ,
 all.equal(cov2cor(ITEMCOV),cor(item.data))[2]))
 
 Is there a better way?
 

`all.equal` is a generic function and it appears you are interested in 
`all.equal.numeric`. Not sure if it’s “better” but you could fairly easily hack 
the all.equal.numeric function to replace this code (near the end of the 
function code) :

if (is.na(xy) || xy  tolerance) 
msg - c(msg, paste(Mean, what, difference:, format(xy)))

,,, with:

if (is.na(xy) || xy  tolerance) 
msg -  xy

(probably best to make it have a different name and not use 'all.equal' to name 
it.)

When it did that I got this as a result:

 all.EQ( seq(1,2, by=0.1)*10, 10:20)
[1] TRUE
 all.EQ( seq(1,2, by=0.11)*10, 10:20)
[1] Numeric: lengths (10, 11) differ
 all.EQ(seq(1,2, by=0.11)*10, 10:19)
[1] 0.03225806

— 


David Winsemius, MD
Alameda, CA, USA

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

Re: [R] Schedule R function/Code to run at specific time

2015-02-26 Thread macfire
I have a problem with statistics, I think this forum is not the right
option, but I'm running out resolution to my problem, so I thought I expose
you here so someone could help me.
Realized a certain amount of tests in different groups, this assessment had
different weights, and the groups were formed by the different amount of
people. I thought of calculating the average to see how much each person
contributed to the total amount of the assessment. What I would like to
know if there is another way I use the absolute number and the average for
quantifying group was better.
Table

 Group

Absolute Points

Unit

Average

A

700

35

20

B

500

20

25

C

900

150

6

D

300

10

30

Att..
Mestre. Marcelo Alves Costa
Grupo de Estudo e Pesquisa em Desenvolvimento e Aprendizagem Motora
(GEPEDAM)
Centro Universitário Filadélfia
(43) 9646-1071


2015-02-26 16:08 GMT-03:00 Doran, Harold hdo...@air.org:

 Is there functionality within R proper, without having to revert to the
 OS, allowing a function or a portion of an R script to be run at a defined
 time? My google searches haven't provided much other than one at the link
 below which relies on an OS.

 Thanks,
 Harold

 https://tgmstat.wordpress.com/2013/09/11/schedule-rscript-with-cron/

 [[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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

Re: [R] integrate with vector arguments

2015-02-26 Thread David Winsemius

 On Feb 26, 2015, at 1:49 PM, marKo mton...@ffri.hr wrote:
 
 v1-c(1:5)
 v2-c(1:5)
 
 f1-function (x) {v1*x+v2*x^2}
 
 The problem is that integrate(f1, 0, 1) does not work.
 I does not, even if a pas the arguments (v1, v2)
 
 f1-function (x, v1, v2) {v1*x+v2*x^2}
 
 or if i try to vectorize the function
 
 f1-Vectorize(function(x, v1, v2){v1*x+v2*x^2},
 vectorize.args=c(v1, v2))
 
 integrate(f1, 0, 1) gives an error:


 f1-function (X, Y) integrate( function(x) {X*x+Y*x^2}, 0, 1)$value
 fV-Vectorize(f1)
 outer( X=v1,Y=v2, FUN= fV)
  [,1] [,2] [,3] [,4] [,5]
[1,] 0.833 1.17  1.5 1.83 2.17
[2,] 1.333 1.67  2.0 2.33 2.67
[3,] 1.833 2.17  2.5 2.83 3.17
[4,] 2.333 2.67  3.0 3.33 3.67
[5,] 2.833 3.17  3.5 3.83 4.17

— 
David Winsemius, MD
Alameda, CA, USA

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

Re: [R] Summing certain values within columns that satisfy a certain condition

2015-02-26 Thread Don McKenzie
Kate — here is a transparent solution (tested but without NA treatment). 
Doubtless there are cleverer faster ones, which later posters will present.

HTH

# example with four columns and 20 rows
nrows - 20

A - sample(c(1:100), nrows, replace=T)
B - sample(c(1:100), nrows, replace=T)
C - sample(c(1:100), nrows, replace=T)
D - sample(c(1:100), nrows, replace=T)

locs - 
c(c(1:nrows)[A==max(A)],c(1:nrows)[B==max(B)],c(1:nrows)[C==max(C)],c(1:nrows)[D==max(D)])

mat1 - matrix(rep(0,4*nrows),nrows,4)
for (i in 1:4)
mat1[,i][locs[i]] - 1
SUM - rowSums(mat1)


 On Feb 26, 2015, at 12:23 PM, Kate Ignatius kate.ignat...@gmail.com wrote:
 
 Hi,
 
 Supposed I had a data frame like so:
 
 A B C D
 0 1 0 7
 0 2 0 7
 0 3 0 7
 0 4 0 7
 0 1 0 0
 0 0 0 0
 0 0 0 0
 0 0 0 0
 0 0 1 5
 0 5 1 5
 0 4 1 5
 0 8 4 7
 0 0 3 0
 0 0 3 4
 0 0 3 4
 0 0 0 5
 0 2 0 6
 0 0 4 0
 0 0 4 0
 0 0 4 0
 
 For each row, I want to count how many max column values appear to
 adventurely get the following outcome, while ignoring zeros and N/As:
 
 A B C D Sum
 0 1 0 7 1
 0 2 0 7 1
 0 3 0 7 1
 0 4 0 7 1
 0 1 0 0 0
 0 0 0 0 0
 0 0 0 0 0
 0 0 0 0 0
 0 0 1 5 0
 0 5 1 5 0
 0 4 1 5 0
 0 8 4 7 3
 0 0 3 0 0
 0 0 3 4 0
 0 0 3 4 0
 0 0 0 5 0
 0 2 0 6 0
 0 0 4 0 1
 0 0 4 0 1
 0 0 4 0 1
 
 I've used the following code but it doesn't seem to work (my sum
 column column is all 1s):
 
 (apply(df,1, function(x)  (sum(x %in% c(pmax(x))
 
 Is this code too simple?
 
 Thanks!
 
 K.
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



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

Re: [R] Best Mac for R

2015-02-26 Thread Thomas Adams
Dan,

FWIW, I have basically the system you describe, except a larger HD — I'm
quite happy, but I'm a biased Mac user, although I love my Ubuntu Linux
machine as well… One can bring any machine to its knees, so there is the
element of expectations. A MacBook Pro stacks up as well or better compared
to a similarly configured windows box. The thing is, IMO, there are at
least two very good virtual machines to run MS-Windows on if the need
arises (as well as Apple's 'Boot Camp') and, I believe, since the core Mac
OS is essentially UNIX/Linux you have all that capability natively as well.

Tom

On Thu, Feb 26, 2015 at 12:50 AM, Dan Murphy chiefmur...@gmail.com wrote:

 I am possibly in the market for a new laptop. Predominantly a Windows
 user, I owned a macbook pro 10 years ago and am considering going that
 route again. Does the standard advice still hold: Get the most
 powerful processor (i7), most ram (16GB), and largest internal storage
 (512GB), if affordable?
 thanks,
 dan

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


[[alternative HTML version deleted]]

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

Re: [R] aggregating variables (sum within groups)

2015-02-26 Thread William Dunlap
 Even though I was looking in several r-books
 I could not find a suitable function to this problem

Which R books did you look through?

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Feb 26, 2015 at 4:02 AM, David Studer stude...@gmail.com wrote:

 Hello everybody!

 I have a (probabely very easy) problem. Even though I was looking in
 several r-books
 I could not find a suitable function to this problem, that's why I hope
 that someone here
 could help me:

 # Sample data:
 group-c(A,A,A,B,B,C,C,C)
 var1-c(1,0,0,1,1,0,NA,1)
 var2-c(0,1,NA,0,1,1,0,0)
 testdata-data.frame(group, var1, var2)

 Now, I'd like to generate two aggregated variables:

 testdata$x- ???   should count the sum of var1 within each group (=4)
 testdata$y- ???   should count the sum of var2 within each group (=3)

 Therefore I am looking for a function like ave() which does not calculate
 the mean value but a sum.

 Thank you for any hints!

 David

 [[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


[R] extract file name from a path string

2015-02-26 Thread Luigi Marongiu
Dear all,
what code should I write in order to extract the file name from a give
path? Let's say that I want to get the file my file.xls which is in
the directory/folder My documents; since I work both with Windows
and Linux, the paths I am looking at are in the format:

path.windows-\\home$\\lm667\\My Documents\\my file.xls
path.linux-/home/My Documents/my file.xls

I used two words for the file name because sometimes the file names
have multiple words rather than a single one separated by capitals,
. or _.
The code should now get the file name, which is included between \\
(or /) and .xls but I don't know what regular expression will do
the trick.
Once the file name has been assigned to a vector, it should be easy to
remove it from the path.windows/.linux and obtain a vector with the
path on its own.
Essentially the output should be as follows:

 file.name
[1] my file.xls
 path.w
[1] \\home$\\lm667\\My Documents\\
 path.l
[1] /home/My Documents/

Thank you,
Luigi

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


Re: [R] Dummy variable in ARIMA

2015-02-26 Thread Mikael Olai Milhøj
Hi.

First of all, thx. But when using in arima(...xreg=fact,...) then fact
should be a vector and not a factor variable? Maybe I should have been more
clear in my first mail, sorry. Or else I have to dig deeper into factors.


/Mikael

On Thu, Feb 26, 2015 at 5:17 PM, Bert Gunter gunter.ber...@gene.com wrote:

 Inline.

 Cheers,
 Bert

 Bert Gunter
 Genentech Nonclinical Biostatistics
 (650) 467-7374

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




 On Thu, Feb 26, 2015 at 8:02 AM, Mikael Olai Milhøj
 mikaelmil...@gmail.com wrote:
  Hi all
 
  I have been searching on the web in vain. I want to include a dummy
  variable in my ARIMA model. Let's say that I want to make an AR(1) model
  for X including a dummy variable which should be 1 for observation 4,5,6
  and zero otherwise (let's say that there is 50 observations in total).
 How
  do I make that?

 You don't, really.

 1. Go through an R tutorial so that you understand the concept of
 factors and how they are used in R modeling.

 2. fact - factor( (1:50) %in% (4:6))

 Cheers,
 Bert

 
  This does the trick but seems inefficient: dummy-c(rep(0,3), rep(1,3),
  rep(0,44))
 
  Thx in advance
 
  Best regards
  /Mikael
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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

Re: [R] Dummy variable in ARIMA

2015-02-26 Thread Bert Gunter
Inline.

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

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




On Thu, Feb 26, 2015 at 8:02 AM, Mikael Olai Milhøj
mikaelmil...@gmail.com wrote:
 Hi all

 I have been searching on the web in vain. I want to include a dummy
 variable in my ARIMA model. Let's say that I want to make an AR(1) model
 for X including a dummy variable which should be 1 for observation 4,5,6
 and zero otherwise (let's say that there is 50 observations in total). How
 do I make that?

You don't, really.

1. Go through an R tutorial so that you understand the concept of
factors and how they are used in R modeling.

2. fact - factor( (1:50) %in% (4:6))

Cheers,
Bert


 This does the trick but seems inefficient: dummy-c(rep(0,3), rep(1,3),
 rep(0,44))

 Thx in advance

 Best regards
 /Mikael

 [[alternative HTML version deleted]]

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

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

[R] Dummy variable in ARIMA

2015-02-26 Thread Mikael Olai Milhøj
Hi all

I have been searching on the web in vain. I want to include a dummy
variable in my ARIMA model. Let's say that I want to make an AR(1) model
for X including a dummy variable which should be 1 for observation 4,5,6
and zero otherwise (let's say that there is 50 observations in total). How
do I make that?

This does the trick but seems inefficient: dummy-c(rep(0,3), rep(1,3),
rep(0,44))

Thx in advance

Best regards
/Mikael

[[alternative HTML version deleted]]

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


Re: [R] aggregating variables (sum within groups)

2015-02-26 Thread Jeff Newmiller
For the record, the ave function in R can apply any function you specify, not 
just mean. The primary feature of ave is that it does not collapse the rows 
like aggregate does. Choose among them according to how you want the output to 
be organized.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On February 26, 2015 4:02:49 AM PST, David Studer stude...@gmail.com wrote:
Hello everybody!

I have a (probabely very easy) problem. Even though I was looking in
several r-books
I could not find a suitable function to this problem, that's why I hope
that someone here
could help me:

# Sample data:
group-c(A,A,A,B,B,C,C,C)
var1-c(1,0,0,1,1,0,NA,1)
var2-c(0,1,NA,0,1,1,0,0)
testdata-data.frame(group, var1, var2)

Now, I'd like to generate two aggregated variables:

testdata$x- ???   should count the sum of var1 within each group (=4)
testdata$y- ???   should count the sum of var2 within each group (=3)

Therefore I am looking for a function like ave() which does not
calculate
the mean value but a sum.

Thank you for any hints!

David

   [[alternative HTML version deleted]]

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

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


Re: [R] Save a list of list and search for values

2015-02-26 Thread jim holtman
You store it as a list of lists and can then use the lapply function
to navigate for values.

result - lapply(1:1, function(x){
mix(param[x])  # whatever your call to 'mix' is with some data
})





Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Thu, Feb 26, 2015 at 9:27 AM, Alaios via R-help r-help@r-project.org wrote:
 Dear all,in my code I am using the mix() function that returns results in a 
 list. The result looks like
 List of 10
  $ parameters  :'data.frame':   2 obs. of  3 variables:
   ..$ pi   : num [1:2] 0.77 0.23
   ..$ mu   : num [1:2] -7034 162783
   ..$ sigma: num [1:2] 20235 95261
  $ se  :'data.frame':   2 obs. of  3 variables:
   ..$ pi.se   : num [1:2] 0.0423 0.0423
   ..$ mu.se   : num [1:2] 177 12422
   ..$ sigma.se: num [1:2] 1067 65551
  $ distribution: chr norm
  $ constraint  :List of 8
   ..$ conpi   : chr NONE
   ..$ conmu   : chr NONE
   ..$ consigma: chr NONE
   ..$ fixpi   : NULL
   ..$ fixmu   : NULL
   ..$ fixsigma: NULL
   ..$ cov : NULL
   ..$ size: NULL
  $ chisq   : num 28
  $ df  : num 5
  $ P   : num 3.67e-05
  $ vmat: num [1:5, 1:5] 1.79e-03 -3.69e-01 -1.17e+02 2.95e+01 
 -2.63e+03 ...
  $ mixdata :Classes ‘mixdata’ and 'data.frame': 11 obs. of  2 
 variables:
   ..$ X: num [1:11] 1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 
 1e+05 ...
   ..$ count: int [1:11] 993 137 82 30 21 5 7 14 21 2 ...
  $ usecondit   : logi FALSE
  - attr(*, class)= chr mix

 In my code I am trying around 10.000 fit (and each of these fits returns the 
 list above) and I want to keep those in a way that later on I would be able 
 to search inside all the lists.For example I would like to find inside those 
 10.000 lists which one has the smallest $chisq value. What would be a 
 suitable way to implement that in R? Luckily I am working in a computer with 
 a lot of ram so storing 10.000 lists temporary in memory before saving to 
 disk would not be a problem.
 What would you suggest me?
 RegardsAlex

 [[alternative HTML version deleted]]

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

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

Re: [R] covert entire dataset to numeric while persuing percentage values

2015-02-26 Thread JS Huang
The following data.frame x as one column named Percent.

 x
  Percent
1 10%
2 20%
3 30%
 as.numeric(substr(x$Percent,1,nchar(x$Percent)-1))
[1] 10 20 30



--
View this message in context: 
http://r.789695.n4.nabble.com/covert-entire-dataset-to-numeric-while-persuing-percentage-values-tp4703862p4703880.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] covert entire dataset to numeric while persuing percentage values

2015-02-26 Thread Jeff Newmiller
I think you are getting ahead of yourself.

You use the term dataset, which is colloquial and not precise. The read.csv 
function returns a data.frame, in which each column can have its own storage 
mode (type). Most data.frames do not have all columns of the same type... if 
they were you might consider converting to a matrix, but with different units 
in each column that would not be a good idea in this case.

From your str output, I think you need to skip loading the second and third 
lines of your file in the first place, since it looks like they consist of 
unit strings. Something like:

fname - file.choose()
xelements - read.csv( fname, header=FALSE, skip=3, stringsAsFactors=FALSE)

but this does not get your column names. One way to get those would be:

names( xelements ) - names( read.csv( fname ) )

As for the percent signs, you can convert those with something like:

xelements$ X..NG.by.Energy - as.numeric( sub( %. , xelements$ 
X..NG.by.Energy ) )

In the future, please don't post in HTML format, as it just leads to confusion 
on this plain text mailing list. Read the Posting Guide for other warnings, and 
let us follow your journey to your problem with a reproducible example. There 
are various discussions online of what is reproducible.. you might start with 
[1]. Note that the read.csv function supports a text argument that lets you 
embed a sample of lines from your file into your example so we could 
troubleshoot your input process better if that is where your problem is.

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

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

On February 26, 2015 1:06:03 AM PST, Methekar, Pushpa (GE Transportation, 
Non-GE) pushpa.methe...@ge.com wrote:
Hi ,
I am little confused  about how to covert entire dataset to numeric .
As I read data like..
Xelements =read.csv(file. Choose(),header = T, stringsAsFactors=FALSE)
str(xelements )

 str(xelements)
'data.frame':  731 obs. of  4 variables:
$ Engine.Speed : chr  rpm ES rpm 1049 ...
$ X..NG.by.Energy  : chr   % NG by Energy % 0% ...
$ Int.Mfld.Temp: chr   Int Mfld Temp �C 49 ...
$ Cmd.Advance.Angle: chr   Cmd Advance Angle �BTDC 13.8 ...

I have second column as in 0%, 10%, In percentage value ,
Whenever I am going to covert whole dataset its showing NA introduced
.second column going to become NA.
Converting separately I would be successful .


 xelements$Engine.Speed - as.numeric(xelements$Engine.Speed)

Warning message:

NAs introduced by coercion

 xelements$X..NG.by.Energy-
as.numeric(sub(%,,xelements$X..NG.by.Energy))/100

Warning message:

NAs introduced by coercion

 xelements$Int.Mfld.Temp- as.numeric(xelements$Int.Mfld.Temp)

Warning message:

NAs introduced by coercion

 xelements$Cmd.Advance.Angle- as.numeric(xelements$Cmd.Advance.Angle)

Warning message:

NAs introduced by coercion

But I want to covert whole dataset at a time. I want to write function
which will help me to solve this problem  .


xelements - data.frame(sapply(xelements, function(x)
as.numeric(as.character(x
sapply(xelements, class)

but it won't be able to covert percentage value  like 10%, 20%
please do help me if you know the way. Thank you

   [[alternative HTML version deleted]]





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

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

Re: [R] format selected columns in dataframe as character

2015-02-26 Thread MacQueen, Don
Of course you could have created them as character vectors in the first
place:

dfx - data.frame(
  group = c(rep('A', 8), rep('B', 15), rep('C', 6)),
  sex = sample(c(M, F), size = 29, replace = TRUE),
  age = runif(n = 29, min = 18, max = 54),
  stringsAsFactors=FALSE
  )


But if that is not possible in your context, then I would suggest this:

for (nm in names(dfx))
   if (is.factor(dfx[[nm]])) dfx[[nm]] - as.character(dfx[[nm]])

It's clear and simple.



-- 
Don MacQueen

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





On 2/26/15, 2:08 AM, Alain D. dialva...@yahoo.de wrote:

Dear R-List,
 
#I have a df with the first two cols formatted as factor.
 
dfx - data.frame(
group = c(rep('A', 8), rep('B', 15), rep('C', 6)),
sex = sample(c(M, F), size = 29, replace = TRUE),
age = runif(n = 29, min = 18, max = 54))
 
# now I want to format both factor VARs as character
# I tried
 
factor.id-names(dfx[sapply(dfx,is.factor)])
chr.names-which(names(dfx)%in% factor.id)
 
dfx[ , chr.names]-as.character(dfx[ , chr.names])
# which gives me
str(dfx)
'data.frame': 29 obs. of 3 variables: $ group: chr c(1, 1, 1, 1, 1, 1,
1, 1, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3) c(2, 2, 1,
1, 1,
1, 2, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2)
c(1,
1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
3, 3, 3,
3) c(2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1,
1, 1,
1, 1, 2, 2, 2) ... $ sex : chr c(2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 2,
2, 2,
1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2) c(1, 1, 1, 1, 1, 1, 1, 1, 2,
2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3) c(2, 2, 1, 1, 1,
1, 2,
1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2) c(1,
1, 1,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
3, 3)
... $ age : num 38.5 18 33.5 26 22.5 ...
 
#though I was hoping for something like
 
'data.frame': 29 obs. of  3 variables:
$ group: chr  A A A A ...
$ sex  : chr  M F F M ...
$ age  : num  21.3 35.2 53.8 21 23.6 ...

#What is wrong with my code?
#Thank you for any help

Best wishes 

Alain
 
 
 
   [[alternative HTML version deleted]]

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

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


Re: [R] library(multcomp) does not work for loading Tukey

2015-02-26 Thread Michael Dewey

Dear Xavier

See below for comments

On 26/02/2015 11:20, CHIRIBOGA Xavier wrote:

Dear colleagues,



For Tukey, I tried to load the function with



library(multcomp) but again a message says:



Error in library(multcomp) : any package called ‘multcomp’ has been found




I suspect you translated this? I would have thought the message in 
English would have been

there is no package called 'multcomp'
which gives you the clue that you should install it first
?install.packages
is your friend

Michael






Thanks for ur help,

Xavier

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


-
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2015.0.5645 / Virus Database: 4299/9183 - Release Date: 02/26/15





--
Michael
http://www.dewey.myzen.co.uk

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


Re: [R] Processing key_column, begin_date, end_date in R

2015-02-26 Thread Jeff Newmiller
Here is another way. Have not tested for large scale efficiency, but if you 
convert dta to a data.table that might improve things.

library(dplyr)
dta - read.csv( text=
key_column,begin_date,end_date
123456,2013-01-01,2014-01-01
123456,2013-07-01,2014-07-01
789102,2012-03-01,2014-03-01
789102,2015-02-01,2016-02-01
789102,2015-02-06,2016-02-06
789102,2015-02-28,2015-03-31
789102,2015-04-30,2015-05-31
, as.is=TRUE)
( dta
%% mutate( begin_date = as.Date( begin_date ),
end_date = as.Date( end_date ) )
%% arrange( key_column, begin_date )
) - dta

mkgp - function( begin_date, cend ) {
  ix - c( TRUE, cend[ -length( begin_date ) ]  begin_date[ -1 ] )
  cumsum( ix )
}

result - ( dta
  %% group_by( key_column )
  %% mutate( cend = as.Date( cummax( as.numeric( end_date ) )
, origin=1970-01-01 )
  , gp = mkgp( begin_date, cend )
  )
  %% ungroup
  %% group_by( key_column, gp )
  %% summarise(  begin_date = begin_date[ 1 ]
, end_date = cend[ length( cend ) ]
)
  %% ungroup
  %% select( -gp )
  %% as.data.frame
  )
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On February 25, 2015 1:18:58 PM PST, Matt Gross gro...@gmail.com wrote:
Hi,

I am trying to process a large dataset in R.  The dataset contains the
following three columns:

key_column - a unique key identifier
begin_date - the start date of the active period
end_date - the end date of the active period


Example data is here:

key_column,begin_date,end_date
123456,2013-01-01,2014-01-01
123456,2013-07-01,2014-07-01
789102,2012-03-01,2014-03-01
789102,2015-02-01,2016-02-01
789102,2015-02-06,2016-02-06

I want to build a condensed table of key_column and begin_date's and
end_date's.  As you can see in the example data above, some begin and
end
date periods overlap with begin_date and end_date pairs for the same
key_column.  In situations where overlap exists I want to have one
record
for the key_column with the min(begin_date) and the max(end_date).

Can anyone help me build the commands to process this data in R?

Thanks,
Matt

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


[R] retrieving protein for swissport

2015-02-26 Thread Ron Flatau
It's possible to retrieve protein for swissport by protein name??

I try using seqinr and query but i didnt find  a way to get all protein
that named Delta 9 acyl CoA desaturase.

If some one have an idea i be glad :P

thank you all

ᐧ

[[alternative HTML version deleted]]

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

Re: [R] Save a list of list and search for values

2015-02-26 Thread Duncan Murdoch

On 26/02/2015 9:27 AM, Alaios via R-help wrote:

Dear all,in my code I am using the mix() function that returns results in a 
list. The result looks like
List of 10
  $ parameters  :'data.frame':   2 obs. of  3 variables:
   ..$ pi   : num [1:2] 0.77 0.23
   ..$ mu   : num [1:2] -7034 162783
   ..$ sigma: num [1:2] 20235 95261
  $ se  :'data.frame':   2 obs. of  3 variables:
   ..$ pi.se   : num [1:2] 0.0423 0.0423
   ..$ mu.se   : num [1:2] 177 12422
   ..$ sigma.se: num [1:2] 1067 65551
  $ distribution: chr norm
  $ constraint  :List of 8
   ..$ conpi   : chr NONE
   ..$ conmu   : chr NONE
   ..$ consigma: chr NONE
   ..$ fixpi   : NULL
   ..$ fixmu   : NULL
   ..$ fixsigma: NULL
   ..$ cov : NULL
   ..$ size: NULL
  $ chisq   : num 28
  $ df  : num 5
  $ P   : num 3.67e-05
  $ vmat: num [1:5, 1:5] 1.79e-03 -3.69e-01 -1.17e+02 2.95e+01 
-2.63e+03 ...
  $ mixdata :Classes ‘mixdata’ and 'data.frame': 11 obs. of  2 
variables:
   ..$ X: num [1:11] 1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 
1e+05 ...
   ..$ count: int [1:11] 993 137 82 30 21 5 7 14 21 2 ...
  $ usecondit   : logi FALSE
  - attr(*, class)= chr mix

In my code I am trying around 10.000 fit (and each of these fits returns the 
list above) and I want to keep those in a way that later on I would be able to 
search inside all the lists.For example I would like to find inside those 
10.000 lists which one has the smallest $chisq value. What would be a suitable 
way to implement that in R? Luckily I am working in a computer with a lot of 
ram so storing 10.000 lists temporary in memory before saving to disk would not 
be a problem.
What would you suggest me?


If all of the lists have the same components, then it would be 
convenient to convert them into a big matrix or dataframe, with one row 
per fit.  It would need to be a dataframe if you include character data 
along with the numbers, but a matrix would be faster, if it's only 
numbers that you need.  You'd use code like this to produce the matrix:


results - matrix(NA_real_, 1, ncols =  however many you keep )
for (i in 1:1) {
  fit -  code to get the fit object 
  results[i,] - with(fit, c(parameters$pi, parameters$mu, 
parameters$sigma,   ..  fill in the rest ..)

}

Duncan Murdoch

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

Re: [R] format selected columns in dataframe as character

2015-02-26 Thread JS Huang
Try as.character like the following shows.

 dfx - data.frame( 
+   group = c(rep('A', 8), rep('B', 15), rep('C', 6)), 
+   sex = sample(c(M, F), size = 29, replace = TRUE), 
+   age = runif(n = 29, min = 18, max = 54))
 dfx
   group sex age
1  A   M 41.35554346
2  A   F 47.73245469
3  A   F 42.97870796
4  A   M 52.51180396
5  A   F 46.72228944
6  A   M 48.64668630
7  A   M 36.07894452
8  A   M 26.96805121
9  B   M 30.67208692
10 B   M 45.09322672
11 B   M 31.86601692
12 B   F 53.28861780
13 B   M 27.74271305
14 B   F 52.05845066
15 B   F 18.94612430
16 B   M 48.66673378
17 B   F 53.07004762
18 B   F 48.15222416
19 B   M 32.17737802
20 B   M 37.02122907
21 B   M 39.31442046
22 B   M 27.90392578
23 B   M 44.70562356
24 C   F 53.43127126
25 C   M 49.85362283
26 C   M 40.40779822
27 C   F 31.41189728
28 C   M 47.49351314
29 C   M 46.34333618
 summary(dfx)
 group  sex age  
 A: 8   F:10   Min.   :18.94612  
 B:15   M:19   1st Qu.:32.17738  
 C: 6  Median :44.70562  
   Mean   :41.46947  
   3rd Qu.:48.64669  
   Max.   :53.43127  
 dfx$group - *as.character*(dfx$group)
 summary(dfx)
group   sex age  
 Length:29  F:10   Min.   :18.94612  
 Class :character   M:19   1st Qu.:32.17738  
 Mode  :character  Median :44.70562  
   Mean   :41.46947  
   3rd Qu.:48.64669  
   Max.   :53.43127  
 dfx
   group sex age
1  A   M 41.35554346
2  A   F 47.73245469
3  A   F 42.97870796
4  A   M 52.51180396
5  A   F 46.72228944
6  A   M 48.64668630
7  A   M 36.07894452
8  A   M 26.96805121
9  B   M 30.67208692
10 B   M 45.09322672
11 B   M 31.86601692
12 B   F 53.28861780
13 B   M 27.74271305
14 B   F 52.05845066
15 B   F 18.94612430
16 B   M 48.66673378
17 B   F 53.07004762
18 B   F 48.15222416
19 B   M 32.17737802
20 B   M 37.02122907
21 B   M 39.31442046
22 B   M 27.90392578
23 B   M 44.70562356
24 C   F 53.43127126
25 C   M 49.85362283
26 C   M 40.40779822
27 C   F 31.41189728
28 C   M 47.49351314
29 C   M 46.34333618
 dfx$sex - *as.character*(dfx$sex)
 summary(dfx)
group   sex age  
 Length:29  Length:29  Min.   :18.94612  
 Class :character   Class :character   1st Qu.:32.17738  
 Mode  :character   Mode  :character   Median :44.70562  
   Mean   :41.46947  
   3rd Qu.:48.64669  
   Max.   :53.43127  
 class(dfx$group)
[1] character
 dfx$group
 [1] A A A A A A A A B B B B B B B B B B
B B B B B C
[25] C C C C C
 class(dfx$sex)
[1] character
 dfx$sex
 [1] M F F M F M M M M M M F M F F M F F
M M M M M F
[25] M M F M M
 



--
View this message in context: 
http://r.789695.n4.nabble.com/format-selected-columns-in-dataframe-as-character-tp4703863p4703878.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R-es] DUDA LLENAR MATRIZ CREADA

2015-02-26 Thread rubenfcasal

Hola David,

Puedes hacer como ya comentaron en las otras respuestas. Pero por 
si sirve de utilidad, pego  al final parte de un código que empleo para 
ilustrar la repetición de contrastes en simulación.


Está con un bucle y guardando en vectores, si se quisiera modificar 
para obtener una matriz y emplear lapply (o sapply), tendrías que crear 
una función del tipo:
fun.test - function(muestra) 
unlist(test(muestra)[c('statistic','p.value')])
reemplazando test por el contraste que te interesa (y suponiendo que 
devuelve el objeto estándar de clase htest).
sapply(muestras, fun.test) podría ser lo que buscas (suponiendo que 
muestras es una lista con los datos en cada componente). Para que 
conste, para ciertas cosas yo no soy reacio a emplear bucles en lugar de 
applies...


Un saludo, Rubén.


# --
# Repetición de contrastes
# --

# --
# Valores iniciales
set.seed(1) # Fijar semilla para reproductibilidad
n - 500
nsim - 1000
estadistico - numeric(nsim)
pvalor - numeric(nsim)


# --
# Realizar contrastes
for(isim in 1:nsim) {
  u - runif(n)
  tmp - ks.test(u, punif,  min=0, max=1)
  estadistico[isim] - tmp$statistic
  pvalor[isim] - tmp$p.value
}
#Probar a cambiar por u - rnorm(n) y tmp - ks.test(u, pnorm,  mean = 
mean(u), sd = sd(u))



# Mantengo algo del resto del código por si resulta de interés...

# --
# Proporción de rechazos
cat(\nProporción de rechazos al 1% =, mean(pvalor  0.01), \n)
cat(Proporción de rechazos al 5% =, mean(pvalor  0.01), \n)
cat(Proporción de rechazos al 10% =, mean(pvalor  0.01), \n)


# --
# Análisis del estadístico contraste

# Histograma
hist(estadistico, freq=FALSE)

#...

# --
# Análisis de los p-valores
# (si todo 'correcto' con distribución uniforme)

# Histograma
hist(pvalor, freq=FALSE)
curve(dunif(x,0,1), add=TRUE)   #abline(h=1)

# Test de Kolmogorov-Smirnov
ks.test(pvalor, punif,  min=0, max=1)

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


Re: [R] Help with nonlinear least squares regression curve fitting

2015-02-26 Thread Prof J C Nash (U30A)
Andrew's suggestion for Year is a help, but package nlmrt shows the
problem you are trying to solve is truly one where there is a Jacobian
singularity. (nlmrt produces the Jacobian singular values -- but read
the output carefully because these are placed for compact output as if
they correspond to parameters, which they do not).

Unfortunately, nlmrt tries to use analytic derivatives, and sign() is
not in the derivatives table for the double sigmoid. BTW, your function
has a typo. Do provide reproducible results. Here is what I did using

callaghan.csv:
Area,Year
104.7181283,1984
32.88026974,1985
56.07395863,1986
191.3422143,1987
233.4661392,1988
57.28317116,1989
201.1273404,1990
34.42570796,1991
165.8962342,1992
58.21905274,1993
114.6643724,1994
342.3461986,1995
184.8877994,1996
94.90509356,1997
45.2026941,1998
68.6196393,1999
575.2440229,2000
519.7557581,2001
904.157509,2002
1107.357517,2003
1682.876061,2004
40.55667824,2005
740.5032604,2006
885.7243469,2007
395.4190968,2008
1031.314519,2009
2597.544987,2010
1316.968695,2011
848.7093901,2012
5076.675075,2013
6132.975491,2014

code:
library(nlmrt)
df - read.csv(callaghan.csv)

fitmodeliq - nlxb(Area ~ (-a*Year)*(Year + b), data = df,
start=list(a=1,b=1, c=1))

fitmodelsig - nlxb(Area~a/(1+exp(-(b+c*Year))), data=df,
start=list(a=1,b=1, c=1))

fitmodelds - nlxb(Area ~
a+2*b*(1/(1+exp(-abs(-c*Year+d)))-1/2)*sign(-c*Year+d), data=df,
start=list(a=1, b=1, c=1))

For information of readers, Duncan Murdoch and I have been working on
nls14 to replace/augment nls(), but we've a way to go yet before this is
ready for CRAN. Collaborators welcome.

John Nash


On 15-02-26 06:00 AM, r-help-requ...@r-project.org wrote:
 Message: 24
 Date: Thu, 26 Feb 2015 07:26:50 +1100
 From: Andrew Robinson a.robin...@ms.unimelb.edu.au
 To: Corey Callaghan ccallaghan2...@fau.edu
 Cc: R help \(r-help@r-project.org\) r-help@r-project.org
 Subject: Re: [R] Help with nonlinear least squares regression curve
   fitting
 Message-ID:
   cahygmd6rruc_aobhrhw7babxnmzrsbi4b7zjt0vn5lrwvw2...@mail.gmail.com
 Content-Type: text/plain; charset=UTF-8
 
 Finding starting values is a bit of a dark art.  That said, there are steps
 you can take, but it may take time.
 
 First, I would scale Year so that it's not in the thousands! Experiment
 with subtracting 1980 or so.  For specific advice, see inline.
 
 On Thu, Feb 26, 2015 at 3:03 AM, Corey Callaghan ccallaghan2...@fau.edu
 wrote:
 
  The curves' functions that I want to test are in the code here (hopefully
  correctly):
 
  Inverse Quadratic Curve:
  fitmodel - nls(Area ~ (-a*Year)*(Year + b), data = df, start=list(a=??,
  b=??, c=??))
 
 I would plot the data and a smooth spline, differentiate the curve
 function, identify some parameter values somewhere stable, and estimate
 some values by eye, or even predict them from the first derivative of the
 spline - spline.smooth will do this.
 
 Sigmodial Curve:
  fitmodel - nls(Area~a/(1+exp(-(b+c*Year))), data=df, start=list(a=???,
  b=???, c=??))
 
 I'd use the highest value as a, fit spline as above then invert area at two
 times to get b and c.
 
 Double sigmoidal Curve:
  fitmodel - nls(Area~a+2b(1/(1+exp(-abs(-c*Year+d)))-1/2)*sign(-c*Year+d),
  data=df, start=list(a=???, b=???, c=???)
 
  I'd use min(Area) as a, figure out b from the maximum (I guess 2b+a is the
 asymptote), and experiment with two values for year to retrieve c and d
  uniroot might help?
 
 Cheers
 
 Andrew
 
 -- Andrew Robinson Deputy Director, CEBRA, School of Biosciences Reader
  Associate Professor in Applied Statistics Tel: (+61) 0403 138 955
 School of Mathematics and Statistics Fax: +61-3-8344 4599 University of
 Melbourne, VIC 3010 Australia Email: a.robin...@ms.unimelb.edu.au
 Website: http://www.ms.unimelb.edu.au/~andrewpr MSME:
 http://www.crcpress.com/product/isbn/9781439858028 FAwR:
 http://www.ms.unimelb.edu.au/~andrewpr/FAwR/ SPuR:
 http://www.ms.unimelb.edu.au/spuRs/ [[alternative HTML version deleted]]

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


Re: [R] How many digits are there in left of dot of 0.0001 ?

2015-02-26 Thread JS Huang
Hi, 
  
  Some modification to work for both positive and negative number:

nchar(format(*abs*(a),scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)+1)
-1.



--
View this message in context: 
http://r.789695.n4.nabble.com/How-many-digits-are-there-in-left-of-dot-of-0-0001-tp4703842p4703872.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] covert entire dataset to numeric while persuing percentage values

2015-02-26 Thread jim holtman
It would help a lot if you posted a subset of your data using 'dput'
so that we know what it actually looks like.  You have character data
mixed with numerics, so you will be NAs in some cases.

Conversion of percent to numeric is accomplished with something like this:

 x - c('12%', '6%', '3.75%')
 # convert to a number
 as.numeric(gsub(%, , x)) / 100
[1] 0.1200 0.0600 0.0375



Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Thu, Feb 26, 2015 at 4:06 AM, Methekar, Pushpa (GE Transportation,
Non-GE) pushpa.methe...@ge.com wrote:
 Hi ,
 I am little confused  about how to covert entire dataset to numeric .
 As I read data like..
 Xelements =read.csv(file. Choose(),header = T, stringsAsFactors=FALSE)
 str(xelements )

 str(xelements)
 'data.frame':  731 obs. of  4 variables:
 $ Engine.Speed : chr  rpm ES rpm 1049 ...
 $ X..NG.by.Energy  : chr   % NG by Energy % 0% ...
 $ Int.Mfld.Temp: chr   Int Mfld Temp °C 49 ...
 $ Cmd.Advance.Angle: chr   Cmd Advance Angle °BTDC 13.8 ...

 I have second column as in 0%, 10%, In percentage value ,
 Whenever I am going to covert whole dataset its showing NA introduced .second 
 column going to become NA.
 Converting separately I would be successful .


 xelements$Engine.Speed - as.numeric(xelements$Engine.Speed)

 Warning message:

 NAs introduced by coercion

 xelements$X..NG.by.Energy- 
 as.numeric(sub(%,,xelements$X..NG.by.Energy))/100

 Warning message:

 NAs introduced by coercion

 xelements$Int.Mfld.Temp- as.numeric(xelements$Int.Mfld.Temp)

 Warning message:

 NAs introduced by coercion

 xelements$Cmd.Advance.Angle- as.numeric(xelements$Cmd.Advance.Angle)

 Warning message:

 NAs introduced by coercion

 But I want to covert whole dataset at a time. I want to write function which 
 will help me to solve this problem  .


 xelements - data.frame(sapply(xelements, function(x) 
 as.numeric(as.character(x
 sapply(xelements, class)

 but it won't be able to covert percentage value  like 10%, 20%
 please do help me if you know the way. Thank you

 [[alternative HTML version deleted]]


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

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

[R] twitteR

2015-02-26 Thread José Luis Aguilar
Hello,

i need help,  I'm trying to get oauth authorization to get rcredentials
.RData

the code that i use is:

library(twitteR)
library(tm)
library(wordcloud)
library(RColorBrewer)
library(RCurl)
library(ROAuth)

options(RCurlOptions = list(cainfo = system.file(CurlSSL, cacert.pem,
package = RCurl)))
u = 
https://raw.github.com/tonybreyal/Blog-Reference-Functions/master/R/bingSearchXScraper/bingSearchXScraper
.
x = getURL(u, cainfo = system.file(CurlSSL, cacert.pem, package =
RCurl))

download.file(url=http://curl.haxx.se/ca/cacert.pem;,
  destfile=cacert.pem
  requestURL - https://api.twitter.com/oauth/request_token;
  accessURL - https://api.twitter.com/oauth/access_token;
 authURL - https://api.twitter.com/oauth/authorize;

 consumerKey  -  eED.
 consumerSecret   -  qo.

twitCred - OAuthFactory$new(consumerKey=consumerKey,
 consumerSecret=consumerSecret,
 requestURL=reqURL,
 accessURL=accessURL,
 authURL=authURL)

)

when Asking for access

 twitCred$handshake(cainfo=cacert.pem)


i receive this message:

ERROR: AUTHORIZATION NO FOUND

Please help me,

thanks a lot!!

[[alternative HTML version deleted]]

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


[R] Save a list of list and search for values

2015-02-26 Thread Alaios via R-help
Dear all,in my code I am using the mix() function that returns results in a 
list. The result looks like
List of 10
 $ parameters  :'data.frame':   2 obs. of  3 variables:
  ..$ pi   : num [1:2] 0.77 0.23
  ..$ mu   : num [1:2] -7034 162783
  ..$ sigma: num [1:2] 20235 95261
 $ se  :'data.frame':   2 obs. of  3 variables:
  ..$ pi.se   : num [1:2] 0.0423 0.0423
  ..$ mu.se   : num [1:2] 177 12422
  ..$ sigma.se: num [1:2] 1067 65551
 $ distribution: chr norm
 $ constraint  :List of 8
  ..$ conpi   : chr NONE
  ..$ conmu   : chr NONE
  ..$ consigma: chr NONE
  ..$ fixpi   : NULL
  ..$ fixmu   : NULL
  ..$ fixsigma: NULL
  ..$ cov : NULL
  ..$ size    : NULL
 $ chisq   : num 28
 $ df  : num 5
 $ P   : num 3.67e-05
 $ vmat    : num [1:5, 1:5] 1.79e-03 -3.69e-01 -1.17e+02 2.95e+01 -2.63e+03 
...
 $ mixdata :Classes ‘mixdata’ and 'data.frame': 11 obs. of  2 variables:
  ..$ X    : num [1:11] 1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 
1e+05 ...
  ..$ count: int [1:11] 993 137 82 30 21 5 7 14 21 2 ...
 $ usecondit   : logi FALSE
 - attr(*, class)= chr mix

In my code I am trying around 10.000 fit (and each of these fits returns the 
list above) and I want to keep those in a way that later on I would be able to 
search inside all the lists.For example I would like to find inside those 
10.000 lists which one has the smallest $chisq value. What would be a suitable 
way to implement that in R? Luckily I am working in a computer with a lot of 
ram so storing 10.000 lists temporary in memory before saving to disk would not 
be a problem.
What would you suggest me?
RegardsAlex

[[alternative HTML version deleted]]

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

Re: [R] Dummy variable in ARIMA

2015-02-26 Thread peter dalgaard

 On 26 Feb 2015, at 17:29 , Mikael Olai Milhøj mikaelmil...@gmail.com wrote:
 
 Hi.
 
 First of all, thx. But when using in arima(...xreg=fact,...) then fact
 should be a vector and not a factor variable? Maybe I should have been more
 clear in my first mail, sorry. Or else I have to dig deeper into factors.
 

You can always do things like as.numeric((1:50) %in% (4:6)), but longer term I 
think it is more generalizable to play with model.matrix(), i.e. M - 
model.matrix(~fact). As far as I recall, arima() will automatically include a 
constant so you need to say xreg=M[,-1] to get rid of the column of ones.


 
 /Mikael
 
 On Thu, Feb 26, 2015 at 5:17 PM, Bert Gunter gunter.ber...@gene.com wrote:
 
 Inline.
 
 Cheers,
 Bert
 
 Bert Gunter
 Genentech Nonclinical Biostatistics
 (650) 467-7374
 
 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
 Clifford Stoll
 
 
 
 
 On Thu, Feb 26, 2015 at 8:02 AM, Mikael Olai Milhøj
 mikaelmil...@gmail.com wrote:
 Hi all
 
 I have been searching on the web in vain. I want to include a dummy
 variable in my ARIMA model. Let's say that I want to make an AR(1) model
 for X including a dummy variable which should be 1 for observation 4,5,6
 and zero otherwise (let's say that there is 50 observations in total).
 How
 do I make that?
 
 You don't, really.
 
 1. Go through an R tutorial so that you understand the concept of
 factors and how they are used in R modeling.
 
 2. fact - factor( (1:50) %in% (4:6))
 
 Cheers,
 Bert
 
 
 This does the trick but seems inefficient: dummy-c(rep(0,3), rep(1,3),
 rep(0,44))
 
 Thx in advance
 
 Best regards
 /Mikael
 
[[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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

Re: [R] extract file name from a path string

2015-02-26 Thread John McKown
Look at dirname() and basename(). The first would be what you call
the path. The second is the file.name without the path.

On Thu, Feb 26, 2015 at 10:58 AM, Luigi Marongiu
marongiu.lu...@gmail.com wrote:
 Dear all,
 what code should I write in order to extract the file name from a give
 path? Let's say that I want to get the file my file.xls which is in
 the directory/folder My documents; since I work both with Windows
 and Linux, the paths I am looking at are in the format:

 path.windows-\\home$\\lm667\\My Documents\\my file.xls
 path.linux-/home/My Documents/my file.xls

 I used two words for the file name because sometimes the file names
 have multiple words rather than a single one separated by capitals,
 . or _.
 The code should now get the file name, which is included between \\
 (or /) and .xls but I don't know what regular expression will do
 the trick.
 Once the file name has been assigned to a vector, it should be easy to
 remove it from the path.windows/.linux and obtain a vector with the
 path on its own.
 Essentially the output should be as follows:

 file.name
 [1] my file.xls
 path.w
 [1] \\home$\\lm667\\My Documents\\
 path.l
 [1] /home/My Documents/

 Thank you,
 Luigi

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



-- 
He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! 
John McKown

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


Re: [R] Dummy variable in ARIMA

2015-02-26 Thread Bert Gunter
Dig deeper.

-- Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

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




On Thu, Feb 26, 2015 at 8:29 AM, Mikael Olai Milhøj
mikaelmil...@gmail.com wrote:
 Hi.

 First of all, thx. But when using in arima(...xreg=fact,...) then fact
 should be a vector and not a factor variable? Maybe I should have been more
 clear in my first mail, sorry. Or else I have to dig deeper into factors.


 /Mikael

 On Thu, Feb 26, 2015 at 5:17 PM, Bert Gunter gunter.ber...@gene.com wrote:

 Inline.

 Cheers,
 Bert

 Bert Gunter
 Genentech Nonclinical Biostatistics
 (650) 467-7374

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




 On Thu, Feb 26, 2015 at 8:02 AM, Mikael Olai Milhøj
 mikaelmil...@gmail.com wrote:
  Hi all
 
  I have been searching on the web in vain. I want to include a dummy
  variable in my ARIMA model. Let's say that I want to make an AR(1) model
  for X including a dummy variable which should be 1 for observation 4,5,6
  and zero otherwise (let's say that there is 50 observations in total).
  How
  do I make that?

 You don't, really.

 1. Go through an R tutorial so that you understand the concept of
 factors and how they are used in R modeling.

 2. fact - factor( (1:50) %in% (4:6))

 Cheers,
 Bert

 
  This does the trick but seems inefficient: dummy-c(rep(0,3), rep(1,3),
  rep(0,44))
 
  Thx in advance
 
  Best regards
  /Mikael
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



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

Re: [R] Processing key_column, begin_date, end_date in R

2015-02-26 Thread jim holtman
here is yet another way:

 dta - read.csv( text=
+ key_column,begin_date,end_date
+  123456,2013-01-01,2014-01-01
+  123456,2013-07-01,2014-07-01
+  789102,2012-03-01,2014-03-01
+  789102,2015-02-01,2016-02-01
+  789102,2015-02-06,2016-02-06
+ 789102,2015-02-28,2015-03-31
+  789102,2015-04-30,2015-05-31
+  , as.is=TRUE)

 # check for overlap by sorting into time order and the adding 1 for
 # begin and -1 for end and create cumsum
 # select only resulting entries with begin @ 1 and end @ 0
 dta - dta %%
+ mutate(begin_date = as.Date(begin_date)  # convert the times
+ , end_date = as.Date(end_date)
+ ) %%
+ gather(time, value, -key_column) %%  # create 'long' data
+ mutate(oper = ifelse(grepl('^b', time), 1, -1)) %%  # value for begin/end
+ arrange(value) %%  # sort by time
+ group_by(key_column) %%  # separate into groups
+ mutate(depth = cumsum(oper)) %%
+ filter((grepl(^b, time)  depth == 1) |  # filter on begin@1 and end@0
+   (grepl(^e, time)  depth == 0)
+   ) %%
+ ungroup() %%
+ arrange(key_column, value)
 # now have pairs of lines for the times
 indx - seq(1, nrow(dta), 2)
 result - data.frame(key_column = dta$key_column[indx]
+ , begin_time = dta$value[indx]
+ , end_time = dta$value[indx + 1L]
+ , stringsAsFactors = FALSE
+ )
 result
  key_column begin_time   end_time
1 123456 2013-01-01 2014-07-01
2 789102 2012-03-01 2014-03-01
3 789102 2015-02-01 2016-02-06


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Wed, Feb 25, 2015 at 4:18 PM, Matt Gross gro...@gmail.com wrote:
 Hi,

 I am trying to process a large dataset in R.  The dataset contains the
 following three columns:

 key_column - a unique key identifier
 begin_date - the start date of the active period
 end_date - the end date of the active period


 Example data is here:

 key_column,begin_date,end_date
 123456,2013-01-01,2014-01-01
 123456,2013-07-01,2014-07-01
 789102,2012-03-01,2014-03-01
 789102,2015-02-01,2016-02-01
 789102,2015-02-06,2016-02-06

 I want to build a condensed table of key_column and begin_date's and
 end_date's.  As you can see in the example data above, some begin and end
 date periods overlap with begin_date and end_date pairs for the same
 key_column.  In situations where overlap exists I want to have one record
 for the key_column with the min(begin_date) and the max(end_date).

 Can anyone help me build the commands to process this data in R?

 Thanks,
 Matt

 --
 Matt Gross
 gro...@gmail.com
 503.329.4545

 [[alternative HTML version deleted]]

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

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


Re: [R] Saving Mean Relative Difference from all.equal()

2015-02-26 Thread Scott Colwell
I think I have one solution. Not very pretty though. Relies on the text not
changing at all.

as.numeric(gsub(Mean relative difference: , ,
all.equal(cov2cor(ITEMCOV),cor(item.data))[2]))

Is there a better way?



--
View this message in context: 
http://r.789695.n4.nabble.com/Saving-Mean-Relative-Difference-from-all-equal-tp4703905p4703908.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Schedule R function/Code to run at specific time

2015-02-26 Thread MacQueen, Don
Everything Duncan said, plus:

A construction like this might do the job

run.at - as.POSIXct('2015-02-26 13:05')
while(TRUE) {
  if ( trunc(Sys.time(),'min') == run.at) source('whatever-it-is.r')
  Sys.sleep(60)
}


but I wouldn't count on it to be as reliable as cron (or Windows
equivalent).

-- 
Don MacQueen

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





On 2/26/15, 11:20 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote:

On 26/02/2015 2:08 PM, Doran, Harold wrote:
 Is there functionality within R proper, without having to revert to the
OS, allowing a function or a portion of an R script to be run at a
defined time? My google searches haven't provided much other than one at
the link below which relies on an OS.

If you want it to start 1000 seconds from now, use Sys.sleep(1000) as
your first statement.  You'll have a process sitting there using no CPU
(but perhaps lots of virtual memory) until the sleeping is done.  Using
cron is better.

Duncan Murdoch

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

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


[R] Saving Mean Relative Difference from all.equal()

2015-02-26 Thread Scott Colwell

Hello,

Does anyone know how to save the numeric value of the mean relative
difference when using the all.equal() command?

For example this:

all.equal(cov2cor(ITEMCOV),cor(item.data))

Gives:

[1] Attributes:  Length mismatch: comparison on first 1 components 
[2] Mean relative difference: 0.01523708   

I'd like to save the value 0.01523708 in a numeric format.

Thanks,




--
View this message in context: 
http://r.789695.n4.nabble.com/Saving-Mean-Relative-Difference-from-all-equal-tp4703905.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Extracting Factor Pattern Matrix Similar to Proc Factor

2015-02-26 Thread Scott Colwell
Thanks everyone



--
View this message in context: 
http://r.789695.n4.nabble.com/Extracting-Factor-Pattern-Matrix-Similar-to-Proc-Factor-tp4703704p4703904.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Schedule R function/Code to run at specific time

2015-02-26 Thread Duncan Murdoch

On 26/02/2015 2:08 PM, Doran, Harold wrote:

Is there functionality within R proper, without having to revert to the OS, 
allowing a function or a portion of an R script to be run at a defined time? My 
google searches haven't provided much other than one at the link below which 
relies on an OS.


If you want it to start 1000 seconds from now, use Sys.sleep(1000) as 
your first statement.  You'll have a process sitting there using no CPU 
(but perhaps lots of virtual memory) until the sleeping is done.  Using 
cron is better.


Duncan Murdoch

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


[R] integrate with vector arguments

2015-02-26 Thread marKo
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I'm a bit stuck.
I have to integrate a series of polynomial functions with vector
arguments.

v1-c(1:5)
v2-c(1:5)

f1-function (x) {v1*x+v2*x^2}

The problem is that integrate(f1, 0, 1) does not work.
I does not, even if a pas the arguments (v1, v2)

f1-function (x, v1, v2) {v1*x+v2*x^2}

or if i try to vectorize the function

f1-Vectorize(function(x, v1, v2){v1*x+v2*x^2},
vectorize.args=c(v1, v2))

integrate(f1, 0, 1) gives an error:

Error in integrate(f1, 0, 1) :
  evaluation of function gave a result of wrong length

Any help will be greatly appreciated.

Thanks,

Marko

-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBAgAGBQJU72qnAAoJEJcj4KySkkQsLAkP/R7DvO0GiZDRrtHgDna/2xj+
XJd8G/gGfe029lVjg+3i6wfKfZ9CoRH+kHEVnT0/SRYcSAeRu3/fys11sjEgVGnl
a/Go167YRYfDkP/OrY4jKtlULySeiGBxNJwKmk1oCidoodk2mejWdPQ61tBj6ozF
sA+Bzoi7Exh2pp88Eks4+Ynz+Toi8Ck1hItV60kP9yOMSBsIPVLw53lGXDfOshzM
zLcFbHM5hyjmt/BQvyaBm3E822YEJgcDQN3nedjQgwThJuEyig2TXHAvyEZcdBWD
H8Py0b5/TBdmxqJQ3EqYyBFmPxeFuhO4ZS22IhP+rqPJ51EZnfqG6DRBHHLqQ9rX
ZnYJN8ryqDVMOrYHn6j3dNd/m7C/YWmrY8gjArv8WxRsX+kX+DAgbRmiw/43BXNG
Y2Jco5dChWBrXQDR3FMoJWBTWjvwgPfP06hnwjrJT1uJZQLPUzhdrIxyHxbhsW0A
UeiRqNiPjE9YpKrFGn9Itg1tXk35yrPrNmmj1nzIzaHejMzT8zf0X2pJAygAYyk3
+mrEgwkB31GOt2mUqqFzDxgDHASaSTPlskviIVJ9klcs7ViWYSy5ARiF4/ptbluE
CTny7dVj/AoXq8dC8TxghOT1QSnPVy7ceb6fCep7LxJDWlFqTEM0LCbL7Ql78yzP
+Em5gaikzPGbJ7uvVKIG
=7J6P
-END PGP SIGNATURE-

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


[R] Schedule R function/Code to run at specific time

2015-02-26 Thread Doran, Harold
Is there functionality within R proper, without having to revert to the OS, 
allowing a function or a portion of an R script to be run at a defined time? My 
google searches haven't provided much other than one at the link below which 
relies on an OS.

Thanks,
Harold

https://tgmstat.wordpress.com/2013/09/11/schedule-rscript-with-cron/

[[alternative HTML version deleted]]

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


Re: [R-es] como eliminar los nombres de las series en el grafico

2015-02-26 Thread eric
Funciono perfecto !! tan facil que era, jajaja ... el que sabe sabe,
como dicen.

Muchas gracias Jorge,


Eric.






On 26/02/15 03:02, Jorge I Velez wrote:
 Eric,
 
 Creo que necesitas Hmisc:::xYplot(..., label.curves = FALSE)
 
 Saludos,
 Jorge.-
 
 
 2015-02-26 11:15 GMT+11:00 eric ericconchamu...@gmail.com
 mailto:ericconchamu...@gmail.com:
 
 Estimada comunidad, estoy haciendo un grafico con la funcion xYplot
 (paquete Hmisc) para agregar barras de error a los puntos del grafico.
 Pero pasa algo que no me gusta: aparece el nombre de las series en el
 grafico.
 
 Alguien sabe como puedo eliminarlas ? no quiero usar ggplot porque ya
 tengo hechos todos los graficos con lattice.
 
 Aqui el codigo que uso y los datos (estan separados por tab, no por ,)
 y el grafico los envio adjuntos.
 
 xYplot(Cbind(ave,ul,ll) ~ con
 , groups=sol,data=ca.med.sincon ,xlab=Solvent concentration (mM)
 , ylab=Contact Angle (°), method=lower bars,  cex=1.1, type=b
 , scales=list(x=list(log=10), equispaced.log=FALSE)
 , abline=list(h=ca.med[ca.med$sol==con,3])
 )
 
 Espero que alguien sepa porque ya he gastado mucho tiempo buscando y
 probando cosas.
 
 Gracias,
 
 Eric.
 
 
 
 
 --
 Forest Engineer
 Master in Environmental and Natural Resource Economics
 Ph.D. student in Sciences of Natural Resources at La Frontera University
 Member in AguaDeTemu2030, citizen movement for Temuco with green city
 standards for living
 
 Nota: Las tildes se han omitido para asegurar compatibilidad con algunos
 lectores de correo.
 
 ___
 R-help-es mailing list
 R-help-es@r-project.org mailto:R-help-es@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-help-es
 
 

-- 
Forest Engineer
Master in Environmental and Natural Resource Economics
Ph.D. student in Sciences of Natural Resources at La Frontera University
Member in AguaDeTemu2030, citizen movement for Temuco with green city
standards for living

Nota: Las tildes se han omitido para asegurar compatibilidad con algunos
lectores de correo.

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


[R] Summing certain values within columns that satisfy a certain condition

2015-02-26 Thread Kate Ignatius
Hi,

Supposed I had a data frame like so:

A B C D
0 1 0 7
0 2 0 7
0 3 0 7
0 4 0 7
0 1 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 1 5
0 5 1 5
0 4 1 5
0 8 4 7
0 0 3 0
0 0 3 4
0 0 3 4
0 0 0 5
0 2 0 6
0 0 4 0
0 0 4 0
0 0 4 0

For each row, I want to count how many max column values appear to
adventurely get the following outcome, while ignoring zeros and N/As:

A B C D Sum
0 1 0 7 1
0 2 0 7 1
0 3 0 7 1
0 4 0 7 1
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 1 5 0
0 5 1 5 0
0 4 1 5 0
0 8 4 7 3
0 0 3 0 0
0 0 3 4 0
0 0 3 4 0
0 0 0 5 0
0 2 0 6 0
0 0 4 0 1
0 0 4 0 1
0 0 4 0 1

I've used the following code but it doesn't seem to work (my sum
column column is all 1s):

(apply(df,1, function(x)  (sum(x %in% c(pmax(x))

Is this code too simple?

Thanks!

K.

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


Re: [R] PEA and APE Tobit

2015-02-26 Thread Arne Henningsen
Dear Annelies

On 26 February 2015 at 09:12, hnlki annelies.hoebe...@ugent.be wrote:
 I estimated a tobit model
 tobit.fit-tobit(y~x,left=0, right=Inf)  (library AER)
 or
 tobit2.fit-censReg(y~x, left=0, right=Inf) (librarycensReg)
 I' have estimated the partial effect at the average as:
 pea-(pnorm((colMeans(x)%*%tobit.fit$coef[-1])/tobit.fit$scale))%*%tobit.fitt$coef[-1]
 and the average partial effect as:
 ape-
 (length(x[,1]))^(-1)*sum(pnorm((x%*%tobit.fit$coef[-1])/tobit.fit$scale))*tobit.fit$coef[-1]

 I guess I did something wrong as
  margEff( tobit2.fit) (library(censReg)
  gives a different result than my partial effect at the average.

 Any ideas about what I did wrong?
 I  did not find the underlying code of margEff.

[...]

 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

Please follow the posting guide and provide a self-contained
reproducible example.

Best regards,
Arne

-- 
Arne Henningsen
http://www.arne-henningsen.name

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


Re: [R] Schedule R function/Code to run at specific time

2015-02-26 Thread peter dalgaard

 On 26 Feb 2015, at 20:20 , Duncan Murdoch murdoch.dun...@gmail.com wrote:
 
 On 26/02/2015 2:08 PM, Doran, Harold wrote:
 Is there functionality within R proper, without having to revert to the OS, 
 allowing a function or a portion of an R script to be run at a defined time? 
 My google searches haven't provided much other than one at the link below 
 which relies on an OS.
 
 If you want it to start 1000 seconds from now, use Sys.sleep(1000) as your 
 first statement.  You'll have a process sitting there using no CPU (but 
 perhaps lots of virtual memory) until the sleeping is done.  Using cron is 
 better.
 

There are also some asynchronous possibilities using tcltk:

tcl(after, 1, quote(print(boo)))

Peter D.

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

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R] Summing certain values within columns that satisfy a certain condition

2015-02-26 Thread Jeff Newmiller
I guess the answer to your question is yes.

dta - read.table( text=
A B C D
0 1 0 7
0 2 0 7
0 3 0 7
0 4 0 7
0 1 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 1 5
0 5 1 5
0 4 1 5
0 8 4 7
0 0 3 0
0 0 3 4
0 0 3 4
0 0 0 5
0 2 0 6
0 0 4 0
0 0 4 0
0 0 4 0
, header=TRUE )
dtacmax - sapply( dta, max )

followed by

dta$Sum - apply(dta,1, function(x) (sum(0!=x  x == dtacmax,na.rm=TRUE)))

or

dtam - as.matrix( dta[,1:4] )
dta$Sum2 - rowSums( !is.na(dtam)  0!=dtam  dtam == matrix( dtacmax, 
ncol=ncol( dtam ), nrow=nrow( dtam ), byrow=TRUE ) )


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

On February 26, 2015 12:23:48 PM PST, Kate Ignatius kate.ignat...@gmail.com 
wrote:
Hi,

Supposed I had a data frame like so:

A B C D
0 1 0 7
0 2 0 7
0 3 0 7
0 4 0 7
0 1 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 1 5
0 5 1 5
0 4 1 5
0 8 4 7
0 0 3 0
0 0 3 4
0 0 3 4
0 0 0 5
0 2 0 6
0 0 4 0
0 0 4 0
0 0 4 0

For each row, I want to count how many max column values appear to
adventurely get the following outcome, while ignoring zeros and N/As:

A B C D Sum
0 1 0 7 1
0 2 0 7 1
0 3 0 7 1
0 4 0 7 1
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 1 5 0
0 5 1 5 0
0 4 1 5 0
0 8 4 7 3
0 0 3 0 0
0 0 3 4 0
0 0 3 4 0
0 0 0 5 0
0 2 0 6 0
0 0 4 0 1
0 0 4 0 1
0 0 4 0 1

I've used the following code but it doesn't seem to work (my sum
column column is all 1s):

(apply(df,1, function(x)  (sum(x %in% c(pmax(x))

Is this code too simple?

Thanks!

K.

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

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


Re: [R] How many digits are there in left of dot of 0.0001 ?

2015-02-26 Thread JS Huang
Hi,

  I assume you want to know the digit count to the left of decimal point. 
If this is the case, then you may use  trunc(log10(max(1,trunc(abs(a)+1
for a numerical variable a.  Count 0.12 as having one digit to the left of
decimal point.

 trunc(log10(max(1,trunc(abs(-10.99)+1
[1] 6
 trunc(log10(max(1,trunc(abs(0)+1
[1] 1
 trunc(log10(max(1,trunc(abs(9.999)+1
[1] 1
 trunc(log10(max(1,trunc(abs(19.999)+1
[1] 2
 trunc(log10(max(1,trunc(abs(-1999.999)+1
[1] 4



--
View this message in context: 
http://r.789695.n4.nabble.com/How-many-digits-are-there-in-left-of-dot-of-0-0001-tp4703842p4703847.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Processing key_column, begin_date, end_date in R

2015-02-26 Thread JS Huang
Hi,
  
  Here is an implemenation:

 date
  key_column begin_dateend_date
1 123456 2013-01-01 2014-01-01 
2 123456 2013-07-01 2014-07-01 
3 789102 2012-03-01 2014-03-01 
4 789102 2015-02-01 2016-02-01 
5 789102 2015-02-06  2016-02-06
 y - t(sapply(unique(date$key_column),function(x)
 c(x,min(as.character(date[date$key_column==x,begin_date])),max(as.character(date[date$key_column==x,end_date])
 y
 [,1] [,2] [,3] 
[1,] 123456 2013-01-01 2014-07-01 
[2,] 789102 2012-03-01 2016-02-06 
 colnames(y)
NULL
 colnames(y) - c(key_column,begin_date,end_date)
 y
 key_column begin_date   end_date 
[1,] 123456   2013-01-01 2014-07-01 
[2,] 789102   2012-03-01 2016-02-06 



--
View this message in context: 
http://r.789695.n4.nabble.com/Processing-key-column-begin-date-end-date-in-R-tp4703835p4703850.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Solved: Re: text miner error: Error in UseMethod(meta, x)

2015-02-26 Thread Sun Shine

Hi list

Closing this one off myself, this is what I did:

The error seems to concern the update of tm to version 0.6: the 
conversion to lower case text should now be:


 docs - tm_map(docs, content_transformer(tolower))

Everything else seems to work fine thereafter.

The issue in the tutorial concerns section 3.1. wherein Graham creates a 
function toSpace. This seems to introduce an additional term that tm_map 
and later DocumentTermMatrix do not seem to know how to handle. This is 
probably an incorrect interpretation of what's going on, but the fix 
appears to be to use the above line earlier in the preparation stage.


If anyone has more informed insight, please share.

Cheers

Sun

On 25/02/15 17:33, Sun Shine wrote:

Hi list

I've been working my way through a tutorial on text mining ( 
http://onepager.togaware.com/TextMiningO.pdf ) and all was well until 
I came across this problem using tm (text miner):


++code+++
 docs - tm_map(docs, content_transformer(tolower))
Warning messages:
1: In mclapply(x$content[i], function(d) tm_reduce(d, x$lazy$maps)) :
  all scheduled cores encountered errors in user code
2: In mclapply(content(x), FUN, ...) :
  all scheduled cores encountered errors in user code
++end-code

After some searching, it appears the best fix for this problem was to 
pass an explicit lazy=TRUE argument to tm, like this:


 docs - tm_map(docs, content_transformer(tolower), lazy=TRUE)

However, a little further on in the tutorial to set up the text 
matrix, a related (?) error was returned:


++code+++
 dtm - DocumentTermMatrix(docs)
Error in UseMethod(meta, x) :
  no applicable method for 'meta' applied to an object of class 
try-error

In addition: Warning message:
In mclapply(unname(content(x)), termFreq, control) :
  all scheduled cores encountered errors in user code
++end-code

I tried applying the explicit lazy=TRUE again, but doesn't change 
things. I have gone over the tutorial again and have followed all of 
the steps (including loading the requisite libraries). Moreover, 
searching on the web seems to return several contradictory suggestions 
and I'm no wiser than I was before.


The closest I came to an answer was at Stack Overflow 
http://stackoverflow.com/questions/24771165/r-project-no-applicable-method-for-meta-applied-to-an-object-of-class-charact 
and that answer suggested using the latest tm (v 0.6) and claimed that 
the earlier tolower step was wrong. However, my code used the 
recommended: corpus - tm_map(corpus, content_transformer(tolower))


Is there anyone on the list who could either sign-post me to a 
solution or assist in debugging this please?


I'm running R version 3.1.2 and tm is 0.6

Many thanks

Sun




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


[R] covert entire dataset to numeric while persuing percentage values

2015-02-26 Thread Methekar, Pushpa (GE Transportation, Non-GE)
Hi ,
I am little confused  about how to covert entire dataset to numeric .
As I read data like..
Xelements =read.csv(file. Choose(),header = T, stringsAsFactors=FALSE)
str(xelements )

 str(xelements)
'data.frame':  731 obs. of  4 variables:
$ Engine.Speed : chr  rpm ES rpm 1049 ...
$ X..NG.by.Energy  : chr   % NG by Energy % 0% ...
$ Int.Mfld.Temp: chr   Int Mfld Temp �C 49 ...
$ Cmd.Advance.Angle: chr   Cmd Advance Angle �BTDC 13.8 ...

I have second column as in 0%, 10%, In percentage value ,
Whenever I am going to covert whole dataset its showing NA introduced .second 
column going to become NA.
Converting separately I would be successful .


 xelements$Engine.Speed - as.numeric(xelements$Engine.Speed)

Warning message:

NAs introduced by coercion

 xelements$X..NG.by.Energy- 
 as.numeric(sub(%,,xelements$X..NG.by.Energy))/100

Warning message:

NAs introduced by coercion

 xelements$Int.Mfld.Temp- as.numeric(xelements$Int.Mfld.Temp)

Warning message:

NAs introduced by coercion

 xelements$Cmd.Advance.Angle- as.numeric(xelements$Cmd.Advance.Angle)

Warning message:

NAs introduced by coercion

But I want to covert whole dataset at a time. I want to write function which 
will help me to solve this problem  .


xelements - data.frame(sapply(xelements, function(x) 
as.numeric(as.character(x
sapply(xelements, class)

but it won't be able to covert percentage value  like 10%, 20%
please do help me if you know the way. Thank you

[[alternative HTML version deleted]]

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

[R] format selected columns in dataframe as character

2015-02-26 Thread Alain D.
Dear R-List,
 
#I have a df with the first two cols formatted as factor.
 
dfx - data.frame(
group = c(rep('A', 8), rep('B', 15), rep('C', 6)),
sex = sample(c(M, F), size = 29, replace = TRUE),
age = runif(n = 29, min = 18, max = 54))
 
# now I want to format both factor VARs as character
# I tried
 
factor.id-names(dfx[sapply(dfx,is.factor)])
chr.names-which(names(dfx)%in% factor.id)
 
dfx[ , chr.names]-as.character(dfx[ , chr.names])
# which gives me
str(dfx)
'data.frame': 29 obs. of 3 variables: $ group: chr c(1, 1, 1, 1, 1, 1, 1, 1, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3) c(2, 2, 1, 1, 1,
1, 2, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2) c(1,
1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
3) c(2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1,
1, 1, 2, 2, 2) ... $ sex : chr c(2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 2,
1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2) c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3) c(2, 2, 1, 1, 1, 1, 2,
1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2) c(1, 1, 1,
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3)
... $ age : num 38.5 18 33.5 26 22.5 ...
 
#though I was hoping for something like
 
'data.frame': 29 obs. of  3 variables:
$ group: chr  A A A A ...
$ sex  : chr  M F F M ...
$ age  : num  21.3 35.2 53.8 21 23.6 ...

#What is wrong with my code?
#Thank you for any help

Best wishes 

Alain
 
 
 
[[alternative HTML version deleted]]

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


[R] Rgraphviz and NA indices error

2015-02-26 Thread Sun Shine

Hi list

Can someone help me debug the following please:

Having downloaded and installed the bioconductor packages and Rgraphviz, 
I am attempting to plot a network graph showing the relation among 
chosen words in the corpus of text data.


I first did this:
 plot(dtm, terms=findFreqTerms(dtm, lowfreq=100) [1:30], 
corThreshold=0.75)


and received the error message:

Error in `[.simple_triplet_matrix`(m, , terms) : NA indices not allowed.


My next step was to remove any NA indices (although to be honest, this 
is more of a stab in the dark because there shouldn't be any NA values 
in the corpus):


 docsNA - (docs[!is.na(docs)])

Then redid the DTM with the NA values removed
 dtmNA - DocumentTermMatrix(docsNA)

Then re-ran Rgraphviv with the new set
 plot(dtmNA, terms=findFreqTerms(dtmNA, lowfreq=100) [1:10], 
corThreshold=0.5)


But, still get an error:
Error in `[.simple_triplet_matrix`(m, , terms) : NA indices not allowed.

I have not been successful in finding out why this error persists nor 
what to do about it.


Anyone have any ideas to progress past this issue?

Thanks

Sun

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


[R] HELP Tukey

2015-02-26 Thread CHIRIBOGA Xavier
Dear all ,



I am trying to do a Tukey comparison, but a message appears:



tuk-glht(mod0,linfct=mcp(Soil=Tukey));summary(tuk)
Error: could not find function glht



Anyone knows how to fix it?



Thanks a lot!



Xavier

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


Re: [R] HELP Tukey

2015-02-26 Thread Thierry Onkelinx
??glht would tell you that glht is a function from the multcomp package.
You need to load a package before you can use its functions.

library(multcomp)

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie  Kwaliteitszorg / team Biometrics  Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2015-02-26 11:21 GMT+01:00 CHIRIBOGA Xavier xavier.chirib...@unine.ch:

 Dear all ,



 I am trying to do a Tukey comparison, but a message appears:



 tuk-glht(mod0,linfct=mcp(Soil=Tukey));summary(tuk)
 Error: could not find function glht



 Anyone knows how to fix it?



 Thanks a lot!



 Xavier

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


[[alternative HTML version deleted]]

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


[R-es] nueva en R

2015-02-26 Thread Gloria Perez Fuentes
hola!soy nueva aqui, estoy haciendo un trabajo sobre R y toda la
informacion que encuentro esta en ingles. me gustaria saber algun libro
sobre R o donde podria conseguir buena informacion sobre el programa en
español, ya sea de su funcionamiento, finalidad del programa,
caracteristicas etc. Nunca he utilizado este programa. gracias.

[[alternative HTML version deleted]]

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


[R] library(multcomp) does not work for loading Tukey

2015-02-26 Thread CHIRIBOGA Xavier
Dear colleagues,



For Tukey, I tried to load the function with



library(multcomp) but again a message says:



Error in library(multcomp) : any package called ‘multcomp’ has been found







Thanks for ur help,

Xavier

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


Re: [R] How many digits are there in left of dot of 0.0001 ?

2015-02-26 Thread ce

yes this is exactly what I want and it works. thanks.

-Original Message-
From: JS Huang [js.hu...@protective.com]
Date: 02/26/2015 03:22 AM
To: r-help@r-project.org
Subject: Re: [R] How many digits are there in left of dot of 0.0001 ?

Hi,

  To get the number of digits to the right of decimal point: 
nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)+1) -1.  

  The part (trunc(log10(max(1,trunc(abs(a)+1) is the number of digits to
the left of decimal.  At the end, subtract 1 for the decimal point.

  Negative number needs more work.

 options(digits=10)
 a - 0.0001
 nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)+1)
 -1
[1] 4
 a - 999.123456
 nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)+1)
 -1
[1] 6



--
View this message in context: 
http://r.789695.n4.nabble.com/How-many-digits-are-there-in-left-of-dot-of-0-0001-tp4703842p4703849.html
Sent from the R help mailing list archive at Nabble.com.

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

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


Re: [R] Replace the value with 1 and 0

2015-02-26 Thread Göran Broström



On 2015-02-26 00:33, JS Huang wrote:

Hi,

   Here is an implementation.  More data are added.  An extra column hasRain
is added instead of replacing column Amount.


rain

Year Month Day Amount
1  1950 1   10.0
2  1950 1   2   35.5
3  1950 1   3   17.8
4  1950 1   4   24.5
5  1950 1   5   12.3
6  1950 1   6   11.5
7  1950 1   75.7
8  1950 1   8   13.2
9  1950 1   9   11.3
10 1950 1  10   14.7
11 1950 1  11   11.9
12 1950 1  12   17.5
13 1950 1  138.1
14 1950 1  140.4
15 1950 1  150.0
16 1950 1  16   19.5
17 1950 1  17   10.7
18 1950 1  180.5
19 1950 1  19   12.7
20 1950 1  206.3
21 1950 2   10.0
22 1950 2   2   35.5
23 1950 2   3   17.8
24 1950 2   4   24.5
25 1950 2   5   12.3
26 1950 2   6   11.5
27 1950 2   75.7
28 1950 2   8   13.2
29 1950 2   9   11.3
30 1950 2  10   14.7
31 1950 2  11   11.9
32 1950 2  12   17.5
33 1950 2  138.1
34 1950 2  140.4
35 1950 2  150.0
36 1950 2  16   19.5
37 1950 2  17   10.7
38 1950 2  180.0
39 1950 2  190.0
40 1950 2  200.0

rain$hasRain - ifelse(rain$Amount0,1,0)


No! Better is

rain$hasRain - as.numeric(rain$Amount  0)

See previous discussions about the use of 'ifelse'.

Göran


rain

Year Month Day Amount hasRain
1  1950 1   10.0   0
2  1950 1   2   35.5   1
3  1950 1   3   17.8   1
4  1950 1   4   24.5   1
5  1950 1   5   12.3   1
6  1950 1   6   11.5   1
7  1950 1   75.7   1
8  1950 1   8   13.2   1
9  1950 1   9   11.3   1
10 1950 1  10   14.7   1
11 1950 1  11   11.9   1
12 1950 1  12   17.5   1
13 1950 1  138.1   1
14 1950 1  140.4   1
15 1950 1  150.0   0
16 1950 1  16   19.5   1
17 1950 1  17   10.7   1
18 1950 1  180.5   1
19 1950 1  19   12.7   1
20 1950 1  206.3   1
21 1950 2   10.0   0
22 1950 2   2   35.5   1
23 1950 2   3   17.8   1
24 1950 2   4   24.5   1
25 1950 2   5   12.3   1
26 1950 2   6   11.5   1
27 1950 2   75.7   1
28 1950 2   8   13.2   1
29 1950 2   9   11.3   1
30 1950 2  10   14.7   1
31 1950 2  11   11.9   1
32 1950 2  12   17.5   1
33 1950 2  138.1   1
34 1950 2  140.4   1
35 1950 2  150.0   0
36 1950 2  16   19.5   1
37 1950 2  17   10.7   1
38 1950 2  180.0   0
39 1950 2  190.0   0
40 1950 2  200.0   0

tapply(rain$hasRain,list(rain$Year,rain$Month),sum)

   1  2
1950 18 15






--
View this message in context: 
http://r.789695.n4.nabble.com/Replace-the-value-with-1-and-0-tp4703838p4703840.html
Sent from the R help mailing list archive at Nabble.com.

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



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


Re: [R] Processing key_column, begin_date, end_date in R

2015-02-26 Thread JS Huang
Hi,

  It's not as easy as I originally thought.  Here is a revision with the
function beginEnd to get it done.

 date
  key_column begin_dateend_date
1 123456 2013-01-01 2014-01-01 
2 123456 2013-07-01 2014-07-01 
3 789102 2012-03-01 2014-03-01 
4 789102 2015-02-01 2016-02-01 
5 789102 2015-02-06  2016-02-06
 beginEnd
function()
{
  date[order(date$key_column,date$begin_date),]
  key - numeric(0)
  begin - character(0)
  end - character(0)
  currentKey - as.numeric(date$key_column[1])
  key - c(key, currentKey)
  currentBegin - as.character(date$begin_date[1])
  begin - c(begin, currentBegin)
  currentEnd - as.character(date$end_date[1])
  for (i in 2:length(date$key_column))
  {
if (currentKey == as.numeric(date$key_column[i]))
{
  if (currentEnd = as.character(date$begin_date[i]))
  {
currentEnd - max(currentEnd, as.character(date$end_date[i]))
  }
  else
  {
end - c(end, currentEnd)
currentKey - as.numeric(date$key_column[i])
key - c(key, currentKey)
currentBegin - as.character(date$begin_date[i])
begin - c(begin, currentBegin)
currentEnd - as.character(date$end_date[i])
  }
  if (i == length(date$key_column))
  {
end - c(end, currentEnd)
  }
}
else
{
  end - c(end, currentEnd)
  currentKey - as.numeric(date$key_column[i])
  key - c(key, currentKey)
  currentBegin - as.character(date$begin_date[i])
  begin - c(begin, currentBegin)
  currentEnd - as.character(date$end_date[i])
  if (i == length(date$key_column))
  {
end - list(end, currentEnd)
  }
}
  }
  result - cbind(key, begin, end)
  colnames(result) - c(key.column,begin.date,end.date)
  return(result)
}
 beginEnd()
 key.column begin.date   end.date 
[1,] 123456   2013-01-01 2014-07-01 
[2,] 789102   2012-03-01 2014-03-01 
[3,] 789102   2015-02-01 2016-02-06 




--
View this message in context: 
http://r.789695.n4.nabble.com/Processing-key-column-begin-date-end-date-in-R-tp4703835p4703852.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] PEA and APE Tobit

2015-02-26 Thread hnlki
Hi,

I estimated a tobit model 
tobit.fit-tobit(y~x,left=0, right=Inf)  (library AER)
or
tobit2.fit-censReg(y~x, left=0, right=Inf) (librarycensReg)
I' have estimated the partial effect at the average as:
pea-(pnorm((colMeans(x)%*%tobit.fit$coef[-1])/tobit.fit$scale))%*%tobit.fitt$coef[-1]
and the average partial effect as:
ape-
(length(x[,1]))^(-1)*sum(pnorm((x%*%tobit.fit$coef[-1])/tobit.fit$scale))*tobit.fit$coef[-1]

I guess I did something wrong as 
 margEff( tobit2.fit) (library(censReg)
 gives a different result than my partial effect at the average. 

Any ideas about what I did wrong? 
I  did not find the underlying code of margEff. 

Kind regards, 




--
View this message in context: 
http://r.789695.n4.nabble.com/PEA-and-APE-Tobit-tp4703856.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How many digits are there in left of dot of 0.0001 ?

2015-02-26 Thread JS Huang
Hi,

  To get the number of digits to the right of decimal point: 
nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)+1) -1.  

  The part (trunc(log10(max(1,trunc(abs(a)+1) is the number of digits to
the left of decimal.  At the end, subtract 1 for the decimal point.

  Negative number needs more work.

 options(digits=10)
 a - 0.0001
 nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)+1)
 -1
[1] 4
 a - 999.123456
 nchar(format(a,scientific=FALSE))-(trunc(log10(max(1,trunc(abs(a)+1)
 -1
[1] 6



--
View this message in context: 
http://r.789695.n4.nabble.com/How-many-digits-are-there-in-left-of-dot-of-0-0001-tp4703842p4703849.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Best Mac for R

2015-02-26 Thread peter dalgaard

 On 26 Feb 2015, at 06:26 , Dan Murphy chiefmur...@gmail.com wrote:
 
 Quick responses as usual. Can always count on R-Help! Bert's point
 that it depends is key, of course. Mark and Karim reminded me that R
 does not use all cores natively. Putting those together, an expensive
 quad core machine is not necessary for simple package development,
 documentation, etc. And for hard core (no pun intended) analysis, a
 multi-core machine won't be fully utilized without parallel
 implementation of some type. Thanks all for your advice. Just what I
 was looking for.
 Dan
 

Notice though, that parallel features _can_ be exploited fairly easily on the 
multi-CPU Macs (it depends somewhat on whether you need fine-grained 
parallelism as in fast matrix operations or just embarrassingly parallel 
tasks like simulation studies - the former needs R to be linked against the 
Accelerate framework).

Also notice that the real Mac experts live on the R-SIG-Mac list and not so 
much on R-help.

-pd


 On Wed, Feb 25, 2015 at 2:53 PM, Karim Mezhoud kmezh...@gmail.com wrote:
 Hi,
 It is not so efficient to have the most speed processor or biggest RAM. In
 general One processor is working at the time.
 It is more interesting to work with Linux for multiple multi_thread package
 and 64 bit.
 I am not sure if turbo boost is working with R.
 http://stackoverflow.com/questions/1395309/how-to-make-r-use-all-processors
 
 
 On Wed, Feb 25, 2015 at 9:12 PM, Mark Sharp msh...@txbiomed.org wrote:
 
 For what I do, which does not require a lot of parallel work, the high end
 iMac was faster and much less expensive than the Mac Pro.
 
 Mark
 R. Mark Sharp, Ph.D.
 msh...@txbiomed.org
 
 
 
 
 
 On Feb 25, 2015, at 1:50 PM, Dan Murphy chiefmur...@gmail.com wrote:
 
 I am possibly in the market for a new laptop. Predominantly a Windows
 user, I owned a macbook pro 10 years ago and am considering going that
 route again. Does the standard advice still hold: Get the most
 powerful processor (i7), most ram (16GB), and largest internal storage
 (512GB), if affordable?
 thanks,
 dan
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 NOTICE:  This E-Mail (including attachments) is confidential and may be
 legally privileged.  It is covered by the Electronic Communications Privacy
 Act, 18 U.S.C.2510-2521.  If you are not the intended recipient, you are
 hereby notified that any retention, dissemination, distribution or copying
 of this communication is strictly prohibited.  Please reply to the sender
 that you have received this message in error, then delete it.
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 
 __
 R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

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


Re: [R-es] nueva en R

2015-02-26 Thread Jorge I Velez
Hola, Gloria.  Bienvenida!

Hay algunos manuales en la parte inferior de
http://cran.r-project.org/other-docs.html

Saludos cordiales,
Jorge.-


2015-02-26 22:36 GMT+11:00 Gloria Perez Fuentes fuper...@gmail.com:

 hola!soy nueva aqui, estoy haciendo un trabajo sobre R y toda la
 informacion que encuentro esta en ingles. me gustaria saber algun libro
 sobre R o donde podria conseguir buena informacion sobre el programa en
 espa�ol, ya sea de su funcionamiento, finalidad del programa,
 caracteristicas etc. Nunca he utilizado este programa. gracias.

 [[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


[R] aggregating variables (sum within groups)

2015-02-26 Thread David Studer
Hello everybody!

I have a (probabely very easy) problem. Even though I was looking in
several r-books
I could not find a suitable function to this problem, that's why I hope
that someone here
could help me:

# Sample data:
group-c(A,A,A,B,B,C,C,C)
var1-c(1,0,0,1,1,0,NA,1)
var2-c(0,1,NA,0,1,1,0,0)
testdata-data.frame(group, var1, var2)

Now, I'd like to generate two aggregated variables:

testdata$x- ???   should count the sum of var1 within each group (=4)
testdata$y- ???   should count the sum of var2 within each group (=3)

Therefore I am looking for a function like ave() which does not calculate
the mean value but a sum.

Thank you for any hints!

David

[[alternative HTML version deleted]]

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


Re: [R] aggregating variables (sum within groups)

2015-02-26 Thread Ivan Calandra

Hi David,

You have your answer in the question:
aggregate()

aggregate(cbind(var1,var2)~group, data=testdata, FUN=sum)

Although I am not sure what you intended to do with testdata$x- as 
the result cannot have the same number of rows than testdata



HTH,
Ivan

--
Ivan Calandra, ATER
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calan...@univ-reims.fr
https://www.researchgate.net/profile/Ivan_Calandra

Le 26/02/15 13:02, David Studer a écrit :

Hello everybody!

I have a (probabely very easy) problem. Even though I was looking in
several r-books
I could not find a suitable function to this problem, that's why I hope
that someone here
could help me:

# Sample data:
group-c(A,A,A,B,B,C,C,C)
var1-c(1,0,0,1,1,0,NA,1)
var2-c(0,1,NA,0,1,1,0,0)
testdata-data.frame(group, var1, var2)

Now, I'd like to generate two aggregated variables:

testdata$x- ???   should count the sum of var1 within each group (=4)
testdata$y- ???   should count the sum of var2 within each group (=3)

Therefore I am looking for a function like ave() which does not calculate
the mean value but a sum.

Thank you for any hints!

David

[[alternative HTML version deleted]]

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



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


Re: [R] How many digits are there in left of dot of 0.0001 ?

2015-02-26 Thread Duncan Murdoch
On 25/02/2015 8:55 PM, ce wrote:
 Dear all,
 
 I would like to count how many digits are there on the left of a the dot of a 
 numeric variable
 
 a=0.0001

This will depend on the formatting used.  If default formatting used by
as.character() is fine, then

nchar(sub(^[[:digit:]]*[.], , a))

should work. (Note that default formatting is scientific for 0.0001.) If
you want some other formatting, then format first, and pass a character
object, e.g.

chars - format(a, scientific = FALSE)
nchar(sub(^[[:digit:]]*[.], , chars))

Duncan Murdoch

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


Re: [R] aggregating variables (sum within groups)

2015-02-26 Thread Brandstätter Christian
Dear David,

your email is quite confusing. Do you want to get the sum for each group
(A,B,C) or each variable as would be indicated by your result?


sum by group:
aggregate(data=testdata,var1~group,sum)

count by group:
aggregate(data=testdata,var1~group,length)

sum by variable:
sum(na.omit(testdata$var1))

But homework shouldn't be posted on this list.
Best regards
Christian



2015-02-26 13:02 GMT+01:00 David Studer stude...@gmail.com:

 Hello everybody!

 I have a (probabely very easy) problem. Even though I was looking in
 several r-books
 I could not find a suitable function to this problem, that's why I hope
 that someone here
 could help me:

 # Sample data:
 group-c(A,A,A,B,B,C,C,C)
 var1-c(1,0,0,1,1,0,NA,1)
 var2-c(0,1,NA,0,1,1,0,0)
 testdata-data.frame(group, var1, var2)

 Now, I'd like to generate two aggregated variables:

 testdata$x- ???   should count the sum of var1 within each group (=4)
 testdata$y- ???   should count the sum of var2 within each group (=3)

 Therefore I am looking for a function like ave() which does not calculate
 the mean value but a sum.

 Thank you for any hints!

 David

 [[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


Re: [R] PEA and APE Tobit

2015-02-26 Thread hnlki
Dear Mr Henningsen,

I have read the posting guide but apparently not well enough.  I didn't find 
how to include R code in my post. I'll read it again and I'll try to give a 
clearer example.
Sorry for the inconvenience. 

Kind regards,
Annelies

 Op 26-feb.-2015 om 21:59 heeft Arne Henningsen-3 [via R] 
 ml-node+s789695n4703915...@n4.nabble.com het volgende geschreven:
 
 Dear Annelies 
 
 On 26 February 2015 at 09:12, hnlki [hidden email] wrote:
 
  I estimated a tobit model 
  tobit.fit-tobit(y~x,left=0, right=Inf)  (library AER) 
  or 
  tobit2.fit-censReg(y~x, left=0, right=Inf) (librarycensReg) 
  I' have estimated the partial effect at the average as: 
  pea-(pnorm((colMeans(x)%*%tobit.fit$coef[-1])/tobit.fit$scale))%*%tobit.fitt$coef[-1]
   
  and the average partial effect as: 
  ape- 
  (length(x[,1]))^(-1)*sum(pnorm((x%*%tobit.fit$coef[-1])/tobit.fit$scale))*tobit.fit$coef[-1]
   
  
  I guess I did something wrong as 
   margEff( tobit2.fit) (library(censReg) 
   gives a different result than my partial effect at the average. 
  
  Any ideas about what I did wrong? 
  I  did not find the underlying code of margEff.
 
 [...] 
 
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code. 
 
 Please follow the posting guide and provide a self-contained 
 reproducible example. 
 
 Best regards, 
 Arne 
 
 -- 
 Arne Henningsen 
 http://www.arne-henningsen.name
 
 __ 
 [hidden email] mailing list -- To UNSUBSCRIBE and more, see 
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code. 
 
 
 If you reply to this email, your message will be added to the discussion 
 below:
 http://r.789695.n4.nabble.com/PEA-and-APE-Tobit-tp4703856p4703915.html
 To unsubscribe from PEA and APE Tobit, click here.
 NAML




--
View this message in context: 
http://r.789695.n4.nabble.com/PEA-and-APE-Tobit-tp4703856p4703919.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

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


[R] get_map in ggplot doesn't allow the exact specification of my box's corners?

2015-02-26 Thread Dimitri Liakhovitski
Hello!

get_map help says:

location: an address, longitude/latitude pair (in that order), or
left/bottom/right/top bounding box

My code:

library(ggmap)
library(mapproj)

lat_bottom = 52.33  # bottom latitude of Berlin
lat_top= 52.5   # top latitude of Berlin
lon_left   = 13.0   # left longitude of Berlin
lon_rigth  = 13.95  # right longitude of Berlin

mymap - get_map(location = c(lon_left,lat_bottom,lon_rigth,lat_top),
source=google)
ggmap(mymap)

Why is it giving me a warning:
Warning: bounding box given to google - spatial extent only approximate.
converting bounding box to center/zoom specification. (experimental)

Does it mean that there is no way for me to create a map with these
exact corners?


Thank you!

-- 
Dimitri Liakhovitski

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


Re: [R] integrate with vector arguments

2015-02-26 Thread Hans W Borchers
marKo mtoncic at ffri.hr writes:

 I'm a bit stuck.
 I have to integrate a series of polynomial functions with vector
 arguments.

 v1-c(1:5)
 v2-c(1:5)

 f1-function (x) {v1*x+v2*x^2}

 The problem is that integrate(f1, 0, 1) does not work.


The point is not that there are vector arguments, but that your function
is vector-valued and so the generated error message below rightly says
evaluation of function gave a result of wrong length.

You could integrate each dimension separately or, e.g., you use quadv()
from package 'pracma' which handles vector-valued functions:

 v1 - v2 - 1:5
 f1-function (x) {v1*x+v2*x^2}

 library(pracma)
 quadv(f1, 0, 1, tol=1e-10)
$Q
[1] 0.833 1.667 2.500 3.333 4.167

$fcnt
[1] 13

$estim.prec
[1] 0.03

quadv() employs an adaptive Simpson quadrature where the recursion is
applied to all components at once.


 I does not, even if a pas the arguments (v1, v2)

 f1-function (x, v1, v2) {v1*x+v2*x^2}

 or if i try to vectorize the function

 f1-Vectorize(function(x, v1, v2){v1*x+v2*x^2},
 vectorize.args=c(v1, v2))

 integrate(f1, 0, 1) gives an error:

 Error in integrate(f1, 0, 1) :
   evaluation of function gave a result of wrong length

 Any help will be greatly appreciated.
 Thanks,

 Marko


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