Re: [R] About uniroot error

2018-09-25 Thread Tania Morgado Garcia
Thanks for your reply. You're right, return a vector. An example of the
dataset:
ts pu carbono
1 15 2.04
1 37 1.27
1 55 0.93
1 80 0.5
1 105 0.49
1 22 2.08
1 41 1.43
1 65 0.78

The data that originate the FCOS and FRCOS pattern functions are others,
which I only use to obtain the functions.

Thanks again

El mar., 25 sept. 2018 a las 10:29, Michael Dewey ()
escribió:

> Dear Tania
>
> Without your dataset I am not sure but a comment below to suggest where
> to look next.
>
> On 24/09/2018 18:37, Tania Morgado Garcia wrote:
> > Thanks for your answers. I continue to learn R and now I am detained in
> an
> > error with uniroot that I see happens to others but I can not find the
> > solution. Next the code
> >
> > x1 <- BAaxOrd$V1
> > y1 <- BAaxOrd$V2
> > x1R <- BAaxOrdRCOS$V1
> > y1R <- BAaxOrdRCOS$V2
> > FCOS1 <- splinefun(smooth.spline(x1,y1))
> > FRCOS1 <- splinefun(smooth.spline(x1R,y1R))
> > FCOS1 <- Vectorize(FCOS1)
> > FRCOS1 <- Vectorize(FRCOS1)
> >
> > req(input$file1)
> >tryCatch(
> >{
> >  df <- read.csv(input$file1$datapath,
> > header = input$header,
> > sep = "\t",
> > quote = '"')
> >},
> >error = function(e) {
> >  # return a safeError if a parsing error occurs
> >  stop(safeError(e))
> >}
> >  )
> >
> >  #if(input$disp == "head") {
> >   # return(head(df))
> >  #}
> >  #else {
> >
> ># Determine Carbon Reserve
> >for (row in 1:nrow(df)) {
> >  if(df$ts==1) {
> > prof <-
> > uniroot(f=function(x){FCOS1(x1)-df$carbono},interval=c(0,20))$root
> > limsup <- prof + df$pu
> > reserva <- integrate(FRCOS1,prof,limsup)$value
> >  }
>
> Are you sure that FCOS(x1) - df$carbono returns a scalar? It looks as
> though it returns a vector to me but without your data I am not sure so
> ignore my post if it does.
> >
> > The if is because there are several types of soil, but I only put one.
> The
> > error is
> >
> > Warning in if (is.na(f.lower)) stop("f.lower = f(lower) is NA") :
> >the condition has length > 1 and only the first element will be used
> > Warning in if (is.na(f.upper)) stop("f.upper = f(upper) is NA") :
> >the condition has length > 1 and only the first element will be used
> > Warning: Error in uniroot: f() values at end points not of opposite sign
> >
> > The file that I load with data has a single row with the values ts = 1,
> > carbon = 2.04 and pu = 15 (I left only that row to be able to determine
> the
> > origin of the error). The functions FCOS1 and FRCOS1 are monotone
> > decreasing.Graphic attachment of FCOS1
> >
> > I would appreciate some help in this regard
> >
> > thanks a lot
> > __
> > 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.
> >
>
> --
> Michael
> http://www.dewey.myzen.co.uk/home.html
>

[[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] About uniroot error

2018-09-25 Thread Michael Dewey

Dear Tania

Without your dataset I am not sure but a comment below to suggest where 
to look next.


On 24/09/2018 18:37, Tania Morgado Garcia wrote:

Thanks for your answers. I continue to learn R and now I am detained in an
error with uniroot that I see happens to others but I can not find the
solution. Next the code

x1 <- BAaxOrd$V1
y1 <- BAaxOrd$V2
x1R <- BAaxOrdRCOS$V1
y1R <- BAaxOrdRCOS$V2
FCOS1 <- splinefun(smooth.spline(x1,y1))
FRCOS1 <- splinefun(smooth.spline(x1R,y1R))
FCOS1 <- Vectorize(FCOS1)
FRCOS1 <- Vectorize(FRCOS1)

req(input$file1)
   tryCatch(
   {
 df <- read.csv(input$file1$datapath,
header = input$header,
sep = "\t",
quote = '"')
   },
   error = function(e) {
 # return a safeError if a parsing error occurs
 stop(safeError(e))
   }
 )

 #if(input$disp == "head") {
  # return(head(df))
 #}
 #else {

   # Determine Carbon Reserve
   for (row in 1:nrow(df)) {
 if(df$ts==1) {
prof <-
uniroot(f=function(x){FCOS1(x1)-df$carbono},interval=c(0,20))$root
limsup <- prof + df$pu
reserva <- integrate(FRCOS1,prof,limsup)$value
 }


Are you sure that FCOS(x1) - df$carbono returns a scalar? It looks as 
though it returns a vector to me but without your data I am not sure so 
ignore my post if it does.


The if is because there are several types of soil, but I only put one.  The
error is

Warning in if (is.na(f.lower)) stop("f.lower = f(lower) is NA") :
   the condition has length > 1 and only the first element will be used
Warning in if (is.na(f.upper)) stop("f.upper = f(upper) is NA") :
   the condition has length > 1 and only the first element will be used
Warning: Error in uniroot: f() values at end points not of opposite sign

The file that I load with data has a single row with the values ts = 1,
carbon = 2.04 and pu = 15 (I left only that row to be able to determine the
origin of the error). The functions FCOS1 and FRCOS1 are monotone
decreasing.Graphic attachment of FCOS1

I would appreciate some help in this regard

thanks a lot
__
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.



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

__
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] Instagram Analysis

2018-09-25 Thread Hasan Diwan
Michael,
On Tue, 25 Sep 2018 at 08:15, Michael Haenlein  wrote:
> I'm looking for an R package that allows me to analyze Instagram.
> Specifically I would like to download for a given account the list of other
> accounts that either this account follows or that follow this account (the
> followers and following numbers).
> any other way to get this information in an easy way?

Send a get request to
https://api.instagram.com/v1/users/{user-id}/follows?access_token=ACCESS-TOKEN
and you'll get JSON back with (among other things) the accounts said
user follows. Hope that helps... Feel free to drop me a line off-list
should you need further help. -- H


-- 
OpenPGP: https://sks-keyservers.net/pks/lookup?op=get=0xFEBAD7FFD041BBA1
If you wish to request my time, please do so using bit.ly/hd1AppointmentRequest.
Si vous voudrais faire connnaisance, allez a bit.ly/hd1AppointmentRequest.

Sent from my mobile device
Envoye de mon portable

__
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] Instagram Analysis

2018-09-25 Thread Michael Haenlein
Dear all,

I'm looking for an R package that allows me to analyze Instagram.
Specifically I would like to download for a given account the list of other
accounts that either this account follows or that follow this account (the
followers and following numbers).

I know there is instaR but this package is quite old (August 2016) and
seems not to have been updated in the meantime. Is there a new package or
any other way to get this information in an easy way?

Thanks,

Michael

[[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] For Loop

2018-09-25 Thread Martin Maechler
> Wensui Liu 
> on Sun, 23 Sep 2018 13:26:32 -0500 writes:

> what you measures is the "elapsed" time in the default
> setting. you might need to take a closer look at the
> beautiful benchmark() function and see what time I am
> talking about.

> I just provided tentative solution for the person asking
> for it and believe he has enough wisdom to decide what's
> best. why bother to judge others subjectively?  

Well, because  Ista Zahn is much much much better R programmer
than you, sorry to be blunt!

Martin

> On Sun, Sep 23, 2018 at 1:18 PM Ista Zahn 
> wrote:
>> 
>> On Sun, Sep 23, 2018 at 1:46 PM Wensui Liu
>>  wrote:
>> >
>> > actually, by the parallel pvec, the user time is a lot
>> shorter. or did > I somewhere miss your invaluable
>> insight?
>> >
>> > > c1 <- 1:100 > > len <- length(c1) > >
>> rbenchmark::benchmark(log(c1[-1]/c1[-len]), replications
>> = 100) > test replications elapsed relative user.self
>> sys.self > 1 log(c1[-1]/c1[-len]) 100 4.617 1 4.484 0.133
>> > user.child sys.child > 1 0 0 > >
>> rbenchmark::benchmark(pvec(1:(len - 1), mc.cores = 4,
>> function(i) log(c1[i + 1] / c1[i])), replications = 100)
>> > test > 1 pvec(1:(len - 1), mc.cores = 4, function(i)
>> log(c1[i + 1]/c1[i])) > replications elapsed relative
>> user.self sys.self user.child sys.child > 1 100 9.079 1
>> 2.571 4.138 9.736 8.046
>> 
>> Your output is mangled in my email, but on my system your
>> pvec approach takes more than twice as long:
>> 
>> c1 <- 1:100 len <- length(c1) library(parallel)
>> library(rbenchmark)
>> 
>> regular <- function() log(c1[-1]/c1[-len])
>> iterate.parallel <- function() { pvec(1:(len - 1),
>> mc.cores = 4, function(i) log(c1[i + 1] / c1[i])) }
>> 
>> benchmark(regular(), iterate.parallel(), replications =
>> 100, columns = c("test", "elapsed", "relative")) ## test
>> elapsed relative ## 2 iterate.parallel() 7.517 2.482 ## 1
>> regular() 3.028 1.000
>> 
>> Honestly, just use log(c1[-1]/c1[-len]). The code is
>> simple and easy to understand and it runs pretty
>> fast. There is usually no reason to make it more
>> complicated.  --Ista
>> 
>> > On Sun, Sep 23, 2018 at 12:33 PM Ista Zahn
>>  wrote:
>> > >
>> > > On Sun, Sep 23, 2018 at 10:09 AM Wensui Liu
>>  wrote:
>> > > >
>> > > > Why?
>> > >
>> > > The operations required for this algorithm are
>> vectorized, as are most > > operations in R. There is no
>> need to iterate through each element.  > > Using
>> Vectorize to achieve the iteration is no better than
>> using > > *apply or a for-loop, and betrays the same
>> basic lack of insight into > > basic principles of
>> programming in R.
>> > >
>> > > And/or, if you want a more practical reason:
>> > >
>> > > > c1 <- 1:100 > > > len <- 100 > > >
>> system.time( s1 <- log(c1[-1]/c1[-len])) > > user system
>> elapsed > > 0.031 0.004 0.035 > > > system.time(s2 <-
>> Vectorize(function(i) log(c1[i + 1] / c1[i])) (1:len)) >
>> > user system elapsed > > 1.258 0.022 1.282
>> > >
>> > > Best, > > Ista
>> > >
>> > > >
>> > > > On Sun, Sep 23, 2018 at 7:54 AM Ista Zahn
>>  wrote:
>> > > >>
>> > > >> On Sat, Sep 22, 2018 at 9:06 PM Wensui Liu
>>  wrote:
>> > > >> >
>> > > >> > or this one:
>> > > >> >
>> > > >> > (Vectorize(function(i) log(c1[i + 1] / c1[i]))
>> (1:len))
>> > > >>
>> > > >> Oh dear god no.
>> > > >>
>> > > >> >
>> > > >> > On Sat, Sep 22, 2018 at 4:16 PM rsherry8
>>  wrote:
>> > > >> > >
>> > > >> > >
>> > > >> > > It is my impression that good R programmers
>> make very little use of the > > >> > > for
>> statement. Please consider the following > > >> > > R
>> statement: > > >> > > for( i in 1:(len-1) ) s[i] =
>> log(c1[i+1]/c1[i], base = exp(1) ) > > >> > > One problem
>> I have found with this statement is that s must exist
>> before > > >> > > the statement is run. Can it be written
>> without using a for > > >> > > loop? Would that be
>> better?
>> > > >> > >
>> > > >> > > Thanks, > > >> > > Bob
>> > > >> > >
>> > > >> > > __
>> > > >> > > 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 > > >> >
>> 

[R-es] X Jornadas de R en Murcia. Julia Silge y François Husson

2018-09-25 Thread Antonio Maurandi López
Julia Silge y François Husson en las X Jornadas de R.

¡¡Ponentes muy cañeRos!! No faltéis

Más info en la web <- http://r-es.org/XjuR/


#*XJRes* 

** 
*https://twitter.com/xjurum/status/1015616224909197312?s=09*

-- 
Antonio Maurandi López
Secretario del Departamento Didáctica de las Ciencias Matemáticas y Sociales
Área de Didáctica de la Matemática
Planta 3ª, pasillo 3º. Despacho 3.22
Facultad de Educación
Universidad de Murcia
30110 Campus de Espinardo
Murcia

@. amaura...@um.es
T. 868 88 4594
http://gauss.inf.um.es/
http://gauss.inf.um.es/umur/
http://www.um.es/web/didactica-matematicas/
Blog: www.sae.saiblogs.inf.um.es
X JORNADAS DE USUARIOS DE R: http://r-es.org/XjuR/
---
Audentes fortuna iuvat


[[alternative HTML version deleted]]

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