Re: [R] sorting a dataframe

2015-06-21 Thread Bert Gunter
Diego:

Nonsense! Look at the results of your code -- you have failed to order
the results as had been requested by the OP. It's also unnecessarily
complicated. The following suffices (where I have used regular
expressions rather substring() to get the numeric part of the strings
-- **assuming** that the strings always consist of letters followed by
numeric digits).

 A = c(A1,A10,A11,A2)
  B = c(1,2,3,4)
  dat = data.frame(A,B)

 numbs - as.numeric(gsub([^[:digit:]]+,,dat$A))
 newdat - dat[order(numbs),]
 newdat
A B
1  A1 1
4  A2 4
2 A10 2
3 A11 3

Cheers,
Bert



Bert Gunter

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


On Sat, Jun 20, 2015 at 6:29 PM, Diego Miro d.miro1...@gmail.com wrote:
 Bogdan,

 Follow my suggestion.

 letter - substring(A, 1, 1)
 number - substring(A, 2, nchar(A))
 new.data - paste0(letter, formatC(as.numeric(number), width = 2, flag =
 0))
 Em 20/06/2015 21:21, Bogdan Tanasa tan...@gmail.com escreveu:

 Dear all,

 I am looking for a suggestion please regarding sorting a dataframe with
 alphanumerical components :

 let's assume we have :

 A = c(A1,A10,A11,A2)
 B = c(1,2,3,4)

 C = data.frame(A,B)

 how could I sort C data.frame in such a way that we have at the end :

 C$A in the order : A1, A2, A10, A11. thank you very much,

 -- bogdan

 [[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-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] sorting a dataframe

2015-06-21 Thread Diego Miro
Bogdan,

Follow my suggestion.

letter - substring(A, 1, 1)
number - substring(A, 2, nchar(A))
new.data - paste0(letter, formatC(as.numeric(number), width = 2, flag =
0))
Em 20/06/2015 21:21, Bogdan Tanasa tan...@gmail.com escreveu:

 Dear all,

 I am looking for a suggestion please regarding sorting a dataframe with
 alphanumerical components :

 let's assume we have :

 A = c(A1,A10,A11,A2)
 B = c(1,2,3,4)

 C = data.frame(A,B)

 how could I sort C data.frame in such a way that we have at the end :

 C$A in the order : A1, A2, A10, A11. thank you very much,

 -- bogdan

 [[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] Obtaining the Hessian for the last iteration of a BFGS in optimx

2015-06-21 Thread Olu Ola via R-help
Hello,
I am running a BFGS using optimx and would like to obtain the Hessian for the 
last iteration.

How can I go about this?

Thank you

__
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] two problems

2015-06-21 Thread Jeff Newmiller
I an not aware of any function or package named qcomhd in base R or in the CRAN 
contributed packages, nor did it turn up when I went searching for it there, so 
your failure to access it seems unsurprising.

Google does find some references to a Github package called WRS that supposedly 
contains such a function, but the reason given for not distributing it on CRAN 
is simply that the package does not contain full documentation. This rather 
pathetic excuse points out that such a package is likely to be very unhelpful 
for any new user of R. I would suggest that you learn a bit more about using R 
before diving into such murky waters, but if you want to push forward you will 
need to use a search engine and perhaps make email contact with the package 
author if you need help.
---
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 June 21, 2015 12:15:36 PM PDT, Juan Wu wujua...@gmail.com wrote:
Hi, list experts

I am totally a new user of the R package. I just tried to use qcomhd,
but
it gives me an error alarm, as below.

qcomhd(RT1, RT2, q = seq(.1, .9, by=.1))
Error: could not find function qcomhd

Then I try to install it, however, it seems that I am not able to
install
it. Also, in my screen, some chaos characters appear. I do not know the
reason.

 install.packages(qcomhd)
Installing package into
慍:/Users/kh645-admin/Documents/R/win-library/3.1?(as 憀ib?is
unspecified)
Warning in install.packages :
  package 憅comhd?is not available (for R version 3.1.2)

A second question is to closely follow this thread *[R] Vincentizing
Reaction Time data in R*

Gabriel, have you find a good solution for your searching? I am also
interested in the vincentizing RT method. Either in R or Matlab would
be
okay for me.

Thanks in advance,
J

   [[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] sorting a dataframe

2015-06-21 Thread Bogdan Tanasa
Thank you all again. It works with :

library(gtools)
dat[mixedorder(A),]

considering :

A = c(A1,A10,A11,A2)
B = c(1,2,3,4)
 dat = data.frame(A,B


On Sun, Jun 21, 2015 at 10:52 AM, Bert Gunter bgunter.4...@gmail.com
wrote:

 Diego:

 Nonsense! Look at the results of your code -- you have failed to order
 the results as had been requested by the OP. It's also unnecessarily
 complicated. The following suffices (where I have used regular
 expressions rather substring() to get the numeric part of the strings
 -- **assuming** that the strings always consist of letters followed by
 numeric digits).

  A = c(A1,A10,A11,A2)
   B = c(1,2,3,4)
   dat = data.frame(A,B)
 
  numbs - as.numeric(gsub([^[:digit:]]+,,dat$A))
  newdat - dat[order(numbs),]
  newdat
 A B
 1  A1 1
 4  A2 4
 2 A10 2
 3 A11 3

 Cheers,
 Bert



 Bert Gunter

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


 On Sat, Jun 20, 2015 at 6:29 PM, Diego Miro d.miro1...@gmail.com wrote:
  Bogdan,
 
  Follow my suggestion.
 
  letter - substring(A, 1, 1)
  number - substring(A, 2, nchar(A))
  new.data - paste0(letter, formatC(as.numeric(number), width = 2, flag =
  0))
  Em 20/06/2015 21:21, Bogdan Tanasa tan...@gmail.com escreveu:
 
  Dear all,
 
  I am looking for a suggestion please regarding sorting a dataframe with
  alphanumerical components :
 
  let's assume we have :
 
  A = c(A1,A10,A11,A2)
  B = c(1,2,3,4)
 
  C = data.frame(A,B)
 
  how could I sort C data.frame in such a way that we have at the end :
 
  C$A in the order : A1, A2, A10, A11. thank you very much,
 
  -- bogdan
 
  [[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.


[[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] more complex by with data.table???

2015-06-21 Thread Arunkumar Srinivasan
Ramiro,

`dt[, lapply(.SD, mean), by=name]` is the idiomatic way.

I suggest reading through the new HTML vignettes at
https://github.com/Rdatatable/data.table/wiki/Getting-started

Ista, thanks for linking to the new vignette.


On Wed, Jun 10, 2015 at 2:17 AM, Ista Zahn istaz...@gmail.com wrote:
 Hi Ramiro,

 There is a demonstration of this on the data.table wiki at
 https://rawgit.com/wiki/Rdatatable/data.table/vignettes/datatable-intro-vignette.html.
 You can do

 dt[, lapply(.SD, mean), by=name]

 or

 dt[, as.list(colMeans(.SD)), by=name]

 BTW, there are pretty straightforward ways to do this in base R as well, e.g,

 data.frame(t(sapply(split(df[-1], df$name), colMeans)))

 Best,
 Ista

 On Tue, Jun 9, 2015 at 4:22 PM, Ramiro Barrantes
 ram...@precisionbioassay.com wrote:
 Hello,

 I am trying to do something that I am able to do with the by function 
 within data.frame but can't figure out how to achieve with data.table.

 Consider

 dt-data.table(name=c(rep(a,5),rep(b,6)),var1=0:10,var2=20:30,var3=40:50)
 myFunction - function(x) { mean(x) }

 I am aware that I can do something like:

 dt[, .(meanVar1=myFunction(var1)) ,by=.(name)]

 but how could I do the equivalent of:

 df-data.frame(name=c(rep(a,5),rep(b,6)),var1=0:10,var2=20:30,var3=40:50)
 myFunction - function(x) { mean(x) }

 columnNames - c(var1,var2,var3)
 result - by(df, df$name, function(x) {
output - c()
for(col in columnNames) {
  output[col] - myFunction(x[,col])
}
   output
 })
 do.call(rbind,result)

 Thanks in advance,
 Ramiro

 [[alternative HTML version deleted]]

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

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

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


[R] two problems

2015-06-21 Thread Juan Wu
Hi, list experts

I am totally a new user of the R package. I just tried to use qcomhd, but
it gives me an error alarm, as below.

qcomhd(RT1, RT2, q = seq(.1, .9, by=.1))
Error: could not find function qcomhd

Then I try to install it, however, it seems that I am not able to install
it. Also, in my screen, some chaos characters appear. I do not know the
reason.

 install.packages(qcomhd)
Installing package into
慍:/Users/kh645-admin/Documents/R/win-library/3.1?(as 憀ib?is unspecified)
Warning in install.packages :
  package 憅comhd?is not available (for R version 3.1.2)

A second question is to closely follow this thread *[R] Vincentizing
Reaction Time data in R*

Gabriel, have you find a good solution for your searching? I am also
interested in the vincentizing RT method. Either in R or Matlab would be
okay for me.

Thanks in advance,
J

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