Marc Schwartz | 1 May 2010 01:04
Gravatar

Re: drop last character in a names'vector


On Apr 30, 2010, at 5:44 PM, Sebastian Kruk wrote:

> Hi, i have a vector filled with names:
> 
> [1] Alvaro Adela ...
> [25] Beatriz Berta ...
> ...
> [100000] ...
> 
> I would like to drop last character in every name.
> 
> I use the next program:
> 
> for (i in 1:100000) {
>                           largo <- nchar(names[i]-1)
>                           names[i] <- substring (names[i],1,largo]
>                          }
> 
> Is another and faster way of do it?
> 
> Thanks,
> 
> Sebastián.

As is the case with R, more than one, but the fastest may be:

names <- c("Alvaro Adela", "Beatriz Berta")

> gsub("^(.*).{1}$", "\\1", names)
(Continue reading)

Bert Gunter | 1 May 2010 01:04

Re: What is the best way to have "R" output tables in an MS Word format?

odfWeave might be a less daunting option here, as it can output results in
some .doc formats. I have no idea how well tables would survive the
translations, however.

-- Bert 

Bert Gunter
Genentech Nonclinical Statistics

-----Original Message-----
From: r-help-bounces <at> r-project.org [mailto:r-help-bounces <at> r-project.org] On
Behalf Of Marc Schwartz
Sent: Friday, April 30, 2010 3:46 PM
To: Max Gunther
Cc: r-help <at> r-project.org
Subject: Re: [R] What is the best way to have "R" output tables in an MS
Word format?

On Apr 30, 2010, at 5:13 PM, Max Gunther wrote:

> Dear "R" list,
> 
> Our statisticians usually give us results back in a PDF format. I would
like
> to be able to copy and past tables from "R" output directly into a
Microsoft
> Word table since this will save us tons of time, be more accurate to
> minimize human copying errors and help us update data in our papers more
> easily.
> 
(Continue reading)

Greg Snow | 1 May 2010 01:04

Re: as.environment Error

I don't know what is specifically causing the error, but I think that you will be happier in the long run (and
probably short run) if you abandon the use of assign and <<- and instead use lists.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow <at> imail.org
801.408.8111

