Re: [R] Gradient color to a line graph

2017-02-05 Thread Riyas MJ
Thank you so much. Both worked well. Thanks

On Sun, Feb 5, 2017 at 2:27 AM, Jeff Newmiller 
wrote:

> You haven't indicated what information you want to convey with this
> gradient.
>
> You also are using arrays where you should be using vectors, usually
> stored in a data frame.
>
> Here is one way using the contributed package ggplot2:
>
> library(ggplot2)
> DF <- data.frame( V1=1:10, V2=11:20, C=21:30 )
> p <- ggplot( DF, aes( x=V1, y=V2, colour=C ) ) +
> geom_line( size=2 ) +
> scale_colour_gradient( low="red", high="blue" )
> print( p )
>
>
> --
> Sent from my phone. Please excuse my brevity.
>
> On February 4, 2017 12:19:14 PM PST, David Winsemius <
> dwinsem...@comcast.net> wrote:
> >
> >> On Feb 4, 2017, at 9:14 AM, Riyas MJ  wrote:
> >>
> >> Hi all,
> >>
> >> I am a new user of R. I just did my first real program.
> >> I would like to know how to put a gradient (like rainbow() or
> >topo.colors,
> >> etc) to a* line* graph.
> >>
> >> Example:
> >> ar1=array(data=1:10,dim=9)
> >> ar2=array(data=11:20,dim=9)
> >> plot(ar1,ar2,type="l",col="red",lwd=3)
> >>
> >> Instead of a red color, I would like to make it in rainbow colors.
> >> Tried to do my own and tried searching but everywhere its about
> >giving
> >> gradient to point graph, not to a line graph. Please help, it is
> >needed for
> >
> >Install the plotrix package and look in its Index page for a function
> >name that has both `color` and `line` in its name.
>



-- 
Riyas MJ
Project assistant (PA -II)
Physical Oceanography Department (POD)
CSIR- National Institute of Oceanography (NIO)
Dona Paula, Goa - 403 004, India
Ph: +91 9037553320, +91 7083030397

[[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] Marg.fct function

2017-02-05 Thread Jeff Newmiller
It is not part of "R". You can dig through all of the packages that the author 
mentions,  or send an email to the author. 
-- 
Sent from my phone. Please excuse my brevity.

On February 5, 2017 11:44:40 AM PST, James Henson  wrote:
>Greetings R Community,
>
>An attempt to reproduce the results from code in the source below
>fails.  R cannot find the function ‘Marg.fct’. An Internet search for
>the ‘Marg.fct’ function was not fruitful.  I appreciate your help.
>Best regards, James F. Henson.
>
>R (and S-PLUS) Manual to Accompany Agresti’s Categorical Data Analysis
>(2002) 2nd edition Laura A. Thompson, 2009©
>
>http://www.stat.ufl.edu/~aa/cda/Thompson_manual.pdf  page 181
>
>The code is:
>
># Code from Manual to Accompany Agresti’s Categorical Data Analysis
>(2002) 2nd edition Laura A. Thompson, 2009
>
>y <- c(144, 33, 84, 126, 2, 4, 14, 29, 0, 2, 6, 25, 0, 0, 1, 5)
>
>ZF <- Z <- matrix(1,16,1)
>
>#
>
>M1 <- Marg.fct(1,rep(4,2)) # used to get m1+, etc
>
>Error: could not find function "Marg.fct"
>
>
>
>M2 <- Marg.fct(2,rep(4,2)) # used to get m+1, etc
>
>#
>
>C.matrix <- matrix(c(
>
>  1, 0, 0, 0, -1, 0, 0, 0, # y1+ = y+1
>
>  0, 1, 0, 0, 0, -1, 0, 0, # y2+ = y+2
>
>  0, 0, 1, 0, 0, 0, -1, 0), # y3+ = y+3
>
>  3,8,byrow=T)
>
>h.fct <- function(m) { # constraint function
>
> marg <- rbind(M1%*%m, M2%*%m) # y1+, y2+, y3+, y4+, y+1, y+2, y+3, y+4
>
>  C.matrix%*%marg # y1+ = y+1, y2+ = y+2, etc
>
>}
>
>#
>
>a <- mph.fit(y=y,Z=Z,ZF=ZF,h.fct=h.fct)
>
>mph.summary(a)
>
>__
>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] Marg.fct function

2017-02-05 Thread peter dalgaard

> On 05 Feb 2017, at 20:44 , James Henson  wrote:
> 
> Greetings R Community,
> 
> An attempt to reproduce the results from code in the source below
> fails.  R cannot find the function ‘Marg.fct’. An Internet search for
> the ‘Marg.fct’ function was not fruitful.  I appreciate your help.
> Best regards, James F. Henson.

