Re: [R] Looking for a more elegant solution than a loop

2015-10-26 Thread William Dunlap
> identical(as.list(x), xz)
[1] TRUE
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Oct 26, 2015 at 6:31 PM, Erin Hodgess  wrote:
> Hello!
>
> The following (which is a toy example) works fine, but I wonder if there is
> a better or more elegant way than to do the loop:
>
>  xz <- vector("list",length=4)
>  x <- 6:9
>  for(i in 1:4)xz[[i]] <- x[i]
>  xz
> [[1]]
> [1] 6
>
> [[2]]
> [1] 7
>
> [[3]]
> [1] 8
>
> [[4]]
> [1] 9
>
> This does exactly what I want, but the "for" loop seems out of place.
> Maybe not.
>
> Thanks,
> Sincerely
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.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-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] Looking for a more elegant solution than a loop

2015-10-26 Thread Erin Hodgess
Beautiful

Thanks so much!
Erin


On Mon, Oct 26, 2015 at 8:47 PM, Fox, John  wrote:

> Dear Erin,
>
> How about
>
> > x <- 6:9
> > as.list(x)
> [[1]]
> [1] 6
>
> [[2]]
> [1] 7
>
> [[3]]
> [1] 8
>
> [[4]]
> [1] 9
>
> Best,
>  John
>
> -
> John Fox, Professor
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> Web: socserv.mcmaster.ca/jfox
>
>
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Erin
> > Hodgess
> > Sent: October 26, 2015 9:32 PM
> > To: R help 
> > Subject: [R] Looking for a more elegant solution than a loop
> >
> > Hello!
> >
> > The following (which is a toy example) works fine, but I wonder if there
> is a
> > better or more elegant way than to do the loop:
> >
> >  xz <- vector("list",length=4)
> >  x <- 6:9
> >  for(i in 1:4)xz[[i]] <- x[i]
> >  xz
> > [[1]]
> > [1] 6
> >
> > [[2]]
> > [1] 7
> >
> > [[3]]
> > [1] 8
> >
> > [[4]]
> > [1] 9
> >
> > This does exactly what I want, but the "for" loop seems out of place.
> > Maybe not.
> >
> > Thanks,
> > Sincerely
> > Erin
> >
> >
> > --
> > Erin Hodgess
> > Associate Professor
> > Department of Mathematical and Statistics University of Houston -
> > Downtown
> > mailto: erinm.hodg...@gmail.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.
>



-- 
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodg...@gmail.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.


Re: [R] Looking for a more elegant solution than a loop

2015-10-26 Thread Fox, John
Dear Erin,

How about

> x <- 6:9
> as.list(x)
[[1]]
[1] 6

[[2]]
[1] 7

[[3]]
[1] 8

[[4]]
[1] 9

Best,
 John

-
John Fox, Professor
McMaster University
Hamilton, Ontario
Canada L8S 4M4
Web: socserv.mcmaster.ca/jfox



> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Erin
> Hodgess
> Sent: October 26, 2015 9:32 PM
> To: R help 
> Subject: [R] Looking for a more elegant solution than a loop
> 
> Hello!
> 
> The following (which is a toy example) works fine, but I wonder if there is a
> better or more elegant way than to do the loop:
> 
>  xz <- vector("list",length=4)
>  x <- 6:9
>  for(i in 1:4)xz[[i]] <- x[i]
>  xz
> [[1]]
> [1] 6
> 
> [[2]]
> [1] 7
> 
> [[3]]
> [1] 8
> 
> [[4]]
> [1] 9
> 
> This does exactly what I want, but the "for" loop seems out of place.
> Maybe not.
> 
> Thanks,
> Sincerely
> Erin
> 
> 
> --
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics University of Houston -
> Downtown
> mailto: erinm.hodg...@gmail.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-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] Looking for a more elegant solution than a loop

2015-10-26 Thread Erin Hodgess
Hello!

The following (which is a toy example) works fine, but I wonder if there is
a better or more elegant way than to do the loop:

 xz <- vector("list",length=4)
 x <- 6:9
 for(i in 1:4)xz[[i]] <- x[i]
 xz
[[1]]
[1] 6

[[2]]
[1] 7

[[3]]
[1] 8

[[4]]
[1] 9

This does exactly what I want, but the "for" loop seems out of place.
Maybe not.

Thanks,
Sincerely
Erin


-- 
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodg...@gmail.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.


Re: [R] Formating time in R

2015-10-26 Thread Cacique Samurai
Hello Jean!

Thanks very much for your help and assistence! Works very fine!

All best,

Raoni

2015-10-26 17:02 GMT-02:00 Adams, Jean :
> Raoni,
>
> You could write your own function to do this.  For example, using the period
> class from the R package lubridate, you could do something like this:
>
> days2 <- function(x) {
>   h1 <- 24*x
>   h <- floor(h1)
>   m1 <- 60*(h1 - h)
>   m <- floor(m1)
>   s <- round(60*(m1 - m))
>   new_period(second=s, minute=m, hour=h)
> }
>
> library(lubridate)
> test <- c(1.424708, 0.028674)
> days2(test)
>
> [1] "34H 11M 35S" "41M 17S"
>
> Jean
>
> On Mon, Oct 26, 2015 at 1:48 PM, Cacique Samurai 
> wrote:
>>
>> Hello R-Helpers!
>>
>> I have a vector of times of events that time is fraction of 1, because
>> it was calculated in excel. Are there some way to format a period
>> greater than 24h in a format like excel [h]:mm:ss?
>>
>> Exemple:
>>
>> test = c(1.424708, 0.028674)
>>
>> > chron (times. = test [2], format = "h:m:S")
>> [1] 00:41:17
>>
>> > chron (times. = test, format = "h:m:S")
>> Time in days:
>> [1] 1.424708 0.028674
>>
>> I need an output like:
>>
>> 34:11:35 0:41:17
>>
>> Thanks in advanced,
>>
>> Raoni
>>
>> --
>> Raoni Rosa Rodrigues
>> Research Associate of Fish Transposition Center CTPeixes
>> Universidade Federal de Minas Gerais - UFMG
>> Brasil
>> rodrigues.ra...@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.
>
>



-- 
Raoni Rosa Rodrigues
Research Associate of Fish Transposition Center CTPeixes
Universidade Federal de Minas Gerais - UFMG
Brasil
rodrigues.ra...@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] Number of digits to display?

2015-10-26 Thread David L Carlson
Just to elaborate on Marc's comment:

> set.seed(42)
> x <- runif(1)
> dput(x) # What R is storing as x
0.914806043496355
> print(x)# Ways to display an approximation of x
[1] 0.914806
> print(x, digits=3)
[1] 0.915
> round(x, 2)
[1] 0.91
> signif(x, 4)
[1] 0.9148
> library(MASS)
> fractions(x)
[1] 7334/8017
> dput(x) # But x is still the same
0.914806043496355


David L. Carlson
Department of Anthropology
Texas A&M University

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marc Schwartz
Sent: Monday, October 26, 2015 2:40 PM
To: Judson 
Cc: R-help 
Subject: Re: [R] Number of digits to display?


> On Oct 26, 2015, at 11:43 AM, Judson  wrote:
> 
> How do I control the number of digits to display, 
> say, in a matrix, without rounding or losing accuracy
> in subsequent calculations? 
> round() of course reduces accuracy.   
> 
> Also, if all my results
> are really fractions, is there a way to display 
> them as fractions of integers rather than 
> decimal expressions?   
> 
> ... judson blake


Hi,

You need to differentiate between the way in which R *stores* numeric values 
and the way in which it *displays* numeric values.

If you want to affect the display of values in routine output, see ?options and 
note 'digits' and 'scipen'.

Also see ?print.default.

Those approaches do not affect the precision of calculations on the *stored* 
values.

For fractions, see:

  require(MASS)
  ?fractions

Regards,

Marc Schwartz

__
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] Function help

2015-10-26 Thread Jim Lemon
Hi Alexander,
I suspect that when you write "try" you mean that you try to run the
function with some value for "pid". The "unexpected symbol" error message
usually includes the offending symbol and that will probably identify the
problem.

Jim

On Mon, Oct 26, 2015 at 1:20 PM,  wrote:

> Hello,
>
> I'm following an example in the book, analyzing baseball data with R, but
> it's not working for me. The example is:
>
> compute.hr <- function(pid){d <- subset(Batting.60, playerID==pid)
> sum(d$HR)}
>
> Every time I try this, it says there's an unexpected symbol. Any idea on
> what the unexpected symbol is or how to fix it? Thanks.
>
> __
> 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] y2z question (AGD)

2015-10-26 Thread David L Carlson
Thanks for this. I knew that na.exclude() existed, but never understood how to 
combine it with naresid().

David C

-Original Message-
From: William Dunlap [mailto:wdun...@tibco.com] 
Sent: Monday, October 26, 2015 1:46 PM
To: David L Carlson
Cc: Martin Canon; R help
Subject: Re: [R] y2z question (AGD)

You can also use the na.exclude function, which is like na.omit but attaches
an attribute, "na.action", telling which rows were removed.  Then use the
naresid function to insert NA's into the right places in the output of
the function
that only works properly on NA-less data.  E.g.,

cleanData <- na.exclude(data)
data$zeta <- naresid(attr(cleanData, "na.action"), with(cleanData,
y2z(weight, age/12, sex, ref=who.wgt)))
data
#  sex weight age   zeta
#1   M8.5   8 -0.124
#2   M8.2   9 -0.751
#3   M9.0  12 -0.635
#4   F NA   9 NA
#5   M5.8   1  2.002