> -----Original Message-----
> From: r-help-bounces <at> r-project.org [mailto:r-help-bounces <at> r-
> project.org] On Behalf Of mailing-list <at> gmx.net
> Sent: Friday, April 30, 2010 11:21 AM
> To: r-help <at> r-project.org
> Subject: [R] as.environment Error
> 
> 
> Dear R community,
> 
> I have a problem with assign:
> 
> <snip>
> 	      for ( iii in 1:dim(ref_df)[2] )
> 	      {
> 		    ret <<-
> ref_df[,iii][names(single_string[ii])]*(single_count/sum(ref_df[,iii]))
> 
> assign(paste("expected_sing_ref",iii,sep=""),c(get(paste("expected_sing
> le_ref",iii,sep=""))), ret)
(Continue reading)

Peter Ehlers | 1 May 2010 01:14
Picon
Favicon

Re: Flattening and unflattening symmetric matrices

On 2010-04-30 15:26, Nicholas Andrews wrote:
> Here's an easy question: I'd like to convert a symmetric matrix to a
> vector composed of the upper.tri() part of it plus the diagonal, and
> convert it back again.  What's the best way to achieve this?  I'm
> wondering if there are some built in functions to do this easily.  I
> can encode fine:
>
> v<- c(diag(A),A[upper.tri(A)])
>
> but I don't see an easy way to recover A from v without loops.  Any tips?

To (re)create a symmetric matrix, use A + t(A):
If vd is diag(A) part of v and vu is the rest of v, and
let's take A to be 4-by-4, then

  A <- matrix(0, 4, 4)
  A[upper.tri(A)] <- vu
  A <- A + t(A)
  diag(A) <- vd
  A

  -Peter Ehlers

>
> ______________________________________________
> R-help <at> r-project.org mailing list
> 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.
>
(Continue reading)

Greg Snow | 1 May 2010 01:24

Re: Periodic regression - lunar percent cover

You have the correct general idea, but it looks like lp may have already been transformed to be in the range
0-1 rather than number of days, if that is the case then you don't need to dived by 29. Again.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow <at> imail.org
801.408.8111

> -----Original Message-----
> From: r-help-bounces <at> r-project.org [mailto:r-help-bounces <at> r-
> project.org] On Behalf Of Tim Clark
> Sent: Thursday, April 29, 2010 5:50 PM
> To: r-help <at> r-project.org
> Subject: [R] Periodic regression - lunar percent cover
> 
> Dear List,
> 
> I am trying include a lunar variable in a model and am having problems
> figuring out the correct way to include it.  I want to convert the
> percent lunar illumination (fraction of moon showing) to a combination
> of sin and cos variables to account for the periodic nature of the
> lunar cycle.  Would someone let me know if I am doing this correctly?
> I have included the first 20 variables from my dataset as an example.
> Y is count data and lp is the lunar percent cover.  The lunar period is
> 29.53.
> 
> y<-c(1, 3, 0, 0, 0, 0, 2, 4, 0, 1, 0, 5, 3, 2, 4, 2, 0, 1, 3, 5)
> lp<-c(0.80, 0.88, 0.62, 0.19, 0.21, 0.01, 0.70, 1.00, 0.88, 0.04, 0.70,
(Continue reading)

Kyeong Soo (Joseph) Kim | 1 May 2010 01:24
Picon

Re: Curve Fitting/Regression with Multiple Observations

I have already learned a lot from the list, both technical and not,
and cannot thank enough for those valuable suggestions. In fact, as
said in my previous posts, I got really critical help and advices,
which really addresses the issues I have.

By the way, there is one point or two in your post I agree on, but I
am not sure why you just pointed out side issues (by snipping a part
of my saying) without touching the main topic of this thread at all. I
can go on but won't because arguing for the sake of argument is of no
value to anyone in this thread.

It would have been better if you could have focused on the topic and
provided some technical and practical information which I could learn
from and be very thankful for.

Regards,
Joseph

On Fri, Apr 30, 2010 at 11:35 PM, Greg Snow <Greg.Snow <at> imail.org> wrote:
>
>> -----Original Message-----
>> From: r-help-bounces <at> r-project.org [mailto:r-help-bounces <at> r-
>> project.org] On Behalf Of Kyeong Soo (Joseph) Kim
>> Sent: Friday, April 30, 2010 4:10 AM
>> To: kMan
>> Cc: r-help <at> r-project.org
>> Subject: Re: [R] Curve Fitting/Regression with Multiple Observations
>
> [snip]
>
(Continue reading)

Greg Snow | 1 May 2010 01:19

Re: understanding behavior of "merge"

So does each person have multiple rows and you want to sample the set of rows?

The usual approach that I take is to split them into a list, sample from the list, the put the list back
together, for example:

tmp1 <- split(as.data.frame(state.x77), state.division)
tmp2 <- sample(tmp1, replace=TRUE)
tmp3 <- do.call( 'rbind', tmp2 )
tmp3$newid <- rep( 1:length(tmp2), sapply(tmp2, nrow) )

wrap that in a function and you have the bootstrap resampling.

Hope this helps,

--

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow <at> imail.org
801.408.8111

> -----Original Message-----
> From: r-help-bounces <at> r-project.org [mailto:r-help-bounces <at> r-
> project.org] On Behalf Of Chris__ Barker
> Sent: Thursday, April 29, 2010 5:26 PM
> To: r-help <at> r-project.org
> Subject: [R] understanding behavior of "merge"
> 
> I'm trying to bootstrap resample from a repeated measures dataset. I
> sample
(Continue reading)

Peter Ehlers | 1 May 2010 01:24
Picon
Favicon

Re: Trouble using Ecdf () from the Hmisc library

On 2010-04-30 15:48, Prasenjit Kapat wrote:
> Hello:
>
> [Kindly Cc when replying]
>
> The question in a nutshell is this: Is there a more robust alternative
> to Ecdf ()?
>
> The details:
>
> I've used Ecdf () _a lot_ over the past few years and I have learned
> to live with its warnings. But I am running short on time and patience
> now [*] Here is a reproducible example:
>
>> library (Hmisc)
>> x<- read.csv ( file = 'http://www.stat.osu.edu/~pkapat/miscl/Data4Ecdf.csv')
>> table (x[, c('X1','X2')])
>      X2
> X1    A  B
>    6   0  1
>    13  7 20
>    15 13 26
>    16 13 13
>    17 10 19
>    18 12 10
>
> As you can see (X1=6,X2=A) is a degenerate cell and (X1=6,X2=B) is
> "near" degenerate! So, errors/warnings are certainly expected while
> dealing with these, as seen here:
>
(Continue reading)

William Dunlap | 1 May 2010 01:19
Favicon

Re: as.environment Error

> -----Original Message-----
> From: r-help-bounces <at> r-project.org 
> [mailto:r-help-bounces <at> r-project.org] On Behalf Of Greg Snow
> Sent: Friday, April 30, 2010 4:04 PM
> To: mailing-list <at> gmx.net; r-help <at> r-project.org
> Subject: Re: [R] as.environment Error
> 
> I don't know what is specifically causing the error, but I 
> think that you will be happier in the long run (and probably 
> short run) if you abandon the use of assign and <<- and 
> instead use lists.
> 
> -- 
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow <at> imail.org
> 801.408.8111
> 
> 
> > -----Original Message-----
> > From: r-help-bounces <at> r-project.org [mailto:r-help-bounces <at> r-
> > project.org] On Behalf Of mailing-list <at> gmx.net
> > Sent: Friday, April 30, 2010 11:21 AM
> > To: r-help <at> r-project.org
> > Subject: [R] as.environment Error
> > 
> > 
> > Dear R community,
> > 
(Continue reading)

Greg Snow | 1 May 2010 01:28

Re: drop last character in a names'vector

No, substr is vectorized, you just have a typo, you are using a different vector for nchar than you are subsetting.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow <at> imail.org
801.408.8111

> -----Original Message-----
> From: r-help-bounces <at> r-project.org [mailto:r-help-bounces <at> r-
> project.org] On Behalf Of Marc Schwartz
> Sent: Friday, April 30, 2010 5:04 PM
> To: Sebastian Kruk
> Cc: r-help <at> r-project.org; r-help <at> stat.math.ethz.ch
> Subject: Re: [R] drop last character in a names'vector
> 
> 
> On Apr 30, 2010, at 5:44 PM, Sebastian Kruk wrote:
> 
> > Hi, i have a vector filled with names:
> >
> > [1] Alvaro Adela ...
> > [25] Beatriz Berta ...
> > ...
> > [100000] ...
> >
> > I would like to drop last character in every name.
> >
> > I use the next program:
(Continue reading)


Gmane