I have no specific knowledge of this, but Thompson's document refers to 
MPH.FIT, and if you google that, you get to 

http://homepage.stat.uiowa.edu/~jblang/mph.fitting/mph.fit.documentation.2.0.htm

which tells you that to get the software, you should contact the author. And 
"please do not distribute", etc.

You could try that, but the document is from 2007, so there is some risk that 
you will experience an example of the "bitrot" that CRAN was designed to 
avoid...

-pd

> 
> R (and S-PLUS) Manual to Accompany Agresti’s Categorical Data Analysis
> (2002) 2nd edition Laura A. Thompson, 2009©
> 
> http://www.stat.ufl.edu/~aa/cda/Thompson_manual.pdf  page 181
> 
> The code is:
> 
> # Code from Manual to Accompany Agresti’s Categorical Data Analysis
> (2002) 2nd edition Laura A. Thompson, 2009
> 
> y <- c(144, 33, 84, 126, 2, 4, 14, 29, 0, 2, 6, 25, 0, 0, 1, 5)
> 
> ZF <- Z <- matrix(1,16,1)
> 
> #
> 
> M1 <- Marg.fct(1,rep(4,2)) # used to get m1+, etc
> 
> Error: could not find function "Marg.fct"
> 
> 
> 
> M2 <- Marg.fct(2,rep(4,2)) # used to get m+1, etc
> 
> #
> 
> C.matrix <- matrix(c(
> 
>  1, 0, 0, 0, -1, 0, 0, 0, # y1+ = y+1
> 
>  0, 1, 0, 0, 0, -1, 0, 0, # y2+ = y+2
> 
>  0, 0, 1, 0, 0, 0, -1, 0), # y3+ = y+3
> 
>  3,8,byrow=T)
> 
> h.fct <- function(m) { # constraint function
> 
>  marg <- rbind(M1%*%m, M2%*%m) # y1+, y2+, y3+, y4+, y+1, y+2, y+3, y+4
> 
>  C.matrix%*%marg # y1+ = y+1, y2+ = y+2, etc
> 
> }
> 
> #
> 
> a <- mph.fit(y=y,Z=Z,ZF=ZF,h.fct=h.fct)
> 
> mph.summary(a)
> 
> __
> 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
Office: A 4.23
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.

[R] Marg.fct function

2017-02-05 Thread James Henson
Greetings R Community,

An attempt to reproduce the results from code in the source below
fails.  R cannot find the function ‘Marg.fct’. An Internet search for
the ‘Marg.fct’ function was not fruitful.  I appreciate your help.
Best regards, James F. Henson.

R (and S-PLUS) Manual to Accompany Agresti’s Categorical Data Analysis
(2002) 2nd edition Laura A. Thompson, 2009©

http://www.stat.ufl.edu/~aa/cda/Thompson_manual.pdf  page 181

The code is:

# Code from Manual to Accompany Agresti’s Categorical Data Analysis
(2002) 2nd edition Laura A. Thompson, 2009

y <- c(144, 33, 84, 126, 2, 4, 14, 29, 0, 2, 6, 25, 0, 0, 1, 5)

ZF <- Z <- matrix(1,16,1)

#

M1 <- Marg.fct(1,rep(4,2)) # used to get m1+, etc

Error: could not find function "Marg.fct"



M2 <- Marg.fct(2,rep(4,2)) # used to get m+1, etc

#

C.matrix <- matrix(c(

  1, 0, 0, 0, -1, 0, 0, 0, # y1+ = y+1

  0, 1, 0, 0, 0, -1, 0, 0, # y2+ = y+2

  0, 0, 1, 0, 0, 0, -1, 0), # y3+ = y+3

  3,8,byrow=T)

h.fct <- function(m) { # constraint function

  marg <- rbind(M1%*%m, M2%*%m) # y1+, y2+, y3+, y4+, y+1, y+2, y+3, y+4

  C.matrix%*%marg # y1+ = y+1, y2+ = y+2, etc

}

#

a <- mph.fit(y=y,Z=Z,ZF=ZF,h.fct=h.fct)

mph.summary(a)

__
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] mean of a column in a list of data frames

2017-02-05 Thread Rui Barradas

Hello,

Try instead the following.

aList<- numeric(3)
for(i in 1:3){
  aList[i] <- mean(ownersList[[i]]$grossIncome)
}
aList

Hope this helps,

Rui Barradas