It is a little wordy, but it does handle both vector and matrix data.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sun, Oct 25, 2015 at 10:53 AM, David L Carlson  wrote:
> It looks like the y2z() function strips NA's so that the vector lengths do 
> not match any longer. The simplest workaround is to remove the NA's. You 
> could do that by using data2 <- na.omit(data) to strip the observations with 
> NA if they will not be used in the rest of the analysis.
>
> If you want to preserve the NAs in the data frame, this seems to work:
>
>> nomiss <- complete.cases(data)
>> data$zeta[nomiss] <- with(data[nomiss, ], y2z(weight, age/12, sex, 
>> ref=who.wgt))
>> data
>   sex weight age   zeta
> 1   M8.5   8 -0.124
> 2   M8.2   9 -0.751
> 3   M9.0  12 -0.635
> 4   F NA   9 NA
> 5   M5.8   1  2.002
>
>
> David L. Carlson
> Department of Anthropology
> Texas A&M University
>
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Canon
> Sent: Sunday, October 25, 2015 7:03 AM
> To: R help 
> Subject: [R] y2z question (AGD)
>
> Hi to all.
>
> I've been trying to calculate weight-for-age z-scores with the y2z
> command (AGD package).
>
> However, I keep getting strange results.
>
> My hypothesis is that missings are the problem.
>
> My dataframe looks like this:
>
> data <- structure(list(sex = structure(c(3L, 3L, 3L, 2L, 3L), .Label = c("",
> "F", "M"), class = "factor"), weight = c(8.5, 8.2, 9, NA, 5.8),
> age = c(8, 9, 12, 9, 1)), .Names = c("sex", "weight", "age"
> ), class = "data.frame", row.names = c(NA, 5L))
>
> Weight is in kg and age in months.
> I will use WHO curves for children younger than 2 years of age.
>
> z-score calculation:
>
> library(AGD)
> data$zeta <- y2z(y = data$weight, x = data$age/12, sex = data$sex,
> ref = get("who.wgt"))
>
> I get:
>
> Warning message:
> In `split<-.default`(`*tmp*`, f, drop = drop, value = value) :
>   number of items to replace is not a multiple of replacement length
>
> data$zeta
> [1] NA NA NA -0.124 NA
>
> However a for loop seems to work.
>
> for (i in 1:5) {
>
>   data$zeta[i] <- y2z(y = data$weight[i],
>  x = data$age[i]/12,
>  sex = data$sex[i],
> ref = get("who.wgt"))
> }
>
> data$zeta
> [1] -0.124 -0.751 -0.635 NA  2.002
>
> Is there a workaround so that I don't have to use a for loop?
> na.action doesn't work either.
>
> Thanks.
>
>
> Martin
>
> __
> 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.


Re: [R] Number of digits to display?

2015-10-26 Thread Duncan Murdoch
On 26/10/2015 12:43 PM, Judson wrote:
> How do I control the number of digits to display, 
> say, in a matrix, without rounding or losing accuracy
> in subsequent calculations? 
> round() of course reduces accuracy.   
> 
> Also, if all my results
> are really fractions, is there a way to display 
> them as fractions of integers rather than 
> decimal expressions?   

See the fractions() function in the MASS package.

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] Number of digits to display?

2015-10-26 Thread Marc Schwartz

> On Oct 26, 2015, at 11:43 AM, Judson  wrote:
> 
> How do I control the number of digits to display, 
> say, in a matrix, without rounding or losing accuracy
> in subsequent calculations? 
> round() of course reduces accuracy.   
> 
> Also, if all my results
> are really fractions, is there a way to display 
> them as fractions of integers rather than 
> decimal expressions?   
> 
> ... judson blake


Hi,

You need to differentiate between the way in which R *stores* numeric values 
and the way in which it *displays* numeric values.

If you want to affect the display of values in routine output, see ?options and 
note 'digits' and 'scipen'.

Also see ?print.default.

Those approaches do not affect the precision of calculations on the *stored* 
values.

For fractions, see:

  require(MASS)
  ?fractions

Regards,

Marc Schwartz

__
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] Number of digits to display?

2015-10-26 Thread William Dunlap
> myMatrix <- outer(c(1,24,30,75,96), 20:25, "/")
> print(myMatrix, digits=3)
 [,1]   [,2]   [,3]   [,4]   [,5] [,6]