Em 05-02-2017 12:01, Brandon Payne escreveu:

I have a list of data frames,

 ownersList <- list(exp2004owners,exp2005owners,
exp2006owners,exp2007owners,
exp2008owners,exp2009owners,
exp2010owners,exp2011owners,
exp2012owners,exp2013owners,
exp2014owners)

  I want to take the mean of the first column $grossIncome.
  I can access the first column with

lapply(ownersList, "[[", 1)  ##works

But I can't take the mean of that.
mean(lapply(ownersList, "[[", 1))  ##not working

There must be a more idiomatic way to write this with map or apply.

ownersIncome<- c(mean(ownersList[[1]]$grossIncome),
  mean(ownersList[[2]]$grossIncome),
  mean(ownersList[[3]]$grossIncome),
  mean(ownersList[[4]]$grossIncome),
  mean(ownersList[[5]]$grossIncome),
  mean(ownersList[[6]]$grossIncome),
  mean(ownersList[[7]]$grossIncome),
  mean(ownersList[[8]]$grossIncome),
  mean(ownersList[[9]]$grossIncome),
  mean(ownersList[[10]]$grossIncome),
  mean(ownersList[[11]]$grossIncome))

I tried a for loop, which also didn't work.

aList<-
 for(i in 1:3){
 mean(ownersList[[i]]$grossIncome)
}
aList

[[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] mean of a column in a list of data frames

2017-02-05 Thread Duncan Murdoch

On 05/02/2017 7:01 AM, Brandon Payne wrote:

I have a list of data frames,

ownersList <- list(exp2004owners,exp2005owners,
   exp2006owners,exp2007owners,
   exp2008owners,exp2009owners,
   exp2010owners,exp2011owners,
   exp2012owners,exp2013owners,
   exp2014owners)

 I want to take the mean of the first column $grossIncome.
 I can access the first column with

lapply(ownersList, "[[", 1)  ##works

But I can't take the mean of that.
mean(lapply(ownersList, "[[", 1))  ##not working


lapply returns a list of the first columns, and mean() doesn't know what 
to do with that.


There must be a more idiomatic way to write this with map or apply.


Yes, take the mean inside lapply:

lapply(ownersList, function(x) mean(x[[1]]))

Not tested.

Duncan Murdoch



ownersIncome<- c(mean(ownersList[[1]]$grossIncome),
 mean(ownersList[[2]]$grossIncome),
 mean(ownersList[[3]]$grossIncome),
 mean(ownersList[[4]]$grossIncome),
 mean(ownersList[[5]]$grossIncome),
 mean(ownersList[[6]]$grossIncome),
 mean(ownersList[[7]]$grossIncome),
 mean(ownersList[[8]]$grossIncome),
 mean(ownersList[[9]]$grossIncome),
 mean(ownersList[[10]]$grossIncome),
 mean(ownersList[[11]]$grossIncome))

I tried a for loop, which also didn't work.

aList<-
for(i in 1:3){
mean(ownersList[[i]]$grossIncome)
}


for loops don't have a useful value:  it's always NULL.  This would have 
worked as


aList <- list()
for(i in 1:3){
aList[[i]] <- mean(ownersList[[i]]$grossIncome)
}


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] mean of a column in a list of data frames

2017-02-05 Thread Brandon Payne
I have a list of data frames,

ownersList <- list(exp2004owners,exp2005owners,
   exp2006owners,exp2007owners,
   exp2008owners,exp2009owners,
   exp2010owners,exp2011owners,
   exp2012owners,exp2013owners,
   exp2014owners)

 I want to take the mean of the first column $grossIncome.
 I can access the first column with

lapply(ownersList, "[[", 1)  ##works

But I can't take the mean of that.
mean(lapply(ownersList, "[[", 1))  ##not working

There must be a more idiomatic way to write this with map or apply.

ownersIncome<- c(mean(ownersList[[1]]$grossIncome),
 mean(ownersList[[2]]$grossIncome),
 mean(ownersList[[3]]$grossIncome),
 mean(ownersList[[4]]$grossIncome),
 mean(ownersList[[5]]$grossIncome),
 mean(ownersList[[6]]$grossIncome),
 mean(ownersList[[7]]$grossIncome),
 mean(ownersList[[8]]$grossIncome),
 mean(ownersList[[9]]$grossIncome),
 mean(ownersList[[10]]$grossIncome),
 mean(ownersList[[11]]$grossIncome))

I tried a for loop, which also didn't work.

aList<-
for(i in 1:3){
mean(ownersList[[i]]$grossIncome)
}
aList

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