[1,] 0.05 0.0476 0.0455 0.0435 0.0417 0.04
[2,] 1.20 1.1429 1.0909 1.0435 1. 0.96
[3,] 1.50 1.4286 1.3636 1.3043 1.2500 1.20
[4,] 3.75 3.5714 3.4091 3.2609 3.1250 3.00
[5,] 4.80 4.5714 4.3636 4.1739 4. 3.84
> MASS::fractions(myMatrix)
 [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
[1,]  1/20  1/21  1/22  1/23  1/24  1/25
[2,]   6/5   8/7 12/11 24/23 1 24/25
[3,]   3/2  10/7 15/11 30/23   5/4   6/5
[4,]  15/4  25/7 75/22 75/23  25/8 3
[5,]  24/5  32/7 48/11 96/23 4 96/25

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Oct 26, 2015 at 9:43 AM, Judson  wrote:
> How do I control the number of digits to display,
> say, in a matrix, without rounding or losing accuracy
> in subsequent calculations?
> round() of course reduces accuracy.
>
> Also, if all my results
> are really fractions, is there a way to display
> them as fractions of integers rather than
> decimal expressions?
>
> ... judson blake
>
> [[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] My simple ORDER is broken

2015-10-26 Thread William Dunlap
Show us the output of
   str(tmp_df)
Your problem could be caused by the Democratic column being
a character or factor column instead of a numeric column:
"71" > "227" but 71 < 227.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Oct 26, 2015 at 9:08 AM, Jim Burke  wrote:
> tmp_df[order(tmp_df$Democratic),]
>Precinct Last.Name Democratic Republican.Total Registered.Voters
> 2  2904 Open Seat  1015
> NA 2903 Open Seat227  245  2035
> 3  2905 Open Seat 71  202   497
>
>
> tmp_df[order(tmp_df[3]),]
>Precinct Last.Name Democratic Republican.Total Registered.Voters
> 2  2904 Open Seat  1015
> NA 2903 Open Seat227  245  2035
> 3  2905 Open Seat 71  202   497
>
>> tmp_df$Democratic[order(tmp_df$Democratic)]
> [1] "1"   "227" "71"
>
> What am I doing wrong? I would like the order below. I suspect the problem
> lies with that NA to the left that R inserted somewhere along the line. So
> how to reorder dataframe rows? Or get rid of that NA?
> 2  2904 Open Seat  1015
> 3  2905 Open Seat 71  202   497
> NA 2903 Open Seat227  245  2035
>
> Thanks,
> Jim Burke
>
> [[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] Number of digits to display?

2015-10-26 Thread Jorge I Velez
Dear Judson,

Perhaps the following example would give you some ideas:

R> options(digits = 4)
R> rnorm(5)
#[1] -0.57089 -0.14759  0.05717 -0.04935  2.22123
R> options(digits = 3)
R> rnorm(5)
#[1]  0.789  0.616  0.156 -1.315 -1.090
R> options(digits = 2)
R> rnorm(5)
#[1] -1.04 -0.58 -0.50  0.30  0.60

​Best regards,
Jorge.-


On Mon, Oct 26, 2015 at 11:43 AM, Judson  wrote:

> How do I control the number of digits to display,
> say, in a matrix, without rounding or losing accuracy
> in subsequent calculations?
> round() of course reduces accuracy.
>
> Also, if all my results
> are really fractions, is there a way to display
> them as fractions of integers rather than
> decimal expressions?
>
> ... judson blake
>
> [[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] My simple ORDER is broken

2015-10-26 Thread Jim Burke
tmp_df[order(tmp_df$Democratic),]
   Precinct Last.Name Democratic Republican.Total Registered.Voters
2  2904 Open Seat  1015
NA 2903 Open Seat227  245  2035
3  2905 Open Seat 71  202   497


tmp_df[order(tmp_df[3]),]
   Precinct Last.Name Democratic Republican.Total Registered.Voters
2  2904 Open Seat  1015
NA 2903 Open Seat227  245  2035
3  2905 Open Seat 71  202   497

> tmp_df$Democratic[order(tmp_df$Democratic)]
[1] "1"   "227" "71"

What am I doing wrong? I would like the order below. I suspect the problem
lies with that NA to the left that R inserted somewhere along the line. So
how to reorder dataframe rows? Or get rid of that NA?
2  2904 Open Seat  1015
3  2905 Open Seat 71  202   497
NA 2903 Open Seat227  245  2035

Thanks,
Jim Burke

[[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] Number of digits to display?

2015-10-26 Thread Judson
How do I control the number of digits to display, 
say, in a matrix, without rounding or losing accuracy
in subsequent calculations? 
round() of course reduces accuracy.   

Also, if all my results
are really fractions, is there a way to display 
them as fractions of integers rather than 
decimal expressions?   

... judson blake
  
[[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] Formating time in R

2015-10-26 Thread Adams, Jean
Raoni,

You could write your own function to do this.  For example, using the
period class from the R package lubridate, you could do something like this:

days2 <- function(x) {
  h1 <- 24*x
  h <- floor(h1)
  m1 <- 60*(h1 - h)
  m <- floor(m1)
  s <- round(60*(m1 - m))
  new_period(second=s, minute=m, hour=h)
}

library(lubridate)
test <- c(1.424708, 0.028674)
days2(test)

[1] "34H 11M 35S" "41M 17S"

Jean

On Mon, Oct 26, 2015 at 1:48 PM, Cacique Samurai 
wrote:

> Hello R-Helpers!
>
> I have a vector of times of events that time is fraction of 1, because
> it was calculated in excel. Are there some way to format a period
> greater than 24h in a format like excel [h]:mm:ss?
>
> Exemple:
>
> test = c(1.424708, 0.028674)
>
> > chron (times. = test [2], format = "h:m:S")
> [1] 00:41:17
>
> > chron (times. = test, format = "h:m:S")
> Time in days:
> [1] 1.424708 0.028674
>
> I need an output like:
>
> 34:11:35 0:41:17
>
> Thanks in advanced,
>
> Raoni
>
> --
> Raoni Rosa Rodrigues
> Research Associate of Fish Transposition Center CTPeixes
> Universidade Federal de Minas Gerais - UFMG
> Brasil
> rodrigues.ra...@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.
>

[[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] Formating time in R

2015-10-26 Thread Cacique Samurai
Hello R-Helpers!

I have a vector of times of events that time is fraction of 1, because
it was calculated in excel. Are there some way to format a period
greater than 24h in a format like excel [h]:mm:ss?

Exemple:

test = c(1.424708, 0.028674)

> chron (times. = test [2], format = "h:m:S")
[1] 00:41:17

> chron (times. = test, format = "h:m:S")
Time in days:
[1] 1.424708 0.028674

I need an output like:

34:11:35 0:41:17

Thanks in advanced,

Raoni

-- 
Raoni Rosa Rodrigues
Research Associate of Fish Transposition Center CTPeixes
Universidade Federal de Minas Gerais - UFMG
Brasil
rodrigues.ra...@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] y2z question (AGD)

2015-10-26 Thread William Dunlap
You can also use the na.exclude function, which is like na.omit but attaches
an attribute, "na.action", telling which rows were removed.  Then use the
naresid function to insert NA's into the right places in the output of
the function
that only works properly on NA-less data.  E.g.,

cleanData <- na.exclude(data)
data$zeta <- naresid(attr(cleanData, "na.action"), with(cleanData,
y2z(weight, age/12, sex, ref=who.wgt)))
data
#  sex weight age   zeta
#1   M8.5   8 -0.124
#2   M8.2   9 -0.751
#3   M9.0  12 -0.635
#4   F NA   9 NA
#5   M5.8   1  2.002

It is a little wordy, but it does handle both vector and matrix data.

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sun, Oct 25, 2015 at 10:53 AM, David L Carlson  wrote:
> It looks like the y2z() function strips NA's so that the vector lengths do 
> not match any longer. The simplest workaround is to remove the NA's. You 
> could do that by using data2 <- na.omit(data) to strip the observations with 
> NA if they will not be used in the rest of the analysis.
>
> If you want to preserve the NAs in the data frame, this seems to work:
>
>> nomiss <- complete.cases(data)
>> data$zeta[nomiss] <- with(data[nomiss, ], y2z(weight, age/12, sex, 
>> ref=who.wgt))
>> data
>   sex weight age   zeta
> 1   M8.5   8 -0.124
> 2   M8.2   9 -0.751
> 3   M9.0  12 -0.635
> 4   F NA   9 NA
> 5   M5.8   1  2.002
>
>
> David L. Carlson
> Department of Anthropology
> Texas A&M University
>
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Canon
> Sent: Sunday, October 25, 2015 7:03 AM
> To: R help 
> Subject: [R] y2z question (AGD)
>
> Hi to all.
>
> I've been trying to calculate weight-for-age z-scores with the y2z
> command (AGD package).
>
> However, I keep getting strange results.
>
> My hypothesis is that missings are the problem.
>
> My dataframe looks like this:
>
> data <- structure(list(sex = structure(c(3L, 3L, 3L, 2L, 3L), .Label = c("",
> "F", "M"), class = "factor"), weight = c(8.5, 8.2, 9, NA, 5.8),
> age = c(8, 9, 12, 9, 1)), .Names = c("sex", "weight", "age"
> ), class = "data.frame", row.names = c(NA, 5L))
>
> Weight is in kg and age in months.
> I will use WHO curves for children younger than 2 years of age.
>
> z-score calculation:
>
> library(AGD)
> data$zeta <- y2z(y = data$weight, x = data$age/12, sex = data$sex,
> ref = get("who.wgt"))
>
> I get:
>
> Warning message:
> In `split<-.default`(`*tmp*`, f, drop = drop, value = value) :
>   number of items to replace is not a multiple of replacement length
>
> data$zeta
> [1] NA NA NA -0.124 NA
>
> However a for loop seems to work.
>
> for (i in 1:5) {
>
>   data$zeta[i] <- y2z(y = data$weight[i],
>  x = data$age[i]/12,
>  sex = data$sex[i],
> ref = get("who.wgt"))
> }
>
> data$zeta
> [1] -0.124 -0.751 -0.635 NA  2.002
>
> Is there a workaround so that I don't have to use a for loop?
> na.action doesn't work either.
>
> Thanks.
>
>
> Martin
>
> __
> 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.


Re: [R] [FORGED] Re: How to correct documentation?

2015-10-26 Thread Duncan Murdoch

On 26/10/2015 11:43 AM, Ming-Lun Ho wrote:

Hi All,
 So, coming back to the original point, how do I get the info to change
the documentation to someone who has the capability to do so? For all I
know, that could be one of you who responded, but I wouldn't know.


Posting the suggestion here is easiest; it's not 100% reliable (because 
people who can make the change might miss it), but it usually works.


If it doesn't (i.e. you post and get no response), you can post it as a 
bug report on bugs.r-project.org, but that's more work to handle, so it 
shouldn't be your first place to go.


If you post here and get an argument about whether your suggestion is 
correct (as in this case), then you shouldn't post it as a bug report.  
This is the place for arguments, the bug list is *not*.


Duncan Murdoch



 Thanks.
 --Ming

On Sun, Oct 25, 2015, 08:11 peter dalgaard  wrote:

>
> > On 25 Oct 2015, at 14:37 , Bert Gunter  wrote:
> >
> > Yes. Too cute, maybe?
> >
>
> ...as in "charming" or...
>
>
>
>
>
> Oh.
>
> ;-)
> pd
>
> > -- Bert
> > Bert Gunter
> >
> > "Data is not information. Information is not knowledge. And knowledge
> > is certainly not wisdom."
> >   -- Clifford Stoll
> >
> >
> > On Sat, Oct 24, 2015 at 9:57 PM, Rolf Turner 
> wrote:
> >> On 25/10/15 17:14, John Sorkin wrote:
> >>>
> >>> Bert Talking about Loglan and problems with the imprecise nature of
> >>> English, which sense of sanction do you mean
> >>>
> >>> to authorize, approve, or allow: an expression now sanctioned by
> >>> educated usage. to ratify or confirm: to sanction a law. to impose a
> >>> sanction on; penalize, especially by way of discipline.
> >>
> >>
> >>
> >> Uh, that was Bert's point I believe.  I.e. he was deliberately striving
> for
> >> ambiguity.
> >>
> >>
> >> cheers,
> >>
> >> Rolf
> >>
> >> --
> >> Technical Editor ANZJS
> >> Department of Statistics
> >> University of Auckland
> >> Phone: +64-9-373-7599 ext. 88276
> >
> > __
> > 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
>
>
>
>
>
>
>
>
>

[[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] Creating new variables in R

2015-10-26 Thread Duncan Murdoch

On 26/10/2015 12:38 PM, peter dalgaard wrote:

pmax() should work even without the fancy stuff. However, as Petr pointed out, so should 
the ifelse construct, unless there is more to the issue than we have been told. So I 
think Jennifer needs to elaborate on the "didn't work" aspect...


Her syntax was incorrect in the original posting, that's all.

Duncan Murdoch


-pd

On 26 Oct 2015, at 13:02 , Erich Neuwirth  wrote:

> data <- within(data,variable3=pmax(variable1,variable2))
> also should work if your variables are numeric.
>
> using dplyr and magrittr (which I recommend to all my students)
> it could be
>
> library(dplyr)
> library(magrittr)
> data %<>% mutate(variable3=pmax(variable1,variable2))
>
>
>
>> On 26 Oct 2015, at 12:53, PIKAL Petr  wrote:
>>
>> Hi
>>
>>> -Original Message-
>>> From: R-help [mailto:r-help-boun...@r-project.org 
] On Behalf Of Duncan
>>> Murdoch
>>> Sent: Monday, October 26, 2015 11:58 AM
>>> To: Lorenz, Jennifer; r-help@r-project.org 
>>> Subject: Re: [R] Creating new variables in R
>>>
>>> On 26/10/2015 6:24 AM, Lorenz, Jennifer wrote:
 Hi,

 I  have a question regarding the creation of new variables on the
>>> basis of existing ones in R.

 I have two variables containing information on parents' educational
>>> degree (e.g. 1 'high school degree', 2 'college degree', etc.). I would
>>> like to create a new variable for 'parents' highest educational
>>> degree', i.e. if variable1 (father's degree) is higher than variable2
>>> (mother's degree) than the new variable (variable3) should take on the
>>> value of variable1, if not, than variable3 should take on the value of
>>> variable2.

 I usually use SPSS for data manipulation, there I would code
>>> variable3 as follows:
 COMPUTE variable3= 0.
 IF variable1 > variable2 variable3= variable1.
 IF variable1 <= variable2 variable3= variable2.

 The closest I came to that in R was with this code:
 data$variable3 <- 0
 data$variable3[data$variable1 > data$variable2]<-data$variable1
 data$variable3[data$variable1 <= data$variable2]<-data$variable2

 I also tried:
 data$variable3 <- ifelse(data$variable1 > data$variable2),
 data$variable1, data$variable2)

 Both didn't work.
>>
>> The ifelse version should work. Are you sure that variable 1 and 2 are 
numeric?.
>>
>> What is a result of str(data)?
>>
>> Cheers
>> Petr
>>

 I am not sure if my post is at all understandable (this is my first
>>> time posting on R-help), but I am really hoping for some advice!
>>>
>>> This is a good place to use the ifelse() function:
>>>
>>> data$variable3 <- ifelse(data$variable1 > data$variable2,
>>>data$variable1, data$variable2)
>>>
>>> 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.
>>
>> 
>> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou 
určeny pouze jeho adresátům.
>> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého 
systému.
>> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
>> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.
>>
>> V případě, že je tento e-mail součástí obchodního jednání:
>> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, 
a to z jakéhokoliv důvodu i bez uvedení důvodu.
>> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s 
dodatkem či odchylkou.
>> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
>> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za 
společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo 
písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu 
případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je 
adresátovi či osobě jím zastoupené známá.
>>
>> This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
>> If you received this e-mail by mistake, please immediately inform its 
sender. Delete the contents of this e-mail with all attachments and its copies from 
your system.
>> If you are not the intended recipient of this e-mail, you are not authorized 
to use, disseminate, cop

Re: [R] Creating new variables in R

2015-10-26 Thread peter dalgaard
pmax() should work even without the fancy stuff. However, as Petr pointed out, 
so should the ifelse construct, unless there is more to the issue than we have 
been told. So I think Jennifer needs to elaborate on the "didn't work" aspect...

-pd

On 26 Oct 2015, at 13:02 , Erich Neuwirth  wrote:

> data <- within(data,variable3=pmax(variable1,variable2))
> also should work if your variables are numeric.
> 
> using dplyr and magrittr (which I recommend to all my students)
> it could be
> 
> library(dplyr)
> library(magrittr)
> data %<>% mutate(variable3=pmax(variable1,variable2))
> 
> 
> 
>> On 26 Oct 2015, at 12:53, PIKAL Petr  wrote:
>> 
>> Hi
>> 
>>> -Original Message-
>>> From: R-help [mailto:r-help-boun...@r-project.org 
>>> ] On Behalf Of Duncan
>>> Murdoch
>>> Sent: Monday, October 26, 2015 11:58 AM
>>> To: Lorenz, Jennifer; r-help@r-project.org 
>>> Subject: Re: [R] Creating new variables in R
>>> 
>>> On 26/10/2015 6:24 AM, Lorenz, Jennifer wrote:
 Hi,
 
 I  have a question regarding the creation of new variables on the
>>> basis of existing ones in R.
 
 I have two variables containing information on parents' educational
>>> degree (e.g. 1 'high school degree', 2 'college degree', etc.). I would
>>> like to create a new variable for 'parents' highest educational
>>> degree', i.e. if variable1 (father's degree) is higher than variable2
>>> (mother's degree) than the new variable (variable3) should take on the
>>> value of variable1, if not, than variable3 should take on the value of
>>> variable2.
 
 I usually use SPSS for data manipulation, there I would code
>>> variable3 as follows:
 COMPUTE variable3= 0.
 IF variable1 > variable2 variable3= variable1.
 IF variable1 <= variable2 variable3= variable2.
 
 The closest I came to that in R was with this code:
 data$variable3 <- 0
 data$variable3[data$variable1 > data$variable2]<-data$variable1
 data$variable3[data$variable1 <= data$variable2]<-data$variable2
 
 I also tried:
 data$variable3 <- ifelse(data$variable1 > data$variable2),
 data$variable1, data$variable2)
 
 Both didn't work.
>> 
>> The ifelse version should work. Are you sure that variable 1 and 2 are 
>> numeric?.
>> 
>> What is a result of str(data)?
>> 
>> Cheers
>> Petr
>> 
 
 I am not sure if my post is at all understandable (this is my first
>>> time posting on R-help), but I am really hoping for some advice!
>>> 
>>> This is a good place to use the ifelse() function:
>>> 
>>> data$variable3 <- ifelse(data$variable1 > data$variable2,
>>>data$variable1, data$variable2)
>>> 
>>> 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.
>> 
>> 
>> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou 
>> určeny pouze jeho adresátům.
>> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
>> jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
>> svého systému.
>> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
>> jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
>> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
>> zpožděním přenosu e-mailu.
>> 
>> V případě, že je tento e-mail součástí obchodního jednání:
>> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, 
>> a to z jakéhokoliv důvodu i bez uvedení důvodu.
>> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
>> Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany 
>> příjemce s dodatkem či odchylkou.
>> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
>> dosažením shody na všech jejích náležitostech.
>> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za 
>> společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn 
>> nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto 
>> emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich 
>> existence je adresátovi či osobě jím zastoupené známá.
>> 
>> This e-mail and any documents attached to it may be confidential and are 
>> intended only for its intended recipients.
>> If you received this e-mail by mistake, please immediately inform its 
>> sender. Delete the contents of this e-mail with all attachments and its 
>> copies from your system.
>> If you are not the intended recipient of this e-mail, you are not authorized 
>> to use, disseminate, copy or disclose this e-mail in any manner.
>> T

Re: [R] y2z question (AGD)

2015-10-26 Thread Martin Canon
Thank you, David.

This solves the problem.

Regards,

Martin

On Sun, Oct 25, 2015 at 12:53 PM, David L Carlson  wrote:

> It looks like the y2z() function strips NA's so that the vector lengths do
> not match any longer. The simplest workaround is to remove the NA's. You
> could do that by using data2 <- na.omit(data) to strip the observations
> with NA if they will not be used in the rest of the analysis.
>
> If you want to preserve the NAs in the data frame, this seems to work:
>
> > nomiss <- complete.cases(data)
> > data$zeta[nomiss] <- with(data[nomiss, ], y2z(weight, age/12, sex,
> ref=who.wgt))
> > data
>   sex weight age   zeta
> 1   M8.5   8 -0.124
> 2   M8.2   9 -0.751
> 3   M9.0  12 -0.635
> 4   F NA   9 NA
> 5   M5.8   1  2.002
>
>
> David L. Carlson
> Department of Anthropology
> Texas A&M University
>
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Martin
> Canon
> Sent: Sunday, October 25, 2015 7:03 AM
> To: R help 
> Subject: [R] y2z question (AGD)
>
> Hi to all.
>
> I've been trying to calculate weight-for-age z-scores with the y2z
> command (AGD package).
>
> However, I keep getting strange results.
>
> My hypothesis is that missings are the problem.
>
> My dataframe looks like this:
>
> data <- structure(list(sex = structure(c(3L, 3L, 3L, 2L, 3L), .Label =
> c("",
> "F", "M"), class = "factor"), weight = c(8.5, 8.2, 9, NA, 5.8),
> age = c(8, 9, 12, 9, 1)), .Names = c("sex", "weight", "age"
> ), class = "data.frame", row.names = c(NA, 5L))
>
> Weight is in kg and age in months.
> I will use WHO curves for children younger than 2 years of age.
>
> z-score calculation:
>
> library(AGD)
> data$zeta <- y2z(y = data$weight, x = data$age/12, sex = data$sex,
> ref = get("who.wgt"))
>
> I get:
>
> Warning message:
> In `split<-.default`(`*tmp*`, f, drop = drop, value = value) :
>   number of items to replace is not a multiple of replacement length
>
> data$zeta
> [1] NA NA NA -0.124 NA
>
> However a for loop seems to work.
>
> for (i in 1:5) {
>
>   data$zeta[i] <- y2z(y = data$weight[i],
>  x = data$age[i]/12,
>  sex = data$sex[i],
> ref = get("who.wgt"))
> }
>
> data$zeta
> [1] -0.124 -0.751 -0.635 NA  2.002
>
> Is there a workaround so that I don't have to use a for loop?
> na.action doesn't work either.
>
> Thanks.
>
>
> Martin
>
> __
> 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] elementwise matrix multiplication with a special structure

2015-10-26 Thread eugen pircalabelu via R-help
Hello again,
Thanks for your reply and sorry for my own late reply!  I am writing from a 
normal yahoo account so i don't know why it behaves like this. I was looking to 
avoid the expand.grid command because my matrices are of size 800x800 (i have 
some filters that exclude out some elements, so i don't need to pass by 
everything, but still) which is quickly too heavy for R but still doable in C. 
Thanks a lot and have  a great day ahead!Eugen



 

 From: David L Carlson 
 To: eugen pircalabelu  
 Sent: Friday, October 23, 2015 9:21 PM
 Subject: RE: [R] elementwise matrix multiplication with a special structure
   
Don't use html formatted emails. The r-help server strips the html formatting 
leaving us the the mess you see below. 

You don't need any loops:

> aa <- matrix(1:9, 3, 3)
> bb <- aa * 10
> cc <- bb * 10
> x <- as.matrix(expand.grid(k=1:3, j=1:3, c=1:3, r=1:3))
> str(x)
 int [1:81, 1:4] 1 2 3 1 2 3 1 2 3 1 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:4] "k" "j" "c" "r"
> dd <- aa[x[, c("j", "k")]] * bb[x[, c("r", "j")]] * cc[x[, c("k", "c")]]
> dd
 [1]  1000  8000  21000  8000  4  96000  21000  84000 189000
[10]  4000  2  42000  32000 10 192000  84000 21 378000
[19]  7000  32000  63000  56000 16 288000 147000 336000 567000
[28]  2000  16000  42000  1  5 12  24000  96000 216000
[37]  8000  4  84000  4 125000 24  96000 24 432000
[46]  14000  64000 126000  7 20 36 168000 384000 648000
[55]  3000  24000  63000  12000  6 144000  27000 108000 243000
[64]  12000  6 126000  48000 15 288000 108000 27 486000
[73]  21000  96000 189000  84000 24 432000 189000 432000 729000

# Or a bit more compactly
> dd <- aa[x[, c(2, 1)]] * bb[x[, c(4, 2)]] * cc[x[, c(1, 3)]]

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352





-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of eugen 
pircalabelu via R-help
Sent: Friday, October 23, 2015 12:31 PM
To: r-help@r-project.org
Subject: [R] elementwise matrix multiplication with a special structure

Hello R users,
I have the following annoying matrix multiplication and I do not know how to 
avoid the nested loops, so maybe someone can help me with some ideas. I have 
searched the forum for past posts but nothing came up.Here it is:
 aa=matrix(1:9,3,3) bb=matrix(seq(10,90,by=10),3,3) cc=matrix(seq(100,900, 
by=100),3,3) dd=NULL 
for(r in 1:3){for(c in 1:3){for(j in 1:3){for(k in 
1:3){dd=c(dd,aa[j,k]*bb[r,j]*cc[k,c])dd [1]   1000   8000  21000   8000  
4  96000  21000  84000 189000   4000[11]  2  42000  32000 10 192000 
 84000 21 378000   7000  32000[21]  63000  56000 16 288000 147000 
336000 567000   2000  16000  42000[31]  1  5 12  24000  96000 
216000   8000  4  84000  4[41] 125000 24  96000 24 432000  
14000  64000 126000  7 20[51] 36 168000 384000 648000   3000  24000 
 63000  12000  6 144000[61]  27000 108000 243000  12000  6 126000  
48000 15 288000 108000[71] 27 486000  21000  96000 189000  84000 24 
432000 189000 432000[81] 729000
What I want to obtain is the content of the vector dd in an efficient (fast) 
and clever way.Thank you very much and have a great day ahead!Eugen

    [[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] [FORGED] Re: How to correct documentation?

2015-10-26 Thread Ming-Lun Ho
Hi All,
So, coming back to the original point, how do I get the info to change
the documentation to someone who has the capability to do so? For all I
know, that could be one of you who responded, but I wouldn't know.
Thanks.
--Ming

On Sun, Oct 25, 2015, 08:11 peter dalgaard  wrote:

>
> > On 25 Oct 2015, at 14:37 , Bert Gunter  wrote:
> >
> > Yes. Too cute, maybe?
> >
>
> ...as in "charming" or...
>
>
>
>
>
> Oh.
>
> ;-)
> pd
>
> > -- Bert
> > Bert Gunter
> >
> > "Data is not information. Information is not knowledge. And knowledge
> > is certainly not wisdom."
> >   -- Clifford Stoll
> >
> >
> > On Sat, Oct 24, 2015 at 9:57 PM, Rolf Turner 
> wrote:
> >> On 25/10/15 17:14, John Sorkin wrote:
> >>>
> >>> Bert Talking about Loglan and problems with the imprecise nature of
> >>> English, which sense of sanction do you mean
> >>>
> >>> to authorize, approve, or allow: an expression now sanctioned by
> >>> educated usage. to ratify or confirm: to sanction a law. to impose a
> >>> sanction on; penalize, especially by way of discipline.
> >>
> >>
> >>
> >> Uh, that was Bert's point I believe.  I.e. he was deliberately striving
> for
> >> ambiguity.
> >>
> >>
> >> cheers,
> >>
> >> Rolf
> >>
> >> --
> >> Technical Editor ANZJS
> >> Department of Statistics
> >> University of Auckland
> >> Phone: +64-9-373-7599 ext. 88276
> >
> > __
> > 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
>
>
>
>
>
>
>
>
>

[[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] Formating time in R

2015-10-26 Thread Cacique Samurai
Hello R-Helpers!

I have a vector of times of events that time is fraction of 1, because it
was calculated in excel. Are there some way to format a period greater than
24h in a format like excel [h]:mm:ss?

Exemple:

test = c(1.424708, 0.028674)

> chron (times. = test [2], format = "h:m:S")
[1] 00:41:17

> chron (times. = test, format = "h:m:S")
Time in days:
[1] 1.424708 0.028674

I need an output like:

*34:11:35* 0:41:17

Thanks in advanced,

Raoni
-- 
Raoni Rosa Rodrigues
Research Associate of Fish Transposition Center CTPeixes
Universidade Federal de Minas Gerais - UFMG
Brasil
rodrigues.ra...@gmail.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.


Re: [R] Having trouble updating and installing R 3.2.1 and 3.2.2

2015-10-26 Thread Jeff Newmiller
I have not used W10, but for quite awhile the *administrator" account (not the 
hidden one named "Administrator") has merely had the right to "Run As 
Administrator"... but doing so explicitly is not recommended unless you 
definitely know what you are doing (in which case you should not be asking for 
help here). As long as you let the UAC (User Account Control) prompt you at the 
necessary moments you should not have permissions trouble. If you have followed 
this advice already then there might be a bug in the installer, but I would 
have thought I would have seen more complaints by now if it was a bug.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  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 October 26, 2015 6:16:47 AM PDT, Keith S Weintraub  wrote:
>I uninstalled all versions of R on my computer and killed all R
>directories (I think).
>
>I am wondering that since I “upgraded” to Windows 10 is it possible
>that I should create a user separate from the administrator account? My
>previous version of Windows was 7 Home I think. 
>
>Here is a longer version of the error messages that I get.
>
>> install.packages("sm")
>Installing package into ‘C:/Users/Administrator/My
>Documents/R/win-library/3.2’
>(as ‘lib’ is unspecified)
>--- Please select a CRAN mirror for use in this session ---
>Warning: unable to access index for repository
>https://cran.cnr.Berkeley.edu/src/contrib
>Warning: unable to access index for repository
>https://cran.cnr.Berkeley.edu/bin/windows/contrib/3.2
>Warning messages:
>1: In normalizePath(path.expand(path), winslash, mustWork) :
>path[1]="C:/Users/Administrator/My Documents/R/win-library/3.2": Access
>is denied
>2: package ‘sm’ is not available (for R version 3.2.2) 
>
>
>Thanks for your help,
>KW
>
>
>> On Oct 25, 2015, at 7:15 PM, Jeff Newmiller
> wrote:
>> 
>> I would guess that you ran R as administrator at some point and now
>you have a permissions problem on your user library. I can't say I know
>how to fix it, though using administrator mode to fix the permissions
>is probably hard while using administrator mode to delete the R
>directory and reinstalling your packages might be easier.
>>
>---
>> Jeff NewmillerThe .   .  Go
>Live...
>> DCN:Basics: ##.#.   ##.#.  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 October 25, 2015 7:50:07 AM PDT, Keith S Weintraub
> wrote:
>>> I get the following error:
>>> 
>>> Warning message:
>>> In normalizePath(path.expand(path), winslash, mustWork) :
>>> path[1]="C:\Users\Administrator\My Documents/R/win-library/3.2":
>Access
>>> is denied
>>> 
>>> This may be the first time that I have tried to upgrade R since I
>>> upgraded my Windows installation (on Parallels on my Mac no less) to
>>> Windows 10.
>>> 
>>> Needless to say when I try to install packages outside of core CRAN
>I
>>> have issues.
>>> 
>>> Any help is greatly appreciated.
>>> 
>>> Thanks much,
>>> KW
>>> 
>>> __
>>> 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] Having trouble updating and installing R 3.2.1 and 3.2.2

2015-10-26 Thread Keith S Weintraub
I uninstalled all versions of R on my computer and killed all R directories (I 
think).

I am wondering that since I “upgraded” to Windows 10 is it possible that I 
should create a user separate from the administrator account? My previous 
version of Windows was 7 Home I think. 

Here is a longer version of the error messages that I get.

> install.packages("sm")
Installing package into ‘C:/Users/Administrator/My Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository 
https://cran.cnr.Berkeley.edu/src/contrib
Warning: unable to access index for repository 
https://cran.cnr.Berkeley.edu/bin/windows/contrib/3.2
Warning messages:
1: In normalizePath(path.expand(path), winslash, mustWork) :
  path[1]="C:/Users/Administrator/My Documents/R/win-library/3.2": Access is 
denied
2: package ‘sm’ is not available (for R version 3.2.2) 


Thanks for your help,
KW


> On Oct 25, 2015, at 7:15 PM, Jeff Newmiller  wrote:
> 
> I would guess that you ran R as administrator at some point and now you have 
> a permissions problem on your user library. I can't say I know how to fix it, 
> though using administrator mode to fix the permissions is probably hard while 
> using administrator mode to delete the R directory and reinstalling your 
> packages might be easier.
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  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 October 25, 2015 7:50:07 AM PDT, Keith S Weintraub  
> wrote:
>> I get the following error:
>> 
>> Warning message:
>> In normalizePath(path.expand(path), winslash, mustWork) :
>> path[1]="C:\Users\Administrator\My Documents/R/win-library/3.2": Access
>> is denied
>> 
>> This may be the first time that I have tried to upgrade R since I
>> upgraded my Windows installation (on Parallels on my Mac no less) to
>> Windows 10.
>> 
>> Needless to say when I try to install packages outside of core CRAN I
>> have issues.
>> 
>> Any help is greatly appreciated.
>> 
>> Thanks much,
>> KW
>> 
>> __
>> 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 to plott bar graphics

2015-10-26 Thread John Kane
Hhi Ujjwal

As Jim says a lot of people don't like the barplot with error bars approach see 
http://biostat.mc.vanderbilt.edu/wiki/Main/DynamitePlots and links for some of 
the reasons  why.

Besides, in Tufte's terms most of a barplot is 'chart junk'.

John Kane
Kingston ON Canada


> -Original Message-
> From: drjimle...@gmail.com
> Sent: Mon, 26 Oct 2015 11:32:35 +1100
> To:
> Subject: Re: [R] How to plott bar graphics
> 
> Hi Ujjwal,
> Given that you have asked about a barplot and included standard errors,
> you
> probably want something like the following:
> 
> uk.df<-read.table(text=
>  
> "habitat,proportion_use,proportion_use_SE,selectivity_index,selectivity_index_SE
>  grassland,0.56,0.22,0.72,0.29
>  sal_forest,0.11,0.04,-0.43,0.13
>  bamboo-mix,0.22,0.07,0.05,0.02
>  miscellaneous,0.11,0.03,-0.59,0.18",sep=",",header=TRUE)
> library(plotrix)
> barpos<-barp(uk.df[c("proportion_use","selectivity_index")],
>  names.arg=c("proportion_use","selectivity_index"),
>  main="Habitat Use Plot",ylab="Proportion of use",
>  col=2:5,ylim=c(-1,1.1))
> dispersion(barpos$x,barpos$y,
>  ulim=as.matrix(uk.df[c("proportion_use_SE","selectivity_index_SE")]))
> legend(0.7,-0.3,uk.df$habitat,fill=2:4)
> 
> You will almost certainly be told that you shouldn't do this, so maybe
> you
> should consider:
> 
> matplot(matrix(c(0.9,1.1,1.9,2.1,2.9,3.1,3.9,4.1),nrow=4,byrow=TRUE),
>  uk.df[c("proportion_use","selectivity_index")],
>  ylab="Proportion and selectivity of use",
>  ylim=c(-1,1.1),pch=18:19,col=2:3,xaxt="n",xlab="Habitat",
>  main="Habitat Use Plot")
> axis(1,at=1:4,labels=uk.df$habitat)
> dispersion(matrix(c(0.9,1.1,1.9,2.1,2.9,3.1,3.9,4.1),nrow=4,byrow=TRUE),
>  as.matrix(uk.df[c("proportion_use","selectivity_index")]),
>  ulim=as.matrix(uk.df[c("proportion_use_SE","selectivity_index_SE")]))
> legend(2.5,1,c("Proportion of use","Selectivity of use"),
>  pch=18:19,col=2:3)
> 
> Jim
> 
> 
> On Sun, Oct 25, 2015 at 11:22 PM, Michael Dewey 
> wrote:
> 
>> Dear Ujjwal
>> 
>> Two problems
>> 1 - you posted in HTML so your post is unreadable
>> 2 - your attached graphic was not in one of the formats which R-help
>> accepts and so was stripped
>> 
>> 
>> On 25/10/2015 11:04, Ujjwal Kumar wrote:
>> 
>>> HI friends
>>> I am struggling in plotting bar graph with this data sets in R.
>>> although I
>>> can plot it in Microsoft excel( attached graphics). I need help in
>>> coding
>>> it for R.(SE=standar error)
>>> 
 data
> 
 habitat
 proportion_use
 proportion_use_SE
 selectivity_index
 selectivity_index_SE
 grassland
 0.56
 0.22
 0.72
 0.29
 sal_forest
 0.11
 0.04
 -0.43
 0.13
 bamboo-mix
 0.22
 0.07
 0.05
 0.02
 miscellaneous
 0.11
 0.03
 -0.59
 0.18
 
> excel-graphics
> 
 
 
 regards:
 Ujjwal
 
>>> 
>>> [[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.
>>> 
>>> 
>> --
>> 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.
>> 
> 
>   [[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.


Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.

__
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] regex not working for some entries in for loop

2015-10-26 Thread S Ellison


> From: Omar André Gonzáles Díaz
> Subject: [R] regex not working for some entries in for loop
> 
> I'm using some regex in a for loop to check for some values in column 
> "source",
> and put a result in column "fuente".

Your regexes are on multiple lines and include whitespace and linefeeds. For 
example you are not testing for 
" .*forum.*|.*buy.*"; you are testing for 
" .*forum.*|
  .*buy.*"
(which among other things includes a \n)
Don’t do that. Keep it to one line with no white space.
if you must have line breaks in the code, form the pattern using paste, as in
pat1 <- paste(c("site.*", ".*event.*", ".*free.*", ".*theguardlan.*", 
".*guardlink.*", ".*torture.*", ".*forum.*", ".*buy.*", 
".*share.*", ".*buttons.*", ".*pyme\\.lavoztx\\.com\\.*", 
".*amezon.*", "computrabajo.com.pe", ".*porn.*", "quality"),
collapse="|")

spam <- grepl(pat1, sf$source,ignore.case = T)

Also, it's not immediately clear why you’re looping. grepl returns a vector of 
logicals; you have a vector of character strings. Consider replacing 'if' 
constructs with 'ifelse' - albeit a complicated ifelse() - and doing the whole 
thing without a loop.

S Ellison


***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, 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] Creating new variables in R

2015-10-26 Thread Erich Neuwirth
data <- within(data,variable3=pmax(variable1,variable2))
also should work if your variables are numeric.

using dplyr and magrittr (which I recommend to all my students)
it could be

library(dplyr)
library(magrittr)
data %<>% mutate(variable3=pmax(variable1,variable2))



> On 26 Oct 2015, at 12:53, PIKAL Petr  wrote:
> 
> Hi
> 
>> -Original Message-
>> From: R-help [mailto:r-help-boun...@r-project.org 
>> ] On Behalf Of Duncan
>> Murdoch
>> Sent: Monday, October 26, 2015 11:58 AM
>> To: Lorenz, Jennifer; r-help@r-project.org 
>> Subject: Re: [R] Creating new variables in R
>> 
>> On 26/10/2015 6:24 AM, Lorenz, Jennifer wrote:
>>> Hi,
>>> 
>>> I  have a question regarding the creation of new variables on the
>> basis of existing ones in R.
>>> 
>>> I have two variables containing information on parents' educational
>> degree (e.g. 1 'high school degree', 2 'college degree', etc.). I would
>> like to create a new variable for 'parents' highest educational
>> degree', i.e. if variable1 (father's degree) is higher than variable2
>> (mother's degree) than the new variable (variable3) should take on the
>> value of variable1, if not, than variable3 should take on the value of
>> variable2.
>>> 
>>> I usually use SPSS for data manipulation, there I would code
>> variable3 as follows:
>>> COMPUTE variable3= 0.
>>> IF variable1 > variable2 variable3= variable1.
>>> IF variable1 <= variable2 variable3= variable2.
>>> 
>>> The closest I came to that in R was with this code:
>>> data$variable3 <- 0
>>> data$variable3[data$variable1 > data$variable2]<-data$variable1
>>> data$variable3[data$variable1 <= data$variable2]<-data$variable2
>>> 
>>> I also tried:
>>> data$variable3 <- ifelse(data$variable1 > data$variable2),
>>> data$variable1, data$variable2)
>>> 
>>> Both didn't work.
> 
> The ifelse version should work. Are you sure that variable 1 and 2 are 
> numeric?.
> 
> What is a result of str(data)?
> 
> Cheers
> Petr
> 
>>> 
>>> I am not sure if my post is at all understandable (this is my first
>> time posting on R-help), but I am really hoping for some advice!
>> 
>> This is a good place to use the ifelse() function:
>> 
>> data$variable3 <- ifelse(data$variable1 > data$variable2,
>> data$variable1, data$variable2)
>> 
>> 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.
> 
> 
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou 
> určeny pouze jeho adresátům.
> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
> jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
> svého systému.
> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
> jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
> zpožděním přenosu e-mailu.
> 
> V případě, že je tento e-mail součástí obchodního jednání:
> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, 
> a to z jakéhokoliv důvodu i bez uvedení důvodu.
> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
> Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany 
> příjemce s dodatkem či odchylkou.
> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
> dosažením shody na všech jejích náležitostech.
> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
> žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
> pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu 
> případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je 
> adresátovi či osobě jím zastoupené známá.
> 
> This e-mail and any documents attached to it may be confidential and are 
> intended only for its intended recipients.
> If you received this e-mail by mistake, please immediately inform its sender. 
> Delete the contents of this e-mail with all attachments and its copies from 
> your system.
> If you are not the intended recipient of this e-mail, you are not authorized 
> to use, disseminate, copy or disclose this e-mail in any manner.
> The sender of this e-mail shall not be liable for any possible damage caused 
> by modifications of the e-mail or by delay with transfer of the email.
> 
> In case that this e-mail forms part of business dealings:
> - the sender reserves the right to end negotiations about entering into a 
> contract in any time, for any reason, and without stating any reasoning.
> - if the e-mail contains an offer, the recipient is enti

Re: [R] Creating new variables in R

2015-10-26 Thread PIKAL Petr
Hi

> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
> Murdoch
> Sent: Monday, October 26, 2015 11:58 AM
> To: Lorenz, Jennifer; r-help@r-project.org
> Subject: Re: [R] Creating new variables in R
>
> On 26/10/2015 6:24 AM, Lorenz, Jennifer wrote:
> > Hi,
> >
> > I  have a question regarding the creation of new variables on the
> basis of existing ones in R.
> >
> > I have two variables containing information on parents' educational
> degree (e.g. 1 'high school degree', 2 'college degree', etc.). I would
> like to create a new variable for 'parents' highest educational
> degree', i.e. if variable1 (father's degree) is higher than variable2
> (mother's degree) than the new variable (variable3) should take on the
> value of variable1, if not, than variable3 should take on the value of
> variable2.
> >
> > I usually use SPSS for data manipulation, there I would code
> variable3 as follows:
> > COMPUTE variable3= 0.
> > IF variable1 > variable2 variable3= variable1.
> > IF variable1 <= variable2 variable3= variable2.
> >
> > The closest I came to that in R was with this code:
> > data$variable3 <- 0
> > data$variable3[data$variable1 > data$variable2]<-data$variable1
> > data$variable3[data$variable1 <= data$variable2]<-data$variable2
> >
> > I also tried:
> > data$variable3 <- ifelse(data$variable1 > data$variable2),
> > data$variable1, data$variable2)
> >
> > Both didn't work.

The ifelse version should work. Are you sure that variable 1 and 2 are numeric?.

What is a result of str(data)?

Cheers
Petr

> >
> > I am not sure if my post is at all understandable (this is my first
> time posting on R-help), but I am really hoping for some advice!
>
> This is a good place to use the ifelse() function:
>
> data$variable3 <- ifelse(data$variable1 > data$variable2,
>  data$variable1, data$variable2)
>
> 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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 

Re: [R] [FORGED] Re: How to correct documentation?

2015-10-26 Thread Duncan Murdoch
On 25/10/2015 7:44 PM, Boris Steipe wrote:
> Ming is right. I can't imagine other discipline's standards are substantially 
> different from ours, but e.g. the ACS style manual is very explicit to 
> require ...
> 
>"Label each axis with the parameter or variable being measured and the 
> units of measure in parentheses."
> 
> The _units_ are not lb/1000. 1/1000 is a _transformation_ of the value, the 
> unit is lb, or in that case (1000 lb). Writing lb/1000 is just as nonsensical 
> as writing g/k instead of (kg). 1000 is simply a numerical prefix to the 
> unit, like kilo.
> 
> It gets worse: According to the UK metric association:
>"The symbol for "per" (meaning "divided by") is “/” (slash)."

How is that relevant?  We aren't trying to represent "per" here, we are
trying to represent "divided by".

The only valid argument I've heard so far is that we should use what the
cited paper used.  That was "1000 lbs", so I'll change it.

Duncan Murdoch

> 
> Accordingly, "lb/1000" is to be read "pounds per 1000" which is actually 
> wrong by six orders of magnitude. 
> 
> I don't think there is ambiguity here nor occasion for sophistry: as written, 
> the label is wrong. It would be more than appropriate for a community that is 
> passionate about data to correct this.
> 
> 
> :-)
> Boris
> 
> (Good Lord! https://xkcd.com/386/)
> 
> On Oct 24, 2015, at 6:07 PM, Rolf Turner  wrote:
> 
>> On 24/10/15 21:10, Jim Lemon wrote:
>>> Hi Ming,
>>> In fact, the notation lb/1000 is correct, as the values represent the
>>> weight of the cars in pounds (lb) divided by 1000. I am not sure why this
>>> particular transformation of the measured values was used, but I'm sure it
>>> has caused confusion previously.
>>
>> I disagree --- and agree with Ming.  The notation is incorrect.  Surely
>> "lb/1000" means thousandths of pounds.  E.g. 12345 lb/1000 is equal to
>> 12.345 lb.
>>
>> I'm sure that others will come up with all sorts of convoluted lawyerish 
>> arguments that the case is otherwise, but as far as I am concerned, any 
>> *sane* person would interpret "lb/1000" to mean thousandths of pounds.
>>
>> If in the unlikely event that the documentation for some data set said 
>> "Weight (gm/1000)", I'm pretty sure that this would be interpreted to mean 
>> milligrams and *not* kilograms!
>>
>> Since the description of the data was presumably taken from that given in 
>> the original source ("Motor Trend" magazine) it would probably be 
>> inappropriate to "correct" it.  However a note/warning should be added to 
>> the mtcars help file indicating that Motor Trend got things upside-down.
>>
>> cheers,
>>
>> Rolf
>>
>> -- 
>> Technical Editor ANZJS
>> Department of Statistics
>> University of Auckland
>> Phone: +64-9-373-7599 ext. 88276
>>
>>> On Sat, Oct 24, 2015 at 11:59 AM, Ming-Lun Ho  wrote:
>>>
 Hi,
 I used "?mtcars" to read the documentation for the dataset. I found a
 mistake in how unit is listed, namely, that for the variable "wt," the unit
 should be listed as "1000 lb," not "lb/1000." However, I don't know whom to
 contact exactly for the correction. Please point me to the right place.
 Thanks.
   --Ming
>>
>> __
>> 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.


Re: [R] Function help

2015-10-26 Thread Duncan Murdoch
On 25/10/2015 10:20 PM, alexander.thoma...@louisville.edu wrote:
> Hello,
> 
> I'm following an example in the book, analyzing baseball data with R, but 
> it's not working for me. The example is:

We don't know what "the book" is.  If this is the textbook for your
class, you should ask your instructor for help.
> 
> compute.hr <- function(pid){d <- subset(Batting.60, playerID==pid)
> sum(d$HR)}

That works for me.

Duncan Murdoch

> 
> Every time I try this, it says there's an unexpected symbol. Any idea on what 
> the unexpected symbol is or how to fix it? Thanks.
> 
> __
> 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] Creating new variables in R

2015-10-26 Thread Duncan Murdoch
On 26/10/2015 6:24 AM, Lorenz, Jennifer wrote:
> Hi,
> 
> I  have a question regarding the creation of new variables on the basis of 
> existing ones in R.
> 
> I have two variables containing information on parents' educational degree 
> (e.g. 1 'high school degree', 2 'college degree', etc.). I would like to 
> create a new variable for 'parents' highest educational degree', i.e. if 
> variable1 (father's degree) is higher than variable2 (mother's degree) than 
> the new variable (variable3) should take on the value of variable1, if not, 
> than variable3 should take on the value of variable2.
> 
> I usually use SPSS for data manipulation, there I would code variable3 as 
> follows:
> COMPUTE variable3= 0.
> IF variable1 > variable2 variable3= variable1.
> IF variable1 <= variable2 variable3= variable2.
> 
> The closest I came to that in R was with this code:
> data$variable3 <- 0
> data$variable3[data$variable1 > data$variable2]<-data$variable1
> data$variable3[data$variable1 <= data$variable2]<-data$variable2
> 
> I also tried:
> data$variable3 <- ifelse(data$variable1 > data$variable2), data$variable1, 
> data$variable2)
> 
> Both didn't work.
> 
> I am not sure if my post is at all understandable (this is my first time 
> posting on R-help), but I am really hoping for some advice!

This is a good place to use the ifelse() function:

data$variable3 <- ifelse(data$variable1 > data$variable2,
 data$variable1, data$variable2)

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] Monte Carlo Simulation Convergence test

2015-10-26 Thread Amelia Marsh
Dear Forum, 

I have series of say 100 (say equity) instrument prices. From these prices, for 
each of these 100 instruments, I generate returns using ln(current price / 
previous price). 

Assuming originally I had 251 prices available for each of these 100 
instruments over last one year period, I have matrix of 250X100 returns.

I assume that these returns follow Multivariate Normal Distribution. Using the 
returns, I generate a mean Vector of returns 'M' and also generate the Variance 
- covariance matrix of returns 'S'.

Then using MASS library, I simulate say 1 returns for each of the 100 
instruments as :

sim_rates = mvrnorm(1, M, S) 

This gives me 1 simulated returns for each of the 100 instruments and using 
these simulated returns carry out further analysis.

My query is how do I carry out convergence test in R to arrive at sufficint 
number of simulations? 


With reagrds

Amelia

__
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] Function help

2015-10-26 Thread alexander . thomas . 1
Hello,

I'm following an example in the book, analyzing baseball data with R, but it's 
not working for me. The example is:

compute.hr <- function(pid){d <- subset(Batting.60, playerID==pid)
sum(d$HR)}

Every time I try this, it says there's an unexpected symbol. Any idea on what 
the unexpected symbol is or how to fix it? Thanks.

__
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] [FORGED] Re: How to correct documentation?

2015-10-26 Thread Jim Lemon
On Mon, Oct 26, 2015 at 10:44 AM, Boris Steipe 
wrote:

> Ming is right.

...

Having started all this trouble, I suppose I should offer a modest
explanation.

The OP was indeed "right" in the sense that the column heading did not
indicate the correct _units_ for the values. I suppose that "kilopounds"
would be the correct units if such a unit was acceptable to the relevant
standards committee. As Boris noted, lb/1000 is (sort of) the
transformation used to get the values. Given the burning interest in this
distinction between units (as used to explicitly back transform the values)
and and explanatory labels (how did these values come to be?) I should
state that the objection I refrained from adding to my original answer was,
'Why didn't they just leave the values in the initial units?"

I was reminded of a long past physics lecturer's favorite units of velocity
- furlongs per fortnight.

Jim

[[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] Creating new variables in R

2015-10-26 Thread Lorenz, Jennifer
Hi,

I  have a question regarding the creation of new variables on the basis of 
existing ones in R.

I have two variables containing information on parents' educational degree 
(e.g. 1 'high school degree', 2 'college degree', etc.). I would like to create 
a new variable for 'parents' highest educational degree', i.e. if variable1 
(father's degree) is higher than variable2 (mother's degree) than the new 
variable (variable3) should take on the value of variable1, if not, than 
variable3 should take on the value of variable2.

I usually use SPSS for data manipulation, there I would code variable3 as 
follows:
COMPUTE variable3= 0.
IF variable1 > variable2 variable3= variable1.
IF variable1 <= variable2 variable3= variable2.

The closest I came to that in R was with this code:
data$variable3 <- 0
data$variable3[data$variable1 > data$variable2]<-data$variable1
data$variable3[data$variable1 <= data$variable2]<-data$variable2

I also tried:
data$variable3 <- ifelse(data$variable1 > data$variable2), data$variable1, 
data$variable2)

Both didn't work.

I am not sure if my post is at all understandable (this is my first time 
posting on R-help), but I am really hoping for some advice!
Thanks!
Jen



---
Jennifer Lorenz, M.A.
Georg-August-Universit�t G�ttingen
Sozialwissenschaftliche Fakult�t
Institut f�r Erziehungswissenschaft
Lehrstuhl Schulp�dagogik / Empirische Schulforschung

e-mail: jlor...@uni-goettingen.de
phone: 0551-39-21411
adress: Waldweg 26, 37073 G�ttingen
room: 8.106

[[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 to plott bar graphics

2015-10-26 Thread Jim Lemon
Hi Ujjwal,
Given that you have asked about a barplot and included standard errors, you
probably want something like the following:

uk.df<-read.table(text=
 
"habitat,proportion_use,proportion_use_SE,selectivity_index,selectivity_index_SE
 grassland,0.56,0.22,0.72,0.29
 sal_forest,0.11,0.04,-0.43,0.13
 bamboo-mix,0.22,0.07,0.05,0.02
 miscellaneous,0.11,0.03,-0.59,0.18",sep=",",header=TRUE)
library(plotrix)
barpos<-barp(uk.df[c("proportion_use","selectivity_index")],
 names.arg=c("proportion_use","selectivity_index"),
 main="Habitat Use Plot",ylab="Proportion of use",
 col=2:5,ylim=c(-1,1.1))
dispersion(barpos$x,barpos$y,
 ulim=as.matrix(uk.df[c("proportion_use_SE","selectivity_index_SE")]))
legend(0.7,-0.3,uk.df$habitat,fill=2:4)

You will almost certainly be told that you shouldn't do this, so maybe you
should consider:

matplot(matrix(c(0.9,1.1,1.9,2.1,2.9,3.1,3.9,4.1),nrow=4,byrow=TRUE),
 uk.df[c("proportion_use","selectivity_index")],
 ylab="Proportion and selectivity of use",
 ylim=c(-1,1.1),pch=18:19,col=2:3,xaxt="n",xlab="Habitat",
 main="Habitat Use Plot")
axis(1,at=1:4,labels=uk.df$habitat)
dispersion(matrix(c(0.9,1.1,1.9,2.1,2.9,3.1,3.9,4.1),nrow=4,byrow=TRUE),
 as.matrix(uk.df[c("proportion_use","selectivity_index")]),
 ulim=as.matrix(uk.df[c("proportion_use_SE","selectivity_index_SE")]))
legend(2.5,1,c("Proportion of use","Selectivity of use"),
 pch=18:19,col=2:3)

Jim


On Sun, Oct 25, 2015 at 11:22 PM, Michael Dewey 
wrote:

> Dear Ujjwal
>
> Two problems
> 1 - you posted in HTML so your post is unreadable
> 2 - your attached graphic was not in one of the formats which R-help
> accepts and so was stripped
>
>
> On 25/10/2015 11:04, Ujjwal Kumar wrote:
>
>> HI friends
>> I am struggling in plotting bar graph with this data sets in R. although I
>> can plot it in Microsoft excel( attached graphics). I need help in coding
>> it for R.(SE=standar error)
>>
>>> data

>>> habitat
>>> proportion_use
>>> proportion_use_SE
>>> selectivity_index
>>> selectivity_index_SE
>>> grassland
>>> 0.56
>>> 0.22
>>> 0.72
>>> 0.29
>>> sal_forest
>>> 0.11
>>> 0.04
>>> -0.43
>>> 0.13
>>> bamboo-mix
>>> 0.22
>>> 0.07
>>> 0.05
>>> 0.02
>>> miscellaneous
>>> 0.11
>>> 0.03
>>> -0.59
>>> 0.18
>>>
 excel-graphics

>>>
>>>
>>> regards:
>>> Ujjwal
>>>
>>
>> [[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.
>>
>>
> --
> 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.
>

[[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 to plott bar graphics

2015-10-26 Thread Jim Lemon
No worries. Just use:

abline(h=0)

Jim

On Mon, Oct 26, 2015 at 6:32 PM, Ujjwal Kumar 
wrote:

> Thank you Jim for your Kind help
> The second code suits my need.
> Just another query If I need to put another line (horizontal, same as x-
> axis that passes through zero (0.0), and actually divide negative value of
> less than 0 and positve value more than zero, How to do this??
>
> Once again Thank you very much for guiding me.
>
> On Mon, Oct 26, 2015 at 6:02 AM, Jim Lemon  wrote:
>
>> Hi Ujjwal,
>> Given that you have asked about a barplot and included standard errors,
>> you probably want something like the following:
>>
>> uk.df<-read.table(text=
>>
>>  
>> "habitat,proportion_use,proportion_use_SE,selectivity_index,selectivity_index_SE
>>  grassland,0.56,0.22,0.72,0.29
>>  sal_forest,0.11,0.04,-0.43,0.13
>>  bamboo-mix,0.22,0.07,0.05,0.02
>>  miscellaneous,0.11,0.03,-0.59,0.18",sep=",",header=TRUE)
>> library(plotrix)
>> barpos<-barp(uk.df[c("proportion_use","selectivity_index")],
>>  names.arg=c("proportion_use","selectivity_index"),
>>  main="Habitat Use Plot",ylab="Proportion of use",
>>  col=2:5,ylim=c(-1,1.1))
>> dispersion(barpos$x,barpos$y,
>>  ulim=as.matrix(uk.df[c("proportion_use_SE","selectivity_index_SE")]))
>> legend(0.7,-0.3,uk.df$habitat,fill=2:4)
>>
>> You will almost certainly be told that you shouldn't do this, so maybe
>> you should consider:
>>
>> matplot(matrix(c(0.9,1.1,1.9,2.1,2.9,3.1,3.9,4.1),nrow=4,byrow=TRUE),
>>  uk.df[c("proportion_use","selectivity_index")],
>>  ylab="Proportion and selectivity of use",
>>  ylim=c(-1,1.1),pch=18:19,col=2:3,xaxt="n",xlab="Habitat",
>>  main="Habitat Use Plot")
>> axis(1,at=1:4,labels=uk.df$habitat)
>> dispersion(matrix(c(0.9,1.1,1.9,2.1,2.9,3.1,3.9,4.1),nrow=4,byrow=TRUE),
>>  as.matrix(uk.df[c("proportion_use","selectivity_index")]),
>>  ulim=as.matrix(uk.df[c("proportion_use_SE","selectivity_index_SE")]))
>> legend(2.5,1,c("Proportion of use","Selectivity of use"),
>>  pch=18:19,col=2:3)
>>
>> Jim
>>
>>
>> On Sun, Oct 25, 2015 at 11:22 PM, Michael Dewey 
>> wrote:
>>
>>> Dear Ujjwal
>>>
>>> Two problems
>>> 1 - you posted in HTML so your post is unreadable
>>> 2 - your attached graphic was not in one of the formats which R-help
>>> accepts and so was stripped
>>>
>>>
>>> On 25/10/2015 11:04, Ujjwal Kumar wrote:
>>>
 HI friends
 I am struggling in plotting bar graph with this data sets in R.
 although I
 can plot it in Microsoft excel( attached graphics). I need help in
 coding
 it for R.(SE=standar error)

> data
>>
> habitat
> proportion_use
> proportion_use_SE
> selectivity_index
> selectivity_index_SE
> grassland
> 0.56
> 0.22
> 0.72
> 0.29
> sal_forest
> 0.11
> 0.04
> -0.43
> 0.13
> bamboo-mix
> 0.22
> 0.07
> 0.05
> 0.02
> miscellaneous
> 0.11
> 0.03
> -0.59
> 0.18
>
>> excel-graphics
>>
>
>
> regards:
> Ujjwal
>

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


>>> --
>>> 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.
>>>
>>
>>
>
>
> --
> with regards
> Ujjwal Kumar
> *Research Fellow*
> Project: "Monitoring Source Population of Tigers in Kanha Tiger Reserve"
> Wildlife Institute of India
> mobile: +91 9808712591(Dehradun)
> +919407344453  (Kanha)
>
>P.O. Box 18 Chandrabani
>   Dehradun (Uttarakhand) 248001
>

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