Re: [R] Identifying breakpoints/inflection points?

2010-04-26 Thread Charlotte Chang
Hi Clint,

Thank you for your help with the code. The span recommendation really
improved the fit of my LOESS curve. I appreciate your thoughtful
assistance!

My remaining question is how could I go about identifying the
inflection points for the LOESS curve? I was thinking about trying to
find the 2nd derivative and then using the uniroot function.

My code is here (but it's buggy and doesn't work):

birds.lo<-loess.smooth(x,y,span=0.45)
d2 <- function(x) {
predict(birds.lo, x, deriv=2)$y
}
x<-year
y<-piproute

> d2(x)
Error in predict(birds.lo, x, deriv = 2)$y :
  $ operator is invalid for atomic vectors

#Desired next step:
uniroot(d2,c(7,10))

Any ideas about this would be profoundly appreciated! I'm hitting a dead end.

Yours,

Charlotte

On Mon, Apr 26, 2010 at 3:32 PM, Clint Bowman  wrote:
> Charlotte,
>
> Try:
>
> birds.lo <- loess(piproute~year,span=.25)
> # play with span to see your desired pattern
> birds.pr<-predict(birds.lo, data.frame(year = seq(1967, 2009, 1)), se =
> FALSE)
> #
> plot($year,birds.pr$fit,ylim=c(0,5))
> par(new=T)
> plot(year,birds.pr$fit,pch="+",col=2,ylim=c(0,5))
>
>
> --
> Clint Bowman                    INTERNET:       cl...@ecy.wa.gov
> Air Quality Modeler             INTERNET:       cl...@math.utah.edu
> Department of Ecology           VOICE:          (360) 407-6815
> PO Box 47600                    FAX:            (360) 407-7534
> Olympia, WA 98504-7600
>
> On Mon, 26 Apr 2010, Charlotte Chang wrote:
>
>> Hello!
>> I have a dataset with the following two vectors:
>>
>>
>> year<-c(1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009)
>>
>>
>> piproute<-c(0.7,0.945945946,1.886363636,1.607843137,4.245614035,3.175675676,2.169014085,2,2.136363636,2.65625,2.080645161,2.114754098,2.090909091,3.012195122,2.935897436,2.592105263,1.075757576,1.210526316,1,1.1875,1.903614458,1.385542169,1.788990826,1.163793103,1.558558559,1.595238095,1.75833,1.858267717,2.169117647,1.403225806,2.859375,3.236220472,2.054263566,3.85417,1.812080537,2.708029197,2.75862069,2.625954198,4.540740741,3.686567164,2.8,2.968253968,3.517730496)
>>
>> Pipits is the response variable (it is the number of birds counted at
>> each survey site in each year) and year is the independent variable.
>> If you plot it in R (plot(year,piproute,pch=19)), you'll see that the
>> relationship looks like a quintic polynomial.
>>
>> Initially I was trying to fit this curve using an iterative equation,
>> but it's not working. I suspect that the curve-fitting equation itself
>> is inappropriate (it's a modified version of the logistic growth
>> equation). Now what I'd like to do is identify the 3 break/inflection
>> points in the population trend. That way, I can make an argument that
>> the break points corresponded to shifts in government policy with
>> respect to land use management. I've been looking at the segmented
>> package, and initially I looked at change.pt test in the circ.stats
>> package (which is inappropriate b/c my data is not amenable to
>> circular statistical analysis). Any ideas on what I could do would be
>> appreciated!
>>
>> Thank you!
>>
>> -Charlotte
>>
>> __
>> R-help@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.
>>
>

__
R-help@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.


Re: [R] selecting rows based on number that occurs after letter

2010-04-26 Thread Dennis Murphy
Hi:

This seems to be easier to pull off if x is a data frame rather than a
matrix.
x <- data.frame(GCM = c("BA1y1","BA2y3","C3A1r1y1","C3A2r2y2t4","C3r2y1y1"),
   y = c(1:3, 11, 12), stringsAsFactors = FALSE)
x$val <- as.numeric(substring(lapply(strsplit(x$GCM, 'y'), '[', 2), 1, 1))

This assumes you want the numeric value after the first occurrence of y. It
works
as follows:
   * use strsplit() to split the GCM string using y as a separator,
generating
 list object;
   * run lapply() over the list and extract the second element, which is
the string
  following the first occurrence of y;
   * use substring() to extract the first character and then coerce the
result to be
 numeric.

Output:

> x
 GCM  y val
a  BA1y1  1   1
b  BA2y3  2   3
c   C3A1r1y1  3   1
d C3A2r2y2t4 11   2
e   C3r2y1y1 12   1

HTH,
Dennis

On Mon, Apr 26, 2010 at 10:10 PM, Daisy Englert Duursma <
daisy.duur...@gmail.com> wrote:

> Hello,
>
> Thanks for your help, I have played around with the suggestion a bit
> but I can still not sub-setting in the way I need
>
> If I have a matrix x as follows:
>
>  > x <- matrix(c("BA1y1","BA2y3","C3A1r1y1","C3A2r2y2t4","C3r2y1y1",1,2,3,
> 11,12)
> , nrow=5, ncol=2,
> dimnames=list(c("a","b","c","d","e"), c("GCM","y")))
>  > x
>  GCM  y
> a "BA1y1"  "1"
> b "BA2y3"  "2"
> c "C3A1r1y1"   "3"
> d "C3A2r2y2t4" "11"
> e "C3r2t1y1"   "12"
>
> and I want to loop through 3 subsets based on the numeric value after
> the y, how do I do this?
>
> What I currently have is:
> > year <-c("1", "2", "3")
> > for (y in year) {
> > subx <- x[sapply(strsplit(as.character(x$GCM), ""), function(zzz)zzz[5]
> == y),]
> }
> Basically this loops through and subsets the rows when the 5th
> character has the defined y value (1, 2,or 3). The problem is that y
> can occur anywhere in the GCM value.
>
> Thanks for the help.
> Daisy
> --
> Daisy Englert Duursma
>
> Room E8C156
> Dept. Biological Sciences
> Macquarie University  NSW  2109
> Australia
>
> Tel +61 2 9850 9256
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Problem with 'lars' package

2010-04-26 Thread Tal Galili
The CRAN website is down, and will remain so for the next few hours, see
link for alternative images:
http://www.r-bloggers.com/r-project-websites-down/



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Tue, Apr 27, 2010 at 1:58 AM,  wrote:

> Hi,
> I'm having trouble running 'lars'. When I install it I get the following
> warning:
>
> >install.packages('lars')
> Warning in install.packages("lars") :
>  argument 'lib' is missing: using
> 'C:\Users\Anna\Documents/R/win-library/2.10'
> --- Please select a CRAN mirror for use in this session ---
> trying URL
> 'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/lars_0.9-7.zip'
> Content type 'application/zip' length 211898 bytes (206 Kb)
> opened URL
> downloaded 206 Kb
>
> package 'lars' successfully unpacked and MD5 sums checked
>
> The downloaded packages are in
>C:\Users\Anna\AppData\Local\Temp\RtmpmRYoLn\downloaded_packages
> Warning message:
> In open.connection(con, "r") :
>  unable to connect to 'cran.r-project.org' on port 80.
>
>
> When I actually try to run it, it gives me the following message:
>
> Error: argument "Gram" is missing, with no default
>
> What is the problem?
> Thank you,
> Anna
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Bhapkar V test

2010-04-26 Thread Tal Galili
Hi Karl,
I don't think this is the solution, but just in case -
the coin package has a reference for the: "homogeneity statistic W of *
Bhapkar* (1966)"
Might it be related to V test ?

Best,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Tue, Apr 27, 2010 at 5:21 AM, Karl-Dieter Crisman wrote:

> Bhapkar V test

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Histogram not plotting correct breaks

2010-04-26 Thread Tal Galili
trying setting
br = 40
inside the hist, and check if that helps...
(breaks won't do it for you either way)

Tal

Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Tue, Apr 27, 2010 at 5:04 AM, burgundy  wrote:

>
> Hi,
>
> I'm using the hist function to plot the frequency of 21 variables, but it
> keeps starting the x-axis from 0 and adding variables 1 and 2 together (all
> other vairables have the correct frequencies). I suspect it adds 1 and 2
> together so that 0 can fit in with demarcations at intervals of 5. Using
> "xlim=c(1,21)" to specify that i don't want to include 0 and using the
> "breaks" command to specify 21 breaks doesn't help. Any advice?
> Thank you!!
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Histogram-not-plotting-correct-breaks-tp2066057p2066057.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Mathematical symbol

2010-04-26 Thread Peter Ehlers

Type

 ?"||"

and read the help page.

If it helps, the statement is equivalent to

 if( (a < 10) || (j > 100) )

 -Peter Ehlers

On 2010-04-26 23:00, assaedi76 assaedi76 wrote:

R users

Thanks in advance

Could someone tell me what this condition means:

if ( a<   10  | |j>  100)

Thanks




[[alternative HTML version deleted]]




__
R-help@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.


--
Peter Ehlers
University of Calgary

__
R-help@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.


Re: [R] selecting rows based on number that occurs after letter

2010-04-26 Thread Daisy Englert Duursma
Hello,

Thanks for your help, I have played around with the suggestion a bit
but I can still not sub-setting in the way I need

If I have a matrix x as follows:

  > x <- matrix(c("BA1y1","BA2y3","C3A1r1y1","C3A2r2y2t4","C3r2y1y1",1,2,3,
11,12)
, nrow=5, ncol=2,
dimnames=list(c("a","b","c","d","e"), c("GCM","y")))
  > x
  GCM  y
a "BA1y1"  "1"
b "BA2y3"  "2"
c "C3A1r1y1"   "3"
d "C3A2r2y2t4" "11"
e "C3r2t1y1"   "12"

and I want to loop through 3 subsets based on the numeric value after
the y, how do I do this?

What I currently have is:
> year <-c("1", "2", "3")
> for (y in year) {
> subx <- x[sapply(strsplit(as.character(x$GCM), ""), function(zzz)zzz[5] == 
> y),]
}
Basically this loops through and subsets the rows when the 5th
character has the defined y value (1, 2,or 3). The problem is that y
can occur anywhere in the GCM value.

Thanks for the help.
Daisy
--
Daisy Englert Duursma

Room E8C156
Dept. Biological Sciences
Macquarie University  NSW  2109
Australia

Tel +61 2 9850 9256

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Peter Ehlers

On 2010-04-26 20:05, Matthew Keller wrote:

Rolf: "Well then, why don't you go away and design and build your own
statistics and data analysis language/package to replace R?"

What a nice reply! The fellow is just trying to understand R. That
response reminds me of citizens of my own country who cannot abide by
any criticism of the USA: "If you don't like it, why don't you leave?"
Classy.


Let's not take things too far out of context. Rolf was replying
to someone who was 'very annoyed' that R has the concept of a
vector. That poster felt that, since a vector is just a special
case of a matrix, there was no need for the vector concept. That
poster had also not yet read enough to realize that there *is*
the 'drop=FALSE' argument.

It's a bit strong to complain that R was not designed to suit
your own needs and yours alone, never mind what others might
think.

I have found R-core to be quite receptive to intelligent and
well thought-out suggestions. But "It is very annoying!" is
not the right approach.

 -Peter Ehlers



I have sympathies with the author. When I first began using R
(migrating from Matlab), I also found the vector concept strange,
especially because I was doing a lot of matrix algebra back then and
didn't like the concept of conflating a row vector with a column
vector. But I've since gotten used to it and can hardly remember why I
struggled with this early on. Perhaps your experience will be similar.

Best of luck!

Matt



On Mon, Apr 26, 2010 at 7:40 PM, Charles C. Berry  wrote:

On Mon, 26 Apr 2010, Stu wrote:


Hi all,

One subtlety is that the drop argument only works if you specify 2 or
more indices e.g. [i, j, ..., drop=F]; but not for a single index e.g
[i, drop=F].


Wrong.


a<- structure(1:5,dim=5)
dim(a)


[1] 5


dim(a[2:3,drop=F]) # don't drop regardless


[1] 2


dim(a[2,drop=F]) # dont' drop regardless


[1] 1


dim(a[2:3,drop=T]) # no extent of length 1


[1] 2


dim(a[2,drop=T]) # drop, extent of length 1


NULL




Why doesn't R complain about the unused "drop=F" argument in the
single index case?


In the example you give (one index for a two-dimension array), vector
indexing is assumed. For vector indexing, drop is irrelevant.

HTH,

Chuck


Cheers,
- Stu

a = matrix(1:10, nrow=1)
b = matrix(10:1, ncol=1)

# a1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(a1 = a[2:5, drop=F])
dim(a1)

# a2 is an vector WITH dim attribute: a row matrix (drop=F works)
(a2 = a[, 2:5, drop=F])
dim(a2)

# b1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(b1 = b[2:5, drop=F])
dim(b1)

# b2 is an vector WITH dim attribute: a column matrix (drop=F works)
(b2 = b[2:5, , drop=F])
dim(b2)


On Mar 30, 4:08Â pm, lith  wrote:


Reframe the problem. Rethink why you need to keep dimensions. I never
ever had to use drop.


The problem is that the type of the return value changes if you happen
to forget to use drop = FALSE, which can easily turn into a nightmare:

m<-matrix(1:20, ncol=4)
for (i in seq(3, 1, -1)) {
    print(class(m[1:i, ]))}

[1] "matrix"
[1] "matrix"
[1] "integer"

__
r-h...@r-project.org mailing
listhttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting
guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@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.



Charles C. Berry                            (858) 534-2098
                                           Dept of 
Family/Preventive
Medicine
E mailto:cbe...@tajo.ucsd.edu               UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ Â La Jolla, San Diego 92093-0901


__
R-help@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.








--
Peter Ehlers
University of Calgary

__
R-help@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.


[R] Mathematical symbol

2010-04-26 Thread assaedi76 assaedi76
R users
 
Thanks in advance
 
Could someone tell me what this condition means:
 
if ( a <  10  | |    j > 100) 
 
Thanks



  
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] How to make legend with line+ character

2010-04-26 Thread Mario Valle

Thanks John and thanks to all!
Seems this requires a lot of effort anyway.
So maybe it is better to take a different approach: take the legend out 
of the chart and put it on a plot.new() on the right of the chart, use 
only colored letters but make them larger to be visible.

Thanks!
mario

On 27-Apr-10 0:54, John Kane wrote:

I suspect that you may have to construct the legend by hand (well, by explicit 
text commands anyway)

Something like this seems to work and it should not be that difficult to write 
a function  to handle the text commands.

plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a')
text(1.4,6, label="-a- ", col="red")
text(2.5,6, label="dg1")


--- On Mon, 4/26/10, Mario Valle  wrote:


From: Mario Valle
Subject: [R] How to make legend with line+ character
To: "r-help@r-project.org"
Received: Monday, April 26, 2010, 7:32 AM
Dear all,
I have a multiline plot with each line labeled with a
different letter.
But I'm not able to make the legend display the same kind
of pattern '-a-', instead the letter is overwritten by the
line. A simpler legend with only the letter is not very
visible and the pt.bg does nothing with letters. Any idea?

plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a')
legend("left", legend=c("ds1","ds2"), bty='n', col=1:2,
lty=2,lwd=4,pch=letters)

Thanks for your help!

 mario
-- Ing. Mario Valle
Data Analysis and Visualization Group
   | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)
   | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland |
Fax:  +41 (91) 610.82.82

__
R-help@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.






--
Ing. Mario Valle
Data Analysis and Visualization Group| 
http://www.cscs.ch/~mvalle

Swiss National Supercomputing Centre (CSCS)  | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82

__
R-help@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.


[R] How to work out 3-way probabilities

2010-04-26 Thread Dimitrij Kudriavcev
Hello.

I have a quick question.

I try to use logit regression, to work out probabilities in the sport event.
I have work out probabilities for group of 2 players:

p1 - probability, what player1 will beat player2
p2 - probability, what player2 will beat player1
pt - tie probability, p1 <- 1 - p1 - p2;

Now i want to work out probabilities for group of 3 players, like:

pg1 - probability, what player1 will beat player2 and player3
pg2 - probability, what player2 will beat player1 and player3
pg3 - probability, what player3 will beat player1 and player2

I have probabilities for every pair of players in that group. Is there a
function in R, what can simply convert this 2-way probabilities in to the
3-way (or more)? Or can some body suggest, how to do it manually? I have try
to work it out, buy just multiply corresponding probabilities, but it seems
a bad way.

Cheers,
Dmitrij.

[[alternative HTML version deleted]]

__
R-help@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.


[R] Histogram not plotting correct breaks

2010-04-26 Thread burgundy

Hi,

I'm using the hist function to plot the frequency of 21 variables, but it
keeps starting the x-axis from 0 and adding variables 1 and 2 together (all
other vairables have the correct frequencies). I suspect it adds 1 and 2
together so that 0 can fit in with demarcations at intervals of 5. Using
"xlim=c(1,21)" to specify that i don't want to include 0 and using the
"breaks" command to specify 21 breaks doesn't help. Any advice?
Thank you!!
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Histogram-not-plotting-correct-breaks-tp2066057p2066057.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Charles C. Berry

On Mon, 26 Apr 2010, Stuart Andrews wrote:



Thanks Charles, for clarifying.

My statement holds for matrices, which are 2 dimensional.  And, as you 
mentioned, a single index implies vector indexing where the drop argument 
doesn't make sense.   I am somewhat relieved, given this new understanding.


But I am still puzzled as to why R doesn't complain about the unused "drop=F" 
argument.  Since this argument is nonsensical, R should tell me this, no?


I take your point that user who was intending to type a vector subscript 
would not also bother to type 'drop=FALSE', and from the POV of the user 
typing "a[1:3,drop=F]" at the keyboard, it makes good sense to me to have 
R tip him/her off to a potential goof.


But subscripts get used a lot down deep in the code, so there are other 
considerations, I suspect. If you are interested in this from a 'code 
development' POV, you might repost to R-devel to ask what might have lead 
to this 'feature'. I have two guesses:


1) subscripting is a pretty low-level operation and checking for this 
particular case is not important enough to justify the added code and 
perhaps slowing things down.


2) a construction like

do.call("[", c(list(x), args, list(drop = FALSE)))

will work without comment as long as the 'args' argument delivers a valid 
subscript or set of subscripts (valid for 'x') and the drop = FALSE 
will always be innocuous even if it is superfluous.



For example, when I add an unrecognized argument to the ls() function I get 
the following:



 ls(nonsense="42")

Error in ls(nonsense = "42") : unused argument(s) (nonsense = "42")


Priorities! Failure of argument matching is a critical error. Having a 
valid but superfluous argument is not, and there are loads of settings in 
which no error is raised like



y <- rnorm(3)
x <- 1:3
lm(y~x,data=list("blah"))


which arguably reveals a mistake by the user of the kind that having the 
unneeded 'drop=FALSE' suggested.


HTH,

Chuck



Cheers,
- Stu


On Apr 26, 2010, at 9:40 PM, Charles C. Berry wrote:


On Mon, 26 Apr 2010, Stu wrote:

> Hi all,
> 
> One subtlety is that the drop argument only works if you specify 2 or

> more indices e.g. [i, j, ..., drop=F]; but not for a single index e.g
> [i, drop=F].

Wrong.

> a <- structure(1:5,dim=5)
> dim(a)
[1] 5
> dim(a[2:3,drop=F]) # don't drop regardless
[1] 2
> dim(a[2,drop=F]) # dont' drop regardless
[1] 1
> dim(a[2:3,drop=T]) # no extent of length 1
[1] 2
> dim(a[2,drop=T]) # drop, extent of length 1
NULL


> 
> Why doesn't R complain about the unused "drop=F" argument in the

> single index case?

In the example you give (one index for a two-dimension array), vector 
indexing is assumed. For vector indexing, drop is irrelevant.


HTH,

Chuck
> 
> Cheers,

> - Stu
> 
> a = matrix(1:10, nrow=1)

> b = matrix(10:1, ncol=1)
> 
> # a1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)

> (a1 = a[2:5, drop=F])
> dim(a1)
> 
> # a2 is an vector WITH dim attribute: a row matrix (drop=F works)

> (a2 = a[, 2:5, drop=F])
> dim(a2)
> 
> # b1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)

> (b1 = b[2:5, drop=F])
> dim(b1)
> 
> # b2 is an vector WITH dim attribute: a column matrix (drop=F works)

> (b2 = b[2:5, , drop=F])
> dim(b2)
> 
> 
> On Mar 30, 4:08 pm, lith  wrote:
> > > Reframe the problem. Rethink why you need to keep dimensions. I never 
> > > ever had to use drop.
> > 
> > The problem is that the type of the return value changes if you happen

> > to forget to use drop = FALSE, which can easily turn into a nightmare:
> > 
> > m <-matrix(1:20, ncol=4)

> > for (i in seq(3, 1, -1)) {
> > print(class(m[1:i, ]))}
> > 
> > [1] "matrix"

> > [1] "matrix"
> > [1] "integer"
> > 
> > __
> > r-h...@r-project.org mailing 
> > listhttps://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting 
> > guidehttp://www.R-project.org/posting-guide.html

> > and provide commented, minimal, self-contained, reproducible code.
> 
> __

> R-help@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.
> 


Charles C. Berry(858) 534-2098
   Dept of Family/Preventive 
Medicine

E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901





Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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

Re: [R] when setting environment: target of assignment expands to non-language object

2010-04-26 Thread Gabor Grothendieck
See ?lockBinding

On Mon, Apr 26, 2010 at 11:20 PM, Michael Steven Rooney
 wrote:
> I tried editing the corExp function (added a line) within the nlme
> environment with the following code, but it looks like my declaration did
> not have any effect. I am guessing it is locked some how. Is there an easy
> way to do this or am I treading into complicated waters? (I just picked up R
> a year ago, and I don't have any experience in development. Willing to
> learn.)
>
>> assignInNamespace("corExp",
> + function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> c("euclidean",
> + "maximum", "manhattan"), fixed = FALSE)
> + {
> + cat("corExp\n")   # I ADDED THIS LINE HERE
> + attr(value, "formula") <- form
> + attr(value, "nugget") <- nugget
> + attr(value, "metric") <- match.arg(metric)
> + attr(value, "fixed") <- fixed
> + class(value) <- c("corExp", "corSpatial", "corStruct")
> + value
> + },
> + environment(corExp))
>> corExp
> function (value = numeric(0), form = ~1, nugget = FALSE, metric =
> c("euclidean",
>     "maximum", "manhattan"), fixed = FALSE)
> {
>     attr(value, "formula") <- form
>     attr(value, "nugget") <- nugget
>     attr(value, "metric") <- match.arg(metric)
>     attr(value, "fixed") <- fixed
>     class(value) <- c("corExp", "corSpatial", "corStruct")
>     value
> }
> 
>
>
> On Mon, Apr 26, 2010 at 10:46 PM, Michael Steven Rooney
>  wrote:
>>
>> Thanks.
>>
>> How do I make my function visible to others? Will assignInNamespace do
>> that?
>>
>> On Mon, Apr 26, 2010 at 10:23 PM, Gabor Grothendieck
>>  wrote:
>>>
>>> See ?assignInNamespace
>>>
>>> On Mon, Apr 26, 2010 at 9:49 PM, Michael Steven Rooney
>>>  wrote:
>>> > Hi,
>>> >
>>> > I am trying to place my own functions in the nlme environment:
>>> >
>>> > The following statement works:
>>> >
>>> > environment(coef.corSPT) <-
>>> > environment(getS3method("coef","corSpatial"))
>>> >
>>> > but this one returns an error:
>>> >
>>> > environment(get("coef<-.corSPT")) <-
>>> > environment(getS3method("coef<-","corSpatial"))
>>> > Error in environment(get("coef<-.corSPT")) <-
>>> > environment(getS3method("coef<-",  :
>>> >  target of assignment expands to non-language object
>>> >
>>> > What should I do?
>>> >
>>> > Thanks.
>>> >
>>> > Mike
>>> >
>>> >        [[alternative HTML version deleted]]
>>> >
>>> > __
>>> > R-help@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.
>>> >
>>
>
>

__
R-help@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.


Re: [R] when setting environment: target of assignment expands to non-language object

2010-04-26 Thread Michael Steven Rooney
I tried editing the corExp function (added a line) within the nlme
environment with the following code, but it looks like my declaration did
not have any effect. I am guessing it is locked some how. Is there an easy
way to do this or am I treading into complicated waters? (I just picked up R
a year ago, and I don't have any experience in development. Willing to
learn.)

> assignInNamespace("corExp",
+ function (value = numeric(0), form = ~1, nugget = FALSE, metric =
c("euclidean",
+ "maximum", "manhattan"), fixed = FALSE)
+ {
+ cat("corExp\n")   # I ADDED THIS LINE HERE
+ attr(value, "formula") <- form
+ attr(value, "nugget") <- nugget
+ attr(value, "metric") <- match.arg(metric)
+ attr(value, "fixed") <- fixed
+ class(value) <- c("corExp", "corSpatial", "corStruct")
+ value
+ },
+ environment(corExp))
> corExp
function (value = numeric(0), form = ~1, nugget = FALSE, metric =
c("euclidean",
"maximum", "manhattan"), fixed = FALSE)
{
attr(value, "formula") <- form
attr(value, "nugget") <- nugget
attr(value, "metric") <- match.arg(metric)
attr(value, "fixed") <- fixed
class(value) <- c("corExp", "corSpatial", "corStruct")
value
}




On Mon, Apr 26, 2010 at 10:46 PM, Michael Steven Rooney <
michael.s.roo...@gmail.com> wrote:

> Thanks.
>
> How do I make my function visible to others? Will assignInNamespace do
> that?
>
>   On Mon, Apr 26, 2010 at 10:23 PM, Gabor Grothendieck <
> ggrothendi...@gmail.com> wrote:
>
>> See ?assignInNamespace
>>
>> On Mon, Apr 26, 2010 at 9:49 PM, Michael Steven Rooney
>>  wrote:
>> > Hi,
>> >
>> > I am trying to place my own functions in the nlme environment:
>> >
>> > The following statement works:
>> >
>> > environment(coef.corSPT) <-
>> environment(getS3method("coef","corSpatial"))
>> >
>> > but this one returns an error:
>> >
>> > environment(get("coef<-.corSPT")) <-
>> > environment(getS3method("coef<-","corSpatial"))
>> > Error in environment(get("coef<-.corSPT")) <-
>> > environment(getS3method("coef<-",  :
>> >  target of assignment expands to non-language object
>> >
>> > What should I do?
>> >
>> > Thanks.
>> >
>> > Mike
>> >
>>  >[[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@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.
>> >
>>
>
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] when setting environment: target of assignment expands to non-language object

2010-04-26 Thread Michael Steven Rooney
Thanks.

How do I make my function visible to others? Will assignInNamespace do that?

On Mon, Apr 26, 2010 at 10:23 PM, Gabor Grothendieck <
ggrothendi...@gmail.com> wrote:

> See ?assignInNamespace
>
> On Mon, Apr 26, 2010 at 9:49 PM, Michael Steven Rooney
>  wrote:
> > Hi,
> >
> > I am trying to place my own functions in the nlme environment:
> >
> > The following statement works:
> >
> > environment(coef.corSPT) <- environment(getS3method("coef","corSpatial"))
> >
> > but this one returns an error:
> >
> > environment(get("coef<-.corSPT")) <-
> > environment(getS3method("coef<-","corSpatial"))
> > Error in environment(get("coef<-.corSPT")) <-
> > environment(getS3method("coef<-",  :
> >  target of assignment expands to non-language object
> >
> > What should I do?
> >
> > Thanks.
> >
> > Mike
> >
>  >[[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
> >
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Stuart Andrews


Thanks Charles, for clarifying.

My statement holds for matrices, which are 2 dimensional.  And, as you  
mentioned, a single index implies vector indexing where the drop  
argument doesn't make sense.   I am somewhat relieved, given this new  
understanding.


But I am still puzzled as to why R doesn't complain about the unused  
"drop=F" argument.  Since this argument is nonsensical, R should tell  
me this, no?  For example, when I add an unrecognized argument to the  
ls() function I get the following:


> ls(nonsense="42")
Error in ls(nonsense = "42") : unused argument(s) (nonsense = "42")

Cheers,
- Stu


On Apr 26, 2010, at 9:40 PM, Charles C. Berry wrote:


On Mon, 26 Apr 2010, Stu wrote:


Hi all,

One subtlety is that the drop argument only works if you specify 2 or
more indices e.g. [i, j, ..., drop=F]; but not for a single index e.g
[i, drop=F].


Wrong.


a <- structure(1:5,dim=5)
dim(a)

[1] 5

dim(a[2:3,drop=F]) # don't drop regardless

[1] 2

dim(a[2,drop=F]) # dont' drop regardless

[1] 1

dim(a[2:3,drop=T]) # no extent of length 1

[1] 2

dim(a[2,drop=T]) # drop, extent of length 1

NULL




Why doesn't R complain about the unused "drop=F" argument in the
single index case?


In the example you give (one index for a two-dimension array),  
vector indexing is assumed. For vector indexing, drop is irrelevant.


HTH,

Chuck


Cheers,
- Stu

a = matrix(1:10, nrow=1)
b = matrix(10:1, ncol=1)

# a1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(a1 = a[2:5, drop=F])
dim(a1)

# a2 is an vector WITH dim attribute: a row matrix (drop=F works)
(a2 = a[, 2:5, drop=F])
dim(a2)

# b1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(b1 = b[2:5, drop=F])
dim(b1)

# b2 is an vector WITH dim attribute: a column matrix (drop=F works)
(b2 = b[2:5, , drop=F])
dim(b2)


On Mar 30, 4:08 pm, lith  wrote:
Reframe the problem. Rethink why you need to keep dimensions. I  
never ever had to use drop.


The problem is that the type of the return value changes if you  
happen
to forget to use drop = FALSE, which can easily turn into a  
nightmare:


m <-matrix(1:20, ncol=4)
for (i in seq(3, 1, -1)) {
print(class(m[1:i, ]))}

[1] "matrix"
[1] "matrix"
[1] "integer"

__
r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/ 
listinfo/r-help

PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@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.



Charles C. Berry(858) 534-2098
   Dept of Family/Preventive  
Medicine

E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego  
92093-0901




__
R-help@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.


Re: [R] how to set chart output size in rgl (surface3d)?

2010-04-26 Thread Duncan Murdoch

Mandy Xu wrote:

Hi R users,

Does anyone know how to change the size of 3d charts? I'm using surface3d in
rgl package, opening a new window each time to display the chart. I want it
so that the chart fills the whole window, because when I output it to png, I
don't want all the white space around the chart (right now, i'm getting this
white "border" around the chart because the chart is smaller than the
window).

I know how to set the size of the window, but not the chart. When I make the
window smaller, the chart automatically resizes so it gets even smaller. Is
there a way to set the chart output size so it fills all (or most) of the
window?


Open a window, resize it to the look you want (the right button 
resizes), then save the par3d("zoom") value into r3dDefaults$zoom.  That 
will be the default zoom for new windows you open using open3d.  (You 
may also want to save par3d("userMatrix") into r3dDefaults$userMatrix, 
if you want to change the orientation of the default view.)


Duncan Murdoch

__
R-help@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.


Re: [R] when setting environment: target of assignment expands to non-language object

2010-04-26 Thread Gabor Grothendieck
See ?assignInNamespace

On Mon, Apr 26, 2010 at 9:49 PM, Michael Steven Rooney
 wrote:
> Hi,
>
> I am trying to place my own functions in the nlme environment:
>
> The following statement works:
>
> environment(coef.corSPT) <- environment(getS3method("coef","corSpatial"))
>
> but this one returns an error:
>
> environment(get("coef<-.corSPT")) <-
> environment(getS3method("coef<-","corSpatial"))
> Error in environment(get("coef<-.corSPT")) <-
> environment(getS3method("coef<-",  :
>  target of assignment expands to non-language object
>
> What should I do?
>
> Thanks.
>
> Mike
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@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.
>

__
R-help@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.


[R] Bhapkar V test

2010-04-26 Thread Karl-Dieter Crisman
Dear R help,

Is there a package which performs the Bhapkar V test (or any of the
Bhapkar-Deshpande L-type tests), preferably on the same sort of data
set input which kruskal.test() takes?  I haven't been able to find
anything so far (the one reference to Bhapkar seems to be some other
test, though I could be wrong) as an R function.

Thank you!
Karl-Dieter Crisman

__
R-help@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.


Re: [R] when setting environment: target of assignment expands to non-language object

2010-04-26 Thread Duncan Murdoch

Michael Steven Rooney wrote:

Hi,

I am trying to place my own functions in the nlme environment:
  


I'm not that does what you want.  It doesn't place your function in the 
environment, it attaches the environment to your function.  The 
difference is that other functions won't see yours, but your function 
will see whatever is in that environment.

The following statement works:

environment(coef.corSPT) <- environment(getS3method("coef","corSpatial"))

but this one returns an error:

environment(get("coef<-.corSPT")) <-
environment(getS3method("coef<-","corSpatial"))
Error in environment(get("coef<-.corSPT")) <-
environment(getS3method("coef<-",  :
  target of assignment expands to non-language object

What should I do?
  


If you want to change the coef<-.corSPT object, use backquotes to treat 
it as a name:

environment(`coef<-.corSPT`) <-  ...

Duncan Murdoch

Thanks.

Mike

[[alternative HTML version deleted]]

__
R-help@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.



__
R-help@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.


Re: [R] Tapply.

2010-04-26 Thread Dennis Murphy
Hi:

> On Mon, Apr 26, 2010 at 8:01 AM, steven mosher wrote:
> Thanks,

>  I was trying to stick with the base package and figure out how the base
routines worked.

If you want to use base functions, then here's a solution with aggregate:
(the Id column
was removed first):

> with(DF, aggregate(DF[, -2], list(Year = Year), FUN = mean, na.rm = TRUE))
  YearD Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 1980 1.00 NaN NaN NaN NaN NaN 212 203 209 228 237 NaN NaN
2 1981 0.50 NaN 251 243 246 241 NaN NaN NaN 230 NaN 231 245
3 1982 0.50 236 237 242 240 242 205 199 NaN NaN NaN NaN NaN
4 1983 0.50 NaN 247 NaN NaN NaN NaN NaN 205 NaN 225 NaN NaN
5 1986 0.00 NaN NaN NaN 240 NaN NaN NaN 213 NaN NaN NaN NaN
6 1987 1.33 241 NaN NaN NaN NaN 218 NaN NaN 235 243 240 NaN
7 1988 1.33 238 246 249 246 244 213 212 224 232 238 232 230
8 1989 1.33 232 233 238 239 231 NaN 215 NaN NaN NaN NaN 238

The problem with tapply() is that the function has to be called recursively
on each
column you want to summarize. You could do it in a loop:
> res <- matrix(NA, 8, 14)
> res[, 1] <- unique(DF$Year)
> res[, 2] <- with(DF, tapply(D, Year, mean, na.rm = TRUE))
> for(j in 3:14) res[, j] <- tapply(DF[, j], DF$Year, mean, na.rm = TRUE)
> res
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[,13]
[1,] 1980 1.00  NaN  NaN  NaN  NaN  NaN  212  203   209   228   237
NaN
[2,] 1981 0.50  NaN  251  243  246  241  NaN  NaN   NaN   230   NaN
231
[3,] 1982 0.50  236  237  242  240  242  205  199   NaN   NaN   NaN
NaN
[4,] 1983 0.50  NaN  247  NaN  NaN  NaN  NaN  NaN   205   NaN   225
NaN
[5,] 1986 0.00  NaN  NaN  NaN  240  NaN  NaN  NaN   213   NaN   NaN
NaN
[6,] 1987 1.33  241  NaN  NaN  NaN  NaN  218  NaN   NaN   235   243
240
[7,] 1988 1.33  238  246  249  246  244  213  212   224   232   238
232
[8,] 1989 1.33  232  233  238  239  231  NaN  215   NaN   NaN   NaN
NaN
 [,14]
[1,]   NaN
[2,]   245
[3,]   NaN
[4,]   NaN
[5,]   NaN
[6,]   NaN
[7,]   230
[8,]   238

but it's not the most efficient way to do things.

Essentially, this approach conforms to the 'split-apply-combine' strategy
which is
more efficiently implemented in functions like aggregate() or in packages
such
as doBy, plyr, reshape and data.table, some of which were mentioned earlier
by
Petr Pikal.

HTH,
Dennis

On Mon, Apr 26, 2010 at 8:01 AM, steven mosher wrote:

> Thanks,
>
>   I was trying to stick with the base package and figure out how the base
> routines worked. I looked at plyer and it was very appealing. I guess i'll
> give in and use it
>
> On Mon, Apr 26, 2010 at 2:33 AM, Dennis Murphy  wrote:
>
>> Hi:
>>
>> Use of ddply() in the plyr package appears to work.
>>
>> library(plyr)
>> ddply(df[, -1], .(Year), colwise(mean), na.rm = TRUE)
>>
>>  D Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
>> 1 1.00 1980 NaN NaN NaN NaN NaN 212 203 209 228 237 NaN NaN
>> 2 0.50 1981 NaN 251 243 246 241 NaN NaN NaN 230 NaN 231 245
>> 3 0.50 1982 236 237 242 240 242 205 199 NaN NaN NaN NaN NaN
>> 4 0.50 1983 NaN 247 NaN NaN NaN NaN NaN 205 NaN 225 NaN NaN
>> 5 0.00 1986 NaN NaN NaN 240 NaN NaN NaN 213 NaN NaN NaN NaN
>> 6 1.33 1987 241 NaN NaN NaN NaN 218 NaN NaN 235 243 240 NaN
>> 7 1.33 1988 238 246 249 246 244 213 212 224 232 238 232 230
>> 8 1.33 1989 232 233 238 239 231 NaN 215 NaN NaN NaN NaN 238
>>
>> Replace the NaNs with NAs and that should do it
>>
>> HTH,
>> Dennis
>>
>> On Sun, Apr 25, 2010 at 9:52 PM, steven mosher wrote:
>>
>>> Having some difficulties with understanding how tapply works and getting
>>> return values I expect
>>>
>>> Data: dataframe. DF  DF$Id $D $Year...
>>>
>>>  Id  D  Year Jan Feb Mar Apr May Jun Jul Aug Sep
>>> Oct
>>> Nov Dec
>>>  11264402000 1 1980  NA  NA  NA  NA  NA 212 203 209 228 237  NA
>>>  NA
>>>  11264402000 0 1981  NA  NA 243 244  NA  NA  NA  NA 225  NA 231
>>>  NA
>>>  11264402000 1 1981  NA 251  NA 248 241  NA  NA  NA 235  NA  NA
>>> 245
>>>  11264402000 0 1982 236 237 242 240 242 205 199  NA  NA  NA  NA
>>>  NA
>>>  11264402000 1 1982 236  NA  NA 240 242  NA  NA  NA  NA  NA  NA
>>>  NA
>>>  11264402000 0 1983  NA 247  NA  NA  NA  NA  NA 205  NA  NA  NA
>>>  NA
>>>  11264402000 1 1983  NA 247  NA  NA  NA  NA  NA  NA  NA 225  NA
>>>  NA
>>>  11264402000 0 1986  NA  NA  NA 240  NA  NA  NA 213  NA  NA  NA
>>>  NA
>>>  11264402000 0 1987 241  NA  NA  NA  NA 218  NA  NA 235 243 240
>>>  NA
>>>  11264402000 1 1987  NA  NA  NA  NA  NA 218  NA  NA 235 243 240
>>>  NA
>>>  11264402000 3 1987  NA  NA  NA  NA  NA 218  NA  NA 235 243 240
>>>  NA
>>>  11264402000 0 1988 238 246 249  NA 244 213 212 224 232 238 232
>>> 230
>>>  11264402000 1 1988 238 246 249 246 244 213 212 224 232  NA  NA
>>> 230
>>>  11264402000 3 1988 238 246 249 246 244 213 212 224 232  NA  NA
>>> 230
>>> 

Re: [R] Manipulating text files

2010-04-26 Thread galen kaufman

Thank you so much for the help. 

 

Is the idea behind doing this to convert the text file to a dataframe to allow 
me to work with and manipulate it?  Also, if I do convert it to a dataframe how 
do I reconvert it to a text file so that I can run it as a properly formatted 
input file in the water quality model?

 

Also, I should have included more of the input file and explained a little 
more. Below is a longer version of the input file just to give you an idea of 
what different parts of it may look like.  

 

….

 Inorganic Solids 2 (mg-DW/L) r
2   Number of boundaries
  1.00  1.00  Boundary Scale & Conversion Factors
1   Boundary Segment Number
2   Number of time-concentration values
   0.00  0.00
   75.  0.00
5   Boundary Segment Number
2   Number of time-concentration values
   0.00  0.00
   75.  0.00
….

….

   1   Segment number
   2  26.3900
   4  2.0
   6  7.0
   7  2.0
   8  1.5
2   Segment number
   2  26.3900
   4  2.0
   6  7.0
   7  2.0
   8  1.5

….
….
2.5 Phytoplankton Maximum Growth Rate Constant @20 øC for Group 1 (1/day)
1.08000 Phytoplankton Growth Temperature Coefficient for Group 1
0.20 Phytoplankton Respiration Rate Constant @20 øC for Group 1 (1/day)
1.04500 Phytoplankton Respiration Temperature Coefficient for Group 1
3.00E-02 Phytoplankton Death Rate Constant (Non-Zoo Predation) for Group 1 
(1/day)
0.00 Phytoplankton Zooplankton Grazing Rate Constant for Group 1 (1/day)
2.50E-02 Phytoplankton Half-Saturation Constant for N Uptake for Group 1 
(mg N/L)
…. 
 
 
I am going to have to change different values throughout the file, not just 
those numbers at the beginning of that last snippet. For example, I may want to 
change what is in the second row under "Segment number". To do this could I do 
something like:
 
# L <- readLines("myfile")
 
out <- strapply(L, "(.*)",
~ data.frame(text, stringsAsFactors = FALSE),
simplify = rbind)
 
Would this then give me each row in a data frame that I could then go in and 
work with?
 
How would I then go in and do steps 1(b) and 1(c)…… (1) (b)find the lines in 
the input file to insert parameter values into(values used in DEOptim 
optimization between “lower” and “upper”), (c) insert those parameter values 
into the input file in the proper spot, and then run this altered input 
file(step 2)…… Per 1(b) how do I tell the function to insert the parameter 
values selected in the DEOptim routine into the input file so that they can be 
run in the model? Also, would using conditional logic or maybe subset() be a 
way to start approaching the finding and replacing of lines in the dataframe?
 
Again, thank you for your help. Any additional help is very much appreciated.

 
> From: ggrothendi...@gmail.com
> Date: Sun, 25 Apr 2010 12:35:26 -0400
> Subject: Re: [R] Manipulating text files
> To: leavealett...@hotmail.com
> CC: r-help@r-project.org
> 
> Try this. First we read in the lines using readLines. (We use
> textConnection here to keep it self contained but you can read it from
> the file as shown in the commented out portion.)
> 
> Using strapply we match the regular expression to the input. The two
> parenthesized portions match the number (\\S+ means one or more
> non-space characters), we then match a space and the rest (.* means
> anything). These are processed as the two arguments of the function
> given in formula notation. Since the arguments are not explicitly
> listed it is assumed that the free variables no and text are the
> arguments. The result is a data frame with a numeric column, no,
> holding the number and a text column, text, holding the text.
> 
> 
> Lines <- "2.5 Phytoplankton Maximum Growth Rate Constant @20 øC
> for Group 1 (1/day)
> 1.08000 Phytoplankton Growth Temperature Coefficient for Group 1
> 0.20 Phytoplankton Respiration Rate Constant @20 øC for Group 1 (1/day)
> 1.04500 Phytoplankton Respiration Temperature Coefficient for Group 1
> 3.00E-02 Phytoplankton Death Rate Constant (Non-Zoo Predation) for
> Group 1 (1/day)
> 0.00 Phytoplankton Zooplankton Grazing Rate Constant for Group 1 (1/day)
> 2.50E-02 Phytoplankton Half-Saturation Constant for N Uptake for
> Group 1 (mg N/L)"
> 
> library(gsubfn) # http://gsubfn.googlecode.com
> 
> # L <- readLines("myfile")
> L <- readLines(textConnection(Lines))
> 
> out <- strapply(L, "(\\S+) (.*)",
> ~ data.frame(no = as.numeric(no), text, stringsAsFactors = FALSE),
> simplify = rbind)
> 
> An alternative to the last statement using only sub is:
> 
> out <- data.frame(no = as.numeric(sub(" .*", "", L)),
> text = sub("^[^ ]+ ", "", L))
> 
> Either of the above out <- statements produces:
> 
> > out
> no text
> [1,] 2.5 "Phytoplankton Maximum Growth Rate Constant @20 øC for
> Group 1 (1/day)"
> [2,] 1.08 "Phytoplankton Growth Temperature Coefficient f

Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Matthew Keller
Rolf: "Well then, why don't you go away and design and build your own
statistics and data analysis language/package to replace R?"

What a nice reply! The fellow is just trying to understand R. That
response reminds me of citizens of my own country who cannot abide by
any criticism of the USA: "If you don't like it, why don't you leave?"
Classy.

I have sympathies with the author. When I first began using R
(migrating from Matlab), I also found the vector concept strange,
especially because I was doing a lot of matrix algebra back then and
didn't like the concept of conflating a row vector with a column
vector. But I've since gotten used to it and can hardly remember why I
struggled with this early on. Perhaps your experience will be similar.

Best of luck!

Matt



On Mon, Apr 26, 2010 at 7:40 PM, Charles C. Berry  wrote:
> On Mon, 26 Apr 2010, Stu wrote:
>
>> Hi all,
>>
>> One subtlety is that the drop argument only works if you specify 2 or
>> more indices e.g. [i, j, ..., drop=F]; but not for a single index e.g
>> [i, drop=F].
>
> Wrong.
>
>> a <- structure(1:5,dim=5)
>> dim(a)
>
> [1] 5
>>
>> dim(a[2:3,drop=F]) # don't drop regardless
>
> [1] 2
>>
>> dim(a[2,drop=F]) # dont' drop regardless
>
> [1] 1
>>
>> dim(a[2:3,drop=T]) # no extent of length 1
>
> [1] 2
>>
>> dim(a[2,drop=T]) # drop, extent of length 1
>
> NULL
>
>
>>
>> Why doesn't R complain about the unused "drop=F" argument in the
>> single index case?
>
> In the example you give (one index for a two-dimension array), vector
> indexing is assumed. For vector indexing, drop is irrelevant.
>
> HTH,
>
> Chuck
>>
>> Cheers,
>> - Stu
>>
>> a = matrix(1:10, nrow=1)
>> b = matrix(10:1, ncol=1)
>>
>> # a1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
>> (a1 = a[2:5, drop=F])
>> dim(a1)
>>
>> # a2 is an vector WITH dim attribute: a row matrix (drop=F works)
>> (a2 = a[, 2:5, drop=F])
>> dim(a2)
>>
>> # b1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
>> (b1 = b[2:5, drop=F])
>> dim(b1)
>>
>> # b2 is an vector WITH dim attribute: a column matrix (drop=F works)
>> (b2 = b[2:5, , drop=F])
>> dim(b2)
>>
>>
>> On Mar 30, 4:08 pm, lith  wrote:

 Reframe the problem. Rethink why you need to keep dimensions. I never
 ever had to use drop.
>>>
>>> The problem is that the type of the return value changes if you happen
>>> to forget to use drop = FALSE, which can easily turn into a nightmare:
>>>
>>> m <-matrix(1:20, ncol=4)
>>> for (i in seq(3, 1, -1)) {
>>>     print(class(m[1:i, ]))}
>>>
>>> [1] "matrix"
>>> [1] "matrix"
>>> [1] "integer"
>>>
>>> __
>>> r-h...@r-project.org mailing
>>> listhttps://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting
>>> guidehttp://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> __
>> R-help@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.
>>
>
> Charles C. Berry                            (858) 534-2098
>                                            Dept of Family/Preventive
> Medicine
> E mailto:cbe...@tajo.ucsd.edu               UC San Diego
> http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901
>
>
> __
> R-help@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.
>
>



-- 
Matthew C Keller
Asst. Professor of Psychology
University of Colorado at Boulder
www.matthewckeller.com

__
R-help@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.


[R] how to set chart output size in rgl (surface3d)?

2010-04-26 Thread Mandy Xu
Hi R users,

Does anyone know how to change the size of 3d charts? I'm using surface3d in
rgl package, opening a new window each time to display the chart. I want it
so that the chart fills the whole window, because when I output it to png, I
don't want all the white space around the chart (right now, i'm getting this
white "border" around the chart because the chart is smaller than the
window).

I know how to set the size of the window, but not the chart. When I make the
window smaller, the chart automatically resizes so it gets even smaller. Is
there a way to set the chart output size so it fills all (or most) of the
window?

Thanks for all your help!

Best,
Mandy

[[alternative HTML version deleted]]

__
R-help@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.


[R] when setting environment: target of assignment expands to non-language object

2010-04-26 Thread Michael Steven Rooney
Hi,

I am trying to place my own functions in the nlme environment:

The following statement works:

environment(coef.corSPT) <- environment(getS3method("coef","corSpatial"))

but this one returns an error:

environment(get("coef<-.corSPT")) <-
environment(getS3method("coef<-","corSpatial"))
Error in environment(get("coef<-.corSPT")) <-
environment(getS3method("coef<-",  :
  target of assignment expands to non-language object

What should I do?

Thanks.

Mike

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] liner regression for multiple keys

2010-04-26 Thread newbie_2010

Hi Ben it's working good except no values of 4th column in output.
And also if the file is large I'm getting the following error.

Error in pf(q, df1, df2, lower.tail, log.p) : 
  Non-numeric argument to mathematical function


I rechecked if I have any non numeric arguments the defined columns.
Inputfile is good.
Any suggestions on this.

Thanx

-- 
View this message in context: 
http://r.789695.n4.nabble.com/liner-regression-for-multiple-keys-tp1839105p2066051.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Upgrading R using the "global library folder" strategy -, what do you think about it?

2010-04-26 Thread R P Herrold

On Mon, 26 Apr 2010, Marshall Feldman wrote:

So why not have the appropriate 
scripts ask a few questions upon the first installation of R (e.g., "Do you 
want to configure R with a "global" library for packages to make future 
upgrading easier?") and at upgrade time ("Your previous version of R has a 
"global" library; do you want the new version to use it?). I'd even go so far 
as to have the shell script automatically call an R script to run 
update.packages().


There is a large body of literature on this -- interactive 
questions of non-root users are useless; root user actiuons 
need to be scripted into the package management system 
acessible to automation to be scaleable, and to attain the 
needed administrator level permissions to make changed


The point is that most users just want to upgrade, and the upgrade procedure 
can and should (a) make this as seamless as possible and (b) allow those who 
may want to run specialized versions of R opt out of the automatic procedure.


and computers in a environment that has to conform to a 
hard specification (think: pharma research for FDA report 
preparation; financial service firms) that the IT department 
manages, cannot tolerate such diversity


There is no easy answer here, as 'one size cannot fit all'

-- Russ herrold

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Charles C. Berry

On Mon, 26 Apr 2010, Stu wrote:


Hi all,

One subtlety is that the drop argument only works if you specify 2 or
more indices e.g. [i, j, ..., drop=F]; but not for a single index e.g
[i, drop=F].


Wrong.


a <- structure(1:5,dim=5)
dim(a)

[1] 5

dim(a[2:3,drop=F]) # don't drop regardless

[1] 2

dim(a[2,drop=F]) # dont' drop regardless

[1] 1

dim(a[2:3,drop=T]) # no extent of length 1

[1] 2

dim(a[2,drop=T]) # drop, extent of length 1

NULL




Why doesn't R complain about the unused "drop=F" argument in the
single index case?


In the example you give (one index for a two-dimension array), vector 
indexing is assumed. For vector indexing, drop is irrelevant.


HTH,

Chuck


Cheers,
- Stu

a = matrix(1:10, nrow=1)
b = matrix(10:1, ncol=1)

# a1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(a1 = a[2:5, drop=F])
dim(a1)

# a2 is an vector WITH dim attribute: a row matrix (drop=F works)
(a2 = a[, 2:5, drop=F])
dim(a2)

# b1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(b1 = b[2:5, drop=F])
dim(b1)

# b2 is an vector WITH dim attribute: a column matrix (drop=F works)
(b2 = b[2:5, , drop=F])
dim(b2)


On Mar 30, 4:08 pm, lith  wrote:

Reframe the problem. Rethink why you need to keep dimensions. I never ever had 
to use drop.


The problem is that the type of the return value changes if you happen
to forget to use drop = FALSE, which can easily turn into a nightmare:

m <-matrix(1:20, ncol=4)
for (i in seq(3, 1, -1)) {
    print(class(m[1:i, ]))}

[1] "matrix"
[1] "matrix"
[1] "integer"

__
r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@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.


[R] Question on StatET

2010-04-26 Thread Shige Song
Dear All,

Does anyone know how to get StatET to do automatic word wrapping for
Sweave document? I am new to StatET, so please pardon me if I missed
something obvious. Many thanks.

Best,
Shige

__
R-help@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.


Re: [R] Unable to connect to 'cran.r-project.org' on port 80.

2010-04-26 Thread Cedrick W. Johnson
There was a notice earlier today about a power outage affecting the main 
CRAN site..


For installing packages, try:
install.packages("packagename", repos="http://cran.wustl.edu";)

or to perform an upgrade:
update.packages(repos="http://cran.wustl.edu";)

until the main CRAN site has been resolved. You can also google for 
alternate CRAN sites to use in the repos= area as well. Bioconductor I 
believe is on it's own site, not affected by the outage.


-c

On 4/26/2010 9:14 PM, Caitlin wrote:

Hi.

I recently upgraded my R installation to 2.11.0 on Windows XP (SP3) without
changing any firewall settings. When I attempted to update my package list,
the 'Select a mirror' took much longer than it normally did, and after I
finally selected the site, I saw:

--- Please select a CRAN mirror for use in this session ---
Warning message:
In open.connection(con, "r") :
unable to connect to 'cran.r-project.org' on port 80.

The only action I performed in a prior session was to download and install
several packages including Bioconductor.

Any idea what the problem might be?

Thanks,

Caitlin

[[alternative HTML version deleted]]

__
R-help@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.


__
R-help@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.


[R] Unable to connect to 'cran.r-project.org' on port 80.

2010-04-26 Thread Caitlin
Hi.

I recently upgraded my R installation to 2.11.0 on Windows XP (SP3) without
changing any firewall settings. When I attempted to update my package list,
the 'Select a mirror' took much longer than it normally did, and after I
finally selected the site, I saw:

--- Please select a CRAN mirror for use in this session ---
Warning message:
In open.connection(con, "r") :
unable to connect to 'cran.r-project.org' on port 80.

The only action I performed in a prior session was to download and install
several packages including Bioconductor.

Any idea what the problem might be?

Thanks,

Caitlin

[[alternative HTML version deleted]]

__
R-help@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.


[R] Problem with 'lars' package

2010-04-26 Thread khasanova
Hi,
I'm having trouble running 'lars'. When I install it I get the following
warning:

>install.packages('lars')
Warning in install.packages("lars") :
  argument 'lib' is missing: using
'C:\Users\Anna\Documents/R/win-library/2.10'
--- Please select a CRAN mirror for use in this session ---
trying URL
'http://cran.cnr.Berkeley.edu/bin/windows/contrib/2.10/lars_0.9-7.zip'
Content type 'application/zip' length 211898 bytes (206 Kb)
opened URL
downloaded 206 Kb

package 'lars' successfully unpacked and MD5 sums checked

The downloaded packages are in
C:\Users\Anna\AppData\Local\Temp\RtmpmRYoLn\downloaded_packages
Warning message:
In open.connection(con, "r") :
  unable to connect to 'cran.r-project.org' on port 80.


When I actually try to run it, it gives me the following message:

Error: argument "Gram" is missing, with no default

What is the problem?
Thank you,
Anna

__
R-help@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.


[R] plotmeans in trellis view?

2010-04-26 Thread DougB

Is there a way to use plotmeans function of Gplots in a trellis view with the
trellis groups defined by a column?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/plotmeans-in-trellis-view-tp2065860p2065860.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Confusing concept of vector and matrix in R

2010-04-26 Thread Stu
Hi all,

One subtlety is that the drop argument only works if you specify 2 or
more indices e.g. [i, j, ..., drop=F]; but not for a single index e.g
[i, drop=F].

Why doesn't R complain about the unused "drop=F" argument in the
single index case?

Cheers,
- Stu

a = matrix(1:10, nrow=1)
b = matrix(10:1, ncol=1)

# a1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(a1 = a[2:5, drop=F])
dim(a1)

# a2 is an vector WITH dim attribute: a row matrix (drop=F works)
(a2 = a[, 2:5, drop=F])
dim(a2)

# b1 is an vector w/o dim attribute (i.e. drop=F is ignored silently)
(b1 = b[2:5, drop=F])
dim(b1)

# b2 is an vector WITH dim attribute: a column matrix (drop=F works)
(b2 = b[2:5, , drop=F])
dim(b2)


On Mar 30, 4:08 pm, lith  wrote:
> > Reframe the problem. Rethink why you need to keep dimensions. I never ever 
> > had to use drop.
>
> The problem is that the type of the return value changes if you happen
> to forget to use drop = FALSE, which can easily turn into a nightmare:
>
> m <-matrix(1:20, ncol=4)
> for (i in seq(3, 1, -1)) {
>     print(class(m[1:i, ]))}
>
> [1] "matrix"
> [1] "matrix"
> [1] "integer"
>
> __
> r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@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.


Re: [R] Remove duplicated rows

2010-04-26 Thread chrisli1223

Thank you Petr, Gustaf and Gabor. Your help is much appreciated.

I have tried:

dataset[!duplicated(dataset[,-2]),]

and it solves my problem.

Thanks,
Chris
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Remove-duplicated-rows-tp2023065p2065997.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] I can't with expression

2010-04-26 Thread Paul Murrell

Hi

How about ... ?

library(grid)
# grid.newpage()
grid.text(expression(italic(P[SF]^{""%up%""})))

... or possibly a bit easier to read ...

grid.text(expression(italic(P[SF]^symbol("\255"

Paul

salca...@obelix.umh.es wrote:

Hi all,

I need an R expression, expression() to get the follows Latex code:
$P^\uparrow_{SF}$.

Imposible, for me!!. 
Thank you in advance

/salva

__
R-help@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.


--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

__
R-help@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.


Re: [R] plotmeans in trellis view?

2010-04-26 Thread Sam Albers

I'm not sure about "plotmeans" but this is usually the way I plot means with
lattice:

library(lattice)
x <-  runif(48, 2, 70)
data <- data.frame(x)
data$factor1 <- factor(c("A", "B", "C", "D"))
data$factor2 <- factor(c("X", "Y", "Z"))
data.mean <- with(data, aggregate(data$x, by=list(factor1=factor1,
factor2=factor2), mean))
with(data.mean, xyplot(x~factor1 | factor2))

Is this sort of what you were looking for?

HTH,

Sam
-- 
View this message in context: 
http://r.789695.n4.nabble.com/plotmeans-in-trellis-view-tp2065860p2065945.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] How to make legend with line+ character

2010-04-26 Thread John Kane
I suspect that you may have to construct the legend by hand (well, by explicit 
text commands anyway)  

Something like this seems to work and it should not be that difficult to write 
a function  to handle the text commands.

plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a')
text(1.4,6, label="-a- ", col="red")
text(2.5,6, label="dg1")


--- On Mon, 4/26/10, Mario Valle  wrote:

> From: Mario Valle 
> Subject: [R] How to make legend with line+ character
> To: "r-help@r-project.org" 
> Received: Monday, April 26, 2010, 7:32 AM
> Dear all,
> I have a multiline plot with each line labeled with a
> different letter.
> But I'm not able to make the legend display the same kind
> of pattern '-a-', instead the letter is overwritten by the
> line. A simpler legend with only the letter is not very
> visible and the pt.bg does nothing with letters. Any idea?
> 
> plot(1:10,10:1,lty=1,type='b', lwd=2,pch='a')
> legend("left", legend=c("ds1","ds2"), bty='n', col=1:2,
> lty=2,lwd=4,pch=letters)
> 
> Thanks for your help!
>            
>     mario
> -- Ing. Mario Valle
> Data Analysis and Visualization Group     
>       | http://www.cscs.ch/~mvalle
> Swiss National Supercomputing Centre (CSCS)   
>   | Tel:  +41 (91) 610.82.60
> v. Cantonale Galleria 2, 6928 Manno, Switzerland |
> Fax:  +41 (91) 610.82.82
> 
> __
> R-help@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.
> 



__
R-help@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.


Re: [R] Identifying breakpoints/inflection points?

2010-04-26 Thread Clint Bowman

Charlotte,

Try:

birds.lo <- loess(piproute~year,span=.25)
# play with span to see your desired pattern
birds.pr<-predict(birds.lo, data.frame(year = seq(1967, 2009, 1)), 
se = FALSE)

#
plot($year,birds.pr$fit,ylim=c(0,5))
par(new=T)
plot(year,birds.pr$fit,pch="+",col=2,ylim=c(0,5))


--
Clint BowmanINTERNET:   cl...@ecy.wa.gov
Air Quality Modeler INTERNET:   cl...@math.utah.edu
Department of Ecology   VOICE:  (360) 407-6815
PO Box 47600FAX:(360) 407-7534
Olympia, WA 98504-7600

On Mon, 26 Apr 2010, Charlotte Chang wrote:


Hello!
I have a dataset with the following two vectors:

year<-c(1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009)

piproute<-c(0.7,0.945945946,1.886363636,1.607843137,4.245614035,3.175675676,2.169014085,2,2.136363636,2.65625,2.080645161,2.114754098,2.090909091,3.012195122,2.935897436,2.592105263,1.075757576,1.210526316,1,1.1875,1.903614458,1.385542169,1.788990826,1.163793103,1.558558559,1.595238095,1.75833,1.858267717,2.169117647,1.403225806,2.859375,3.236220472,2.054263566,3.85417,1.812080537,2.708029197,2.75862069,2.625954198,4.540740741,3.686567164,2.8,2.968253968,3.517730496)

Pipits is the response variable (it is the number of birds counted at
each survey site in each year) and year is the independent variable.
If you plot it in R (plot(year,piproute,pch=19)), you'll see that the
relationship looks like a quintic polynomial.

Initially I was trying to fit this curve using an iterative equation,
but it's not working. I suspect that the curve-fitting equation itself
is inappropriate (it's a modified version of the logistic growth
equation). Now what I'd like to do is identify the 3 break/inflection
points in the population trend. That way, I can make an argument that
the break points corresponded to shifts in government policy with
respect to land use management. I've been looking at the segmented
package, and initially I looked at change.pt test in the circ.stats
package (which is inappropriate b/c my data is not amenable to
circular statistical analysis). Any ideas on what I could do would be
appreciated!

Thank you!

-Charlotte

__
R-help@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.



__
R-help@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.


Re: [R] numerical or not?

2010-04-26 Thread Ted Harding
On 26-Apr-10 21:19:51, Laetitia Schmid wrote:
> Hi,
> I've had a little problem for several weeks now. It is annoying and
> therefore I will ask for help:
> When I write a script with several iterations, I make it write out a
> text file to save the data during the run. For example I write:
> if (i %% 25) write.table(output,"temporary_output.txt")
> Later on, when I read in this output and want to calculate things,
> R complains that x is not numeric.
> I read it in with the following command:
> dat1<-read.table("temporary_output.txt",header=TRUE).
> It seems that R is saving my temporary output as a list.
> What is wrong here? And how can I do it better?
> 
> This time I attached the temporary_output.txt:

Thanks for supplying the file, Laetitia. it consists of one row
of variable-names (1600 of them), a first column of row-names
(integers **in quotes** from "1", "2", ... , "26", "27"), and
then 1600 columns each with 27 items of numerical (integer) data.

When read in using

  dat1<-read.table("temporary_output.txt",header=TRUE)

the result is dataframe of 1600 columns and 27 rows pof data.
The result of str(dat1) is:

  str(dat1)
  # 'data.frame':   27 obs. of  1600 variables:
  # $ P38: int  4 4 3 4 4 4 3 4 4 2 ...
  # $ P39: int  3 4 3 4 4 4 4 4 3 2 ...
  # $ P40: int  4 2 4 3 4 3 4 4 3 4 ...
  # $ P41: int  4 3 3 3 4 4 2 3 4 3 ...
  # $ P44: int  4 3 4 3 4 3 3 4 3 4 ...
  # $ P45: int  4 3 3 3 2 2 3 3 2 4 ...
  # $ P46: int  3 3 3 3 4 3 2 3 3 4 ...
  # $ P50: int  3 4 3 3 3 3 4 3 3 4 ...
  # $ P64: int  3 3 3 2 4 2 4 4 4 4 ...
  # $ P72: int  4 4 3 3 4 3 3 2 3 3 ...
  # $ P131   : int  4 3 3 3 3 3 4 4 3 4 ...
  # $ P132   : int  4 3 3 4 3 3 3 3 3 4 ...
  # $ P161   : int  4 3 3 4 3 3 4 3 3 3 ...
  # $ P174   : int  4 3 4 3 3 2 3 4 3 3 ...
  # $ P183   : int  3 2 4 3 4 3 3 4 4 4 ...
  # 

I have encountered no problem doing numerical calculations
with the data in this dataframe. Example:

  for(i in (1:27)){print(sum(dat[i,]))}
  # [1] 5095
  # [1] 5276
  # [1] 5004
  # 
  # [1] 5552
  # [1] 5417
  # [1] 5452

There are no non-numeric data in any row or column.

So it is totally unclear why, when you "want to calculate
things", you should get a statement to the effect that
"x is not numeric". What is "x", by the way? Is it a variable
in the "things" you want to calculate?

The best next step is for you to post an example of a calculation
based on "dat1" (as read in by the above command from the file
"temporary_output.txt" which you supplied) which gives rise to
the message about "not numeric". Then we can take it further.

As things stand, there is nothing visibly wrong with your data file,
so the problem almost certainly lies in the calculations that
you are trying to do.

Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 26-Apr-10   Time: 23:30:19
-- XFMail --

__
R-help@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.


Re: [R] numerical or not?

2010-04-26 Thread John Kane
I don't seem to be able to duplicate the problem.  Using your read.table 
command I get a data.frame (which is of course a type of list) and something 
like sum(dat1[,1] gives me a numerical result.

What variable is giving you the not numerical error message

--- On Mon, 4/26/10, Laetitia Schmid  wrote:

> From: Laetitia Schmid 
> Subject: [R] numerical or not?
> To: r-help@r-project.org
> Received: Monday, April 26, 2010, 5:19 PM
> Hi,
> I've had a little problem for several weeks now. It is
> annoying and
> therefore I will ask for help:
> When I write a script with several iterations, I make it
> write out a
> text file to save the data during the run. For example I
> write:
> if (i %% 25) write.table(output,"temporary_output.txt")
> Later on, when I read in this output and want to calculate
> things, R
> complains that x is not numeric.
> I read it in with the following command:
> dat1<-read.table("temporary_output.txt",header=TRUE).
> It seems that R is saving my temporary output as a list.
> What is wrong here? And how can I do it better?
> 
> This time I attached the temporary_output.txt:
> 
> 
> 
> 
> Thanks.
> Laetitia
> -Inline Attachment Follows-
> 
> __
> R-help@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.
>

__
R-help@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.


Re: [R] multiple paired t-tests without loops

2010-04-26 Thread Matthew Finkbeiner
Yes, I suspect that I will end up using a sampling approach, but I'd 
like to use an exact test if it's at all feasible.


Here are two samples of data from 3 subjects:
Sample  SubjC1  C2
44  1   0.0093  0.0077
44  2   0.0089  0.0069
44  3   0.051   0.0432
44  4   0.014   0.0147
44  5   0.0161  0.0117
45  1   0.0103  0.0086
45  2   0.0099  0.0078
45  3   0.0542  0.0458
45  4   0.0154  0.0163
45  5   0.0175  0.0129


and then here is the script I've pieced together from things I've found 
on the web (sorry for not citing the snippets!).  any pointers on how to 
speed it up would be greatly appreciated.


#--
# Utility function
# that returns binary representation of 1:(2^n) X SubjN
binary.v <-
function(n)
{
  x <- 1:(2^n)
  mx <- max(x)
  digits <- floor(log2(mx))
  ans <- 0:(digits-1); lx <- length(x)
  x <- matrix(rep(x,rep(digits, lx)),ncol=lx)
  x <- (x %/% 2^ans) %% 2
}

library(plyr)


#first some global variables
TotalSubjects <- 5
TotalSamples <- 2
StartSample <- 44
EndSample <- ((StartSample + TotalSamples)-1)
maxTs <- NULL
obsTs <- NULL




#create index array that drives the permuations for all samples
ind <- binary.v(TotalSubjects)

#transpose ind so that the first 2^N items correspond to S1,
#the second 2^N correspond to S2 and so on...
transind <- t(ind)

#get data file that is organized first by sample then by subj (e.g. 
sample1 subject1

# sample1 subject 2 ... sample 1 subject N)
#sampledatafile <- file.choose()

samples <- read.table(sampledatafile, header=T)

#this is the progress bar
pb <- txtProgressBar(min = StartSample, max = EndSample, style = 3)
setTxtProgressBar(pb, 1)

start.t <- proc.time()

#begin loop that analyzes data sample by sample
for (s in StartSample:EndSample) {

S <- samples[samples$Sample==s,] #pick up data for current sample

#reproduce data frame rows once for each permutation to be done
expanddata <- S[rep(1:nrow(S), each = 2^TotalSubjects),]


#create new array to hold the flipped (permuted) data
permdata = expanddata

#permute the data
permdata[transind==1,3] <- expanddata[transind==1,4] #Cnd1 <- Cnd2
permdata[transind==1,4] <- expanddata[transind==1,3] #Cnd2 <- Cnd1

#create permutation # as a factor in dataframe
PermN <- rep(rep(1:2^TotalSubjects, TotalSubjects),2)

#create Sample# as a factor
Sample <- rep(permdata[,1],2) #Sample# is in the 1st Column

#create subject IDs as a factor
Subj <- rep(permdata[,2],2) #Subject ID is in the 2nd Column

#stack the permutated data
StackedPermData <- stack(permdata[,3:4])

#bind all the factors together
StackedPermData <- as.data.frame(cbind(Sample, Subj, PermN, 
StackedPermData))



#sort by perm
sortedstack <- 
as.data.frame(StackedPermData[order(StackedPermData$PermN,

StackedPermData$Sample),])


#clear up some memory
rm(expanddata, permdata, StackedPermData)

#pull out data 1 perm at a time
res<-ddply(sortedstack, c("Sample", "PermN"), function(.data){

# Type combinations by Class
combs<-t(combn(sort(unique(.data[,5])),2))

# Applying the t-test for them
aaply(combs,1, function(.r){
x1<-.data[.data[,5]==.r[1],4] # select first column
x2<-.data[.data[,5]==.r[2],4] # select first column

tvalue <- t.test(x1,x2, paired = T)

res <- c(tvalue$statistic,tvalue$parameter,tvalue$p.value)
names(res) <- c('stat','df','pvalue')
res
}
)
}
)

 # update progress bar
 setTxtProgressBar(pb, s)

 #get max T vals
 maxTs <- c(maxTs, tapply (res$stat, list (res$Sample), max))

 #get observed T vals
 obsTs <- c(obsTs, res$stat[length(res$stat)])

 #here we need to save res to a binary file


}
#close out the progress bar
close(pb)

end.t <- proc.time() - start.t
print(end.t)

#get cutoffs
#these are the 2-tailed t-vals that maintain experimentwise error at the 
0.05 level

lowerT <- quantile(maxTs, .025)
upperT <- quantile(maxTs, .975)











On 4/27/2010 6:53 AM, Greg Snow wrote:

The usual way to speed up permutation testing is to sample from the
set of possible permutations rather than looking at all possible
ones.

If you show some code then we may be able to find some inefficiencies
for you, but there is not general solution, poorly written uses of
apply will be slower than well written for loops.  In some cases
rewriting critical pieces in C or fortran will help quite a bit, but
we need to see what you are already doing to know if that will help
or not.



__
R-help@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.


[R] Identifying breakpoints/inflection points?

2010-04-26 Thread Charlotte Chang
Hello!
I have a dataset with the following two vectors:

year<-c(1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009)

piproute<-c(0.7,0.945945946,1.886363636,1.607843137,4.245614035,3.175675676,2.169014085,2,2.136363636,2.65625,2.080645161,2.114754098,2.090909091,3.012195122,2.935897436,2.592105263,1.075757576,1.210526316,1,1.1875,1.903614458,1.385542169,1.788990826,1.163793103,1.558558559,1.595238095,1.75833,1.858267717,2.169117647,1.403225806,2.859375,3.236220472,2.054263566,3.85417,1.812080537,2.708029197,2.75862069,2.625954198,4.540740741,3.686567164,2.8,2.968253968,3.517730496)

Pipits is the response variable (it is the number of birds counted at
each survey site in each year) and year is the independent variable.
If you plot it in R (plot(year,piproute,pch=19)), you'll see that the
relationship looks like a quintic polynomial.

Initially I was trying to fit this curve using an iterative equation,
but it's not working. I suspect that the curve-fitting equation itself
is inappropriate (it's a modified version of the logistic growth
equation). Now what I'd like to do is identify the 3 break/inflection
points in the population trend. That way, I can make an argument that
the break points corresponded to shifts in government policy with
respect to land use management. I've been looking at the segmented
package, and initially I looked at change.pt test in the circ.stats
package (which is inappropriate b/c my data is not amenable to
circular statistical analysis). Any ideas on what I could do would be
appreciated!

Thank you!

-Charlotte

__
R-help@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.


Re: [R] Dropping "trailing zeroes" in longitudinal data

2010-04-26 Thread David Atkins


Bill--

Awesome; the code is perfect (for what we need).

Thank you so much for your help.

cheers, Dave

Dave Atkins, PhD
Research Associate Professor
Department of Psychiatry and Behavioral Science
University of Washington
datk...@u.washington.edu

Center for the Study of Health and Risk Behaviors (CSHRB)   
1100 NE 45th Street, Suite 300  
Seattle, WA  98105  
206-616-3879
http://depts.washington.edu/cshrb/
(Mon-Wed)   

Center for Healthcare Improvement, for Addictions, Mental Illness,
  Medically Vulnerable Populations (CHAMMP)
325 9th Avenue, 2HH-15
Box 359911
Seattle, WA 98104?
206-897-4210
http://www.chammp.org
(Thurs)


William Dunlap wrote:

-Original Message-
From: r-help-boun...@r-project.org 
[mailto:r-help-boun...@r-project.org] On Behalf Of David Atkins

Sent: Monday, April 26, 2010 12:23 PM
To: r-help@r-project.org
Subject: [R] Dropping "trailing zeroes" in longitudinal data


Background: Our research group collected data from students 
via the web 
about their drinking habits (alcohol) over the last 90 days.  As you 
might guess, some students seem to have lost interest and 
completed some 
information but not all.  Unfortunately, the survey was programmed to 
"pre-populate" the fields with zeroes (to make it easier for 
students to 
complete).


Obviously, when we see a stretch of zeroes, we've no idea 
whether this 
is "true" data or not, but we'd like to at least do some sensitivity 
analyses by dropping "trailing zeroes" (ie, when there are non-zero 
responses for some duration of the data that then "flat line" 
into all 
zeroes to the end of the time period)


I've included a toy dataset below.

Basically, we have the data in the "long" format, and what 
I'd like to 
do is subset the data.frame by deleting rows that occur at 
the end of a 
person's data that are all zeroes.  In a nutshell, select rows from a 
person that are continuously zero, up to first non-zero, 
starting at the 
end of their data (which, below, would be time = 10).


With the toy data, this would be the last 6 rows of ids #10 
and #8 (for 
example).  I can begin to think about how I might do this via 
grep/regexp but am a bit stumped about how to translate that to this 
type of data.


Any thoughts appreciated.

cheers, Dave

### toy dataset
set.seed(123)
toy.df <- data.frame(id = factor(rep(1:10, each=10)),
time = rep(1:10, 10),
	   dv = rnbinom(100, mu 
= 0.5, size = 100))

toy.df

library(lattice)

xyplot(dv ~ time | id, data = toy.df, type = c("g","l"))


Try using rle (run length encoding) along with either ave()
or lapply().  E.g., define the function

isInTrailingRunOfZeroes <- function (x, group, minRunLength = 1) {
as.logical(ave(x, group, FUN = function(x) {
r <- rle(x)
n <- length(r$values)
if (n == 0) {
logical(0)
} else if (r$values[n] == 0 && r$lengths[n] >= minRunLength) {
rep(c(FALSE, TRUE), c(sum(r$lengths[-n]), r$lengths[n]))
} else {
rep(FALSE, sum(r$lengths))
}
}))
}

and use it to drop the trailing runs of 0's with
xyplot(data=toy.df[!isInTrailingRunOfZeroes(toy.df$dv, toy.df$id),],
   dv~time|id, type=c("g","l"))
or replace them with NA's with
toy.df.copy <- toy.df
toy.df.copy[isInTrailingRunOfZeroes(toy.df.copy$dv,
toy.df.copy$id),"dv"] <- NA

The last argument, minRunLength lets you say you only want
to consider the data spurious if there are at least that many
zeroes.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

--
Dave Atkins, PhD
Research Associate Professor
Department of Psychiatry and Behavioral Science
University of Washington
datk...@u.washington.edu

Center for the Study of Health and Risk Behaviors (CSHRB)   
1100 NE 45th Street, Suite 300  
Seattle, WA  98105  
206-616-3879
http://depts.washington.edu/cshrb/
(Mon-Wed)   

Center for Healthcare Improvement, for Addictions, Mental Illness,
   Medically Vulnerable Populations (CHAMMP)
325 9th Avenue, 2HH-15
Box 359911
Seattle, WA 98104?
206-897-4210
http://www.chammp.org
(Thurs)

__
R-help@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.



__
R-help@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.


Re: [R] numerical or not?

2010-04-26 Thread jim holtman
It would be quicker, and easier, to use save/load to keep your temporary
output.  Therefore you would not have to be concerned with a structure that
would be compatible to write.table/read.table.

2010/4/26 Laetitia Schmid 

> Hi,
> I've had a little problem for several weeks now. It is annoying and
> therefore I will ask for help:
> When I write a script with several iterations, I make it write out a
> text file to save the data during the run. For example I write:
> if (i %% 25) write.table(output,"temporary_output.txt")
> Later on, when I read in this output and want to calculate things, R
> complains that x is not numeric.
> I read it in with the following command:
> dat1<-read.table("temporary_output.txt",header=TRUE).
> It seems that R is saving my temporary output as a list.
> What is wrong here? And how can I do it better?
>
> This time I attached the temporary_output.txt:
>
>
>
>
>
> Thanks.
> Laetitia
> __
> R-help@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.
>
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] numerical or not?

2010-04-26 Thread Sarah Goslee
I tried reading in your text file with the read.table statement
you provided. Everything worked fine for me - str() shows that
all values are integers, and functions such as summary()
work as anticipated.

You don't tell us *what* you are trying to do. One possible source
of error is that read.table() creates a dataframe - a list, not a matrix.
You can convert dat1
dat1 <- as.matrix(dat1)
and that might work better for your (unspecified) purposes.

If that doesn't help, providing a *working* example of what you
are doing will get you the most effective answers.

Sarah

2010/4/26 Laetitia Schmid :
> Hi,
> I've had a little problem for several weeks now. It is annoying and
> therefore I will ask for help:
> When I write a script with several iterations, I make it write out a
> text file to save the data during the run. For example I write:
> if (i %% 25) write.table(output,"temporary_output.txt")
> Later on, when I read in this output and want to calculate things, R
> complains that x is not numeric.
> I read it in with the following command:
> dat1<-read.table("temporary_output.txt",header=TRUE).
> It seems that R is saving my temporary output as a list.
> What is wrong here? And how can I do it better?
>
> This time I attached the temporary_output.txt:
>
>
>




-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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.


Re: [R] barplot - offsetting individual bars

2010-04-26 Thread Kevin Turner
I see what your suggesting.  Make the rain negative so that it plots on the
other side of the axis.  The axis labels can be adjusted accordingly.  That
makes it simple.  Thanks for the help.


On Mon, Apr 26, 2010 at 3:49 PM, Greg Snow  wrote:

> Does this do what you want?
>
> rainsnow <- rbind( c(0,1,2,3,2,1,0), c(2,2,1,0,0,1,2) )
>
> rainsnow2 <- rbind( rainsnow[1,], -rainsnow[1,], -rainsnow[2,] )
>
> fig=barplot(rainsnow2, horiz=TRUE, space=0, col=c("grey70",NA,
> "white"), axes=FALSE)
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
>
>
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> > project.org] On Behalf Of Kevin Turner
> > Sent: Saturday, April 24, 2010 1:04 PM
> > To: r-help@r-project.org
> > Subject: [R] barplot - offsetting individual bars
> >
> > Hello,
> >
> > I'm trying currently using barplot to summarize precipitation data.  So
> > far
> > I've compiled total annual snow and rain accumulation in a table
> > (attached).  I've been successful at plotting it using the following
> > code:
> >
> > fig=barplot(t(Annual_Precip_table), horiz=TRUE, space=0,
> > col=c("grey70",
> > "white"), axes=FALSE)
> > .
> > .
> > The result is a stacked barplot with total annual rain represented by
> > grey
> > bars and total annual snow represented by white bars.  This is great,
> > however, I'd like to position the bars so that the rain bars are right
> > justified on the axis and the snow bars are left justified on the axis.
> >
> > I looked around for ways to do this, and I'm not sure, but is plotrix
> > capable of doing it using the barb function?  Does anyone have
> > experience
> > with this kind of plot?
> >
> > Thanks.
> >
> > --
> > Kevin Turner
> > Department of Geography
> > and Environmental Studies
> > Wilfrid Laurier University
> > Waterloo, Ontario
>



-- 
Kevin Turner
Department of Geography
and Environmental Studies
Wilfrid Laurier University
Waterloo, Ontario

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] write.csv size limit in R 2.11.0 -- crashes

2010-04-26 Thread Duncan Murdoch

On 26/04/2010 4:25 PM, N Klepeis wrote:

Hi,

I just installed R 2.11.0 Win32 and tried to use write.csv (or 
write.table) to write a 121000x26 data frame. This crashes R.


The dataframe was written OK in R 2.10.1.

I tried up to 108000 rows and the file was written OK.  But then going 
to 109000 causes the crash.


Anyone else see this?   I'll gather some more info before reporting a bug.
  


Please try R 2.11.0 patched.  There was a problem in the date/time 
formatting routines which I fixed a few days ago in revision 51811 that 
could be involved here.  (You may need to wait a few days:
CRAN is offline, and the mirrors I checked hadn't updated to this 
version yet.)


You could also try an R-devel build; it never had the bug.

Duncan Murdoch

P.S. Bug discussions are generally better in R-devel rather than R-help

__
R-help@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.


Re: [R] table command

2010-04-26 Thread Greg Snow
Is the fact that 0 is a possible and interesting value (even in being absent) a 
property of the table? Or a property of the variable?

I would argue that it is probably a property of the variable, and this is the 
better way to work with it in R (some older programs forced us to specify this 
at the analysis stage and it can take a bit of an effort to break that habit 
and do the more sensible approach).

I would convert your data to factors (or ordered factors) and specify the 
levels, then table just works on its own:

# untested code
> s2 <- as.data.frame( lapply(s, function(x) factor(x, levels=0:1) ) )
> table( s2[,c(1,3)] )

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Shubha Vishwanath Karanth
> Sent: Saturday, April 24, 2010 7:59 AM
> To: r-help@r-project.org; r-h...@stat.math.ethz.ch
> Subject: [R] table command
> 
> Hi,
> 
> 
> 
> Let s be a dataframe.
> 
> 
> 
> > s
> 
>A B C
> 
>0 0 1
> 
>1 0 1
> 
>1 0 1
> 
>0 0 1
> 
>1 0 1
> 
>0 1 1
> 
>0 1 1
> 
>0 1 1
> 
>0 0 1
> 
> 
> 
> > tab1=table(s[,c(1,2)])
> 
> > tab1
> 
>B
> 
> A   0 1
> 
>   0 3 3
> 
>   1 3 0
> 
> 
> 
> > tab2=table(s[,c(1,3)])
> 
> > tab2
> 
>C
> 
> A   1
> 
>   0 6
> 
>   1 3
> 
> 
> 
> 
> 
> The problem is I need to access frequency corresponding to (0,0).
> tab1[1] will give me the correct value while tab2[1] will not give the
> frequency which I expected. So, is there a possibility in the table
> command to have the order of tab1 and tab2 being equal? (here 2*2). May
> be by filling in the appropriate value as 0 or NA?
> 
> 
> 
> Thanks,
> 
> Shubha
> 
> 
> 
> This e-mail may contain confidential and/or privileged
> i...{{dropped:13}}
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] multiple paired t-tests without loops

2010-04-26 Thread Greg Snow
The usual way to speed up permutation testing is to sample from the set of 
possible permutations rather than looking at all possible ones.

If you show some code then we may be able to find some inefficiencies for you, 
but there is not general solution, poorly written uses of apply will be slower 
than well written for loops.  In some cases rewriting critical pieces in C or 
fortran will help quite a bit, but we need to see what you are already doing to 
know if that will help or not.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Matthew Finkbeiner
> Sent: Saturday, April 24, 2010 4:58 AM
> To: r-help@r-project.org
> Subject: [R] multiple paired t-tests without loops
> 
> I am new to R and I suspect my problem is easily solved, but I haven't
> been able to figure it out without using loops.  I am trying to
> implement Blair & Karniski's (1993) permutation test.  I've included a
> sample data frame below.  This data frame represents the conditional
> means (C1, C2) for 3 subjects in 2 consecutive samples of a continuous
> data set (e.g. ERP waveform).  Each sample includes all possible
> permuations of the subject means (2^N), which is 8 in this case.
> 
> The problem: I need to run a paired t-test on each SampleXPermutation
> set and save the maximum t-value obtained for each sample.  The real
> data set has 16 subjects (216 permutations) and 500 samples, which
> leads
> to more than 32 million t-tests.  I have a loop version of the program
> working, but it would take a few weeks to complete the job and I was
> hoping that someone could tell me how to do it faster?
> 
> thank you kindly,
> 
> Matthew Finkbeiner
> 
> 
> 
> "Sample""C1""C2""PermN"
> 158perm1
> 143perm1
> 164perm1
> 226perm1
> 231perm1
> 274perm1
> 185perm2
> 134perm2
> 164perm2
> 262perm2
> 213perm2
> 274perm2
> 158perm3
> 134perm3
> 164perm3
> 226perm3
> 213perm3
> 274perm3
> 185perm4
> 143perm4
> 146perm4
> 262perm4
> 231perm4
> 247perm4
> 158perm5
> 143perm5
> 146perm5
> 226perm5
> 231perm5
> 247perm5
> 185perm6
> 134perm6
> 146perm6
> 262perm6
> 213perm6
> 247perm6
> 158perm7
> 134perm7
> 146perm7
> 226perm7
> 213perm7
> 247perm7
> 185perm8
> 143perm8
> 164perm8
> 262perm8
> 231perm8
> 274perm8
> 
> 
> 
> 
> 
> 
> --
> Dr. Matthew Finkbeiner
> Senior Lecturer & ARC Australian Research Fellow
> Macquarie Centre for Cognitive Science (MACCS)
> Macquarie University, Sydney, NSW 2109
> 
> Phone: +61 2 9850-6718
> Fax:   +61 2 9850-6059
> Homepage: http://www.maccs.mq.edu.au/~mfinkbei
> Lab Homepage: http://www.maccs.mq.edu.au/laboratories/action/
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] seed

2010-04-26 Thread Greg Snow
The set.seed function works like you show.  If you want to get a little fancier 
you can use the char2seed function from the TeachingDemos package, then you 
could set you seed with something like:

> char2seed('jimmy')

Or another string that represents the simulation.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Jimmy Söderly
> Sent: Monday, April 26, 2010 8:46 AM
> To: r-help@r-project.org
> Subject: [R] seed
> 
> Hi everybody,
> 
> How can I set the seed for my simulations ? Is "set.seed(123456)"
> alright ?
> 
> Thanks a lot,
> Jimmy
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] change the size of matrix

2010-04-26 Thread Henrique Dallazuanna
You can use matrix:

A=matrix(c(1,4,7,10,2,5,8,11,3,6,9,12),c(3,4))
B <- matrix(A, 2, 6)

On Mon, Apr 26, 2010 at 4:58 PM, anderson nuel wrote:

> I would find function which change the size automatically.
>
> For example:
>
> > A=matrix(c(1,4,7,10,2,5,8,11,3,6,9,12),c(3,4))
> > A
> [,1] [,2] [,3] [,4]
> [1,]1   1086
> [2,]42   119
> [3,]753   12
>
> B=func(A,2,6)
>
> B becomes:
>
>13579   11
>2468   10   12
>
> Best
>
> 2010/4/26 David Winsemius 
>
> >
> > On Apr 26, 2010, at 3:18 PM, anderson nuel wrote:
> >
> >  Dear r-help,
> >>
> >> Could you help me to find the function which change the size of matrix .
> >>
> >
> > ?dim
> >
> >
> >>
> >> Best Regards
> >>
> >
> >
> > David Winsemius, MD
> > West Hartford, CT
> >
> >
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] change the size of matrix

2010-04-26 Thread anderson nuel
I would find function which change the size automatically.

For example:

> A=matrix(c(1,4,7,10,2,5,8,11,3,6,9,12),c(3,4))
> A
 [,1] [,2] [,3] [,4]
[1,]1   1086
[2,]42   119
[3,]753   12

B=func(A,2,6)

B becomes:

13579   11
2468   10   12

Best

2010/4/26 David Winsemius 

>
> On Apr 26, 2010, at 3:18 PM, anderson nuel wrote:
>
>  Dear r-help,
>>
>> Could you help me to find the function which change the size of matrix .
>>
>
> ?dim
>
>
>>
>> Best Regards
>>
>
>
> David Winsemius, MD
> West Hartford, CT
>
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] write.csv size limit in R 2.11.0 -- crashes

2010-04-26 Thread N Klepeis

Hi,

I just installed R 2.11.0 Win32 and tried to use write.csv (or 
write.table) to write a 121000x26 data frame. This crashes R.


The dataframe was written OK in R 2.10.1.

I tried up to 108000 rows and the file was written OK.  But then going 
to 109000 causes the crash.


Anyone else see this?   I'll gather some more info before reporting a bug.

--Neil

__
R-help@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.


Re: [R] failing to select a subset of observations based on variable values [Sec: UNCLASSIFIED]

2010-04-26 Thread David Winsemius


On Apr 26, 2010, at 3:39 PM, Gosse, Michelle wrote:


Greetings all.

I'm starting analysis in R on a reasonably sized pre-existing  
dataset, of 583 variables and 1127 observations. This was an SPSS  
datafile, which I read in using the read.spss command using the  
foreign package, and the data was assigned to a data.frame when it  
was read in. The defaults in read.spss were used, except I set  
to.data.frame = TRUE.


The data is a survey dataset (each observation/case = one  
participant), and many of the variables are participants' responses  
to Likert scale items. These have been coded on a 1 to 7 scale, with  
"8" used to code "Don't know" responses. The assumption is that the  
1-7 responses are at least interval level, however the response "8"  
is clearly not. For many analyses, this doesn't matter because I'm  
only doing chi-square tests. However, for a between-group comparison  
crosstab I would like to exclude those who gave "8" responses  
because I am only interesting in testing differences for the  
participants who gave responses measured on the Likert scale proper.


I have encountered problems when I need to exclude the observations  
from analysis, where they gave an "8" response to either of two  
questions (Question 1A and Question 1B), which relate to columns 72  
and 73 of the dataframe. The chi-square I am trying to do is based  
on two other variables (mean of Q1A+Q1B for each participant) and a  
grouping variable, which are contained in columns 8 and 80 of the  
dataframe, respectively. The reason I am excluding anyone who gave  
an "8" ("Don't know) response on questions 1A and 1B is that their  
mean on these two questions cannot be interpreted as the value "8"  
is nominal rather than interval/ratio and therefore cannot be used  
in a mathematical expression.


I've been trying to use an if-or combination, and I can't get it to  
work.


Did you read the help page for if?
?"if"

The chi-square test without the attempt to subset using "if" is  
working fine, I don't understand what I am doing wrong in my  
attempts to subset.


I have tried to reference the variables like this:

if ("Q1A"!=8 | "Q1B"!=8)

+ (table(micronutrients[,8,80]))


chisq.test(table(micronutrients[,8,80]))


The group counts returned from the table statement show me that no  
observations are being excluded from the analysis. The chisq.test  
works fine on (table(micronutrients[,8,80])) but, of course, it is  
being performed on the entire dataset as I have been unsuccessful in  
subsetting the data.


I tried to see if the column names were objects and I got these  
errors:

object("Q1A")

Error: could not find function "object"

Q1A

Error: object 'Q1A' not found
I'm not sure if this is important.

So I tried to do the if-or using the column number, but that didn't  
work either:

if (micronutrients[,72]!=8 | micronutrients[,73]!=8)


Leave behind your SPSS syntactical constructions. SPSS and the SAS  
data steps have implicit loops that operate sequantially along rows of  
datasets. R does not work that way. A corresponding operation in R  
might be:


 apply(dataframe1, 1, )

 "if" is a program control mechanism that does not operate on  
vectors. If it gets a vector if evaluates the first element and  
ignores the rest. (You should have gotten a warning and you should  
have posted the warning.)


There is also the ifelse function that works with and returns vectors.


+ ()

Warning message:
In if () (table(micronutrients[,  :
 the condition has length > 1 and only the first element will be used

I got exactly the same chi-square output as in my previous attempt.

If any of you know SPSS, what I am trying to do in R is equivalent  
to: temporary. select if not (Q1A=8 or Q1B=8). In SAS, it would be  
the same as a subsetting if that lasted only for the particular  
analysis, or a where, e.g. proc tabulate; where Q1A ne 8 or Q1B ne 8;


How can I subset the data? I would prefer not to create another  
variable to hold the recodes as the dataset is already complex.


?subset
?with

with(subset(dfrm, micronutrients[, 72] != 8 | micronutrients[, 73] !=  
8), table(...) )


Not sure what you intended with ... table(micronutrients[,8,80]) ... ,  
but generally one does not first reference an object with two  
dimensions and then do so with three. It is considered good form  
around these parts to offer at the very least str() on an object about  
which you are hoping to get specific advice. We cannot read your mind.





I only wish the subsetting condition to hold for the test  
immediately following the instruction to subset (I need to subset  
the data in different ways for different question combinations).  
Because the instruction is complete once the table() command is  
issued, I am assuming that the if statement only relates to the  
table() command and therefore only indirectly to the chisq.test()  
command following (as this is being performed on the subsetted  
table) - which is exactly wha

Re: [R] Dropping "trailing zeroes" in longitudinal data

2010-04-26 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of David Atkins
> Sent: Monday, April 26, 2010 12:23 PM
> To: r-help@r-project.org
> Subject: [R] Dropping "trailing zeroes" in longitudinal data
> 
> 
> Background: Our research group collected data from students 
> via the web 
> about their drinking habits (alcohol) over the last 90 days.  As you 
> might guess, some students seem to have lost interest and 
> completed some 
> information but not all.  Unfortunately, the survey was programmed to 
> "pre-populate" the fields with zeroes (to make it easier for 
> students to 
> complete).
> 
> Obviously, when we see a stretch of zeroes, we've no idea 
> whether this 
> is "true" data or not, but we'd like to at least do some sensitivity 
> analyses by dropping "trailing zeroes" (ie, when there are non-zero 
> responses for some duration of the data that then "flat line" 
> into all 
> zeroes to the end of the time period)
> 
> I've included a toy dataset below.
> 
> Basically, we have the data in the "long" format, and what 
> I'd like to 
> do is subset the data.frame by deleting rows that occur at 
> the end of a 
> person's data that are all zeroes.  In a nutshell, select rows from a 
> person that are continuously zero, up to first non-zero, 
> starting at the 
> end of their data (which, below, would be time = 10).
> 
> With the toy data, this would be the last 6 rows of ids #10 
> and #8 (for 
> example).  I can begin to think about how I might do this via 
> grep/regexp but am a bit stumped about how to translate that to this 
> type of data.
> 
> Any thoughts appreciated.
> 
> cheers, Dave
> 
> ### toy dataset
> set.seed(123)
> toy.df <- data.frame(id = factor(rep(1:10, each=10)),
>   time = rep(1:10, 10),
>  dv = rnbinom(100, mu 
> = 0.5, size = 100))
> toy.df
> 
> library(lattice)
> 
> xyplot(dv ~ time | id, data = toy.df, type = c("g","l"))

Try using rle (run length encoding) along with either ave()
or lapply().  E.g., define the function

isInTrailingRunOfZeroes <- function (x, group, minRunLength = 1) {
as.logical(ave(x, group, FUN = function(x) {
r <- rle(x)
n <- length(r$values)
if (n == 0) {
logical(0)
} else if (r$values[n] == 0 && r$lengths[n] >= minRunLength) {
rep(c(FALSE, TRUE), c(sum(r$lengths[-n]), r$lengths[n]))
} else {
rep(FALSE, sum(r$lengths))
}
}))
}

and use it to drop the trailing runs of 0's with
xyplot(data=toy.df[!isInTrailingRunOfZeroes(toy.df$dv, toy.df$id),],
   dv~time|id, type=c("g","l"))
or replace them with NA's with
toy.df.copy <- toy.df
toy.df.copy[isInTrailingRunOfZeroes(toy.df.copy$dv,
toy.df.copy$id),"dv"] <- NA

The last argument, minRunLength lets you say you only want
to consider the data spurious if there are at least that many
zeroes.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 
> 
> -- 
> Dave Atkins, PhD
> Research Associate Professor
> Department of Psychiatry and Behavioral Science
> University of Washington
> datk...@u.washington.edu
> 
> Center for the Study of Health and Risk Behaviors (CSHRB) 
> 1100 NE 45th Street, Suite 300
> Seattle, WA  98105
> 206-616-3879  
> http://depts.washington.edu/cshrb/
> (Mon-Wed) 
> 
> Center for Healthcare Improvement, for Addictions, Mental Illness,
>Medically Vulnerable Populations (CHAMMP)
> 325 9th Avenue, 2HH-15
> Box 359911
> Seattle, WA 98104?
> 206-897-4210
> http://www.chammp.org
> (Thurs)
> 
> __
> R-help@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.
> 

__
R-help@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.


Re: [R] 2 simple question

2010-04-26 Thread Greg Snow
A couple of additions to the suggestions that you have already received:

1. you can use par(mfrow=c(r,c)) to set up the plotting areas, then us 
par(mfg=c(r,c)) to tell R which frame to plot into.

2. you could start with an empty plot and use the subplot function 
(TeachingDemos package) to place each plot exactly where you want.

3. you can use layout, just create the matrix with the numbers representing the 
order you want to plot.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of tamas barjak
> Sent: Friday, April 23, 2010 2:58 PM
> To: r-help@r-project.org
> Subject: [R] 2 simple question
> 
> Hi All!
> 
> I have 2 plain questions:
> 
> 1.)
> I know that very primitive question, but that to grant it, that the
> drawing
> on the screen divided up onto which part draw
> 
> for example:
> 
> 
> layout(matrix(1:4,ncol=2, byrow=T))
> 
> plot(x, y, ...) <--- 1. screen
> 
> plot(y, z, ...) <--- 3. screen
> 
> plot(z, x, ...) <--- 2. screen
> 
> etc...
> 
> 2.)
> 
> How I can fix it and to insert the random numbers in order for him to
> generate them later
> 
> for example:
> 
> a<-runif(100)
> 
> and to insert these here---> rnorm(100, 0, 1)
> 
> Thank you!
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] change the size of matrix

2010-04-26 Thread David Winsemius


On Apr 26, 2010, at 3:58 PM, anderson nuel wrote:


I would find function which change the size automatically.


Read the help page again. You have too quickly formed an erroneous  
conclusion.




For example:

> A=matrix(c(1,4,7,10,2,5,8,11,3,6,9,12),c(3,4))
> A
 [,1] [,2] [,3] [,4]
[1,]1   1086
[2,]42   119
[3,]753   12

B=func(A,2,6)

B becomes:

13579   11
2468   10   12

Best

2010/4/26 David Winsemius 

On Apr 26, 2010, at 3:18 PM, anderson nuel wrote:

Dear r-help,

Could you help me to find the function which change the size of  
matrix .


?dim



Best Regards


David Winsemius, MD
West Hartford, CT




David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] change the size of matrix

2010-04-26 Thread David Winsemius


On Apr 26, 2010, at 3:18 PM, anderson nuel wrote:


Dear r-help,

Could you help me to find the function which change the size of  
matrix .


?dim




Best Regards



David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] barplot - offsetting individual bars

2010-04-26 Thread Greg Snow
Does this do what you want?

rainsnow <- rbind( c(0,1,2,3,2,1,0), c(2,2,1,0,0,1,2) )

rainsnow2 <- rbind( rainsnow[1,], -rainsnow[1,], -rainsnow[2,] )

fig=barplot(rainsnow2, horiz=TRUE, space=0, col=c("grey70",NA,
"white"), axes=FALSE)

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Kevin Turner
> Sent: Saturday, April 24, 2010 1:04 PM
> To: r-help@r-project.org
> Subject: [R] barplot - offsetting individual bars
> 
> Hello,
> 
> I'm trying currently using barplot to summarize precipitation data.  So
> far
> I've compiled total annual snow and rain accumulation in a table
> (attached).  I've been successful at plotting it using the following
> code:
> 
> fig=barplot(t(Annual_Precip_table), horiz=TRUE, space=0,
> col=c("grey70",
> "white"), axes=FALSE)
> .
> .
> The result is a stacked barplot with total annual rain represented by
> grey
> bars and total annual snow represented by white bars.  This is great,
> however, I'd like to position the bars so that the rain bars are right
> justified on the axis and the snow bars are left justified on the axis.
> 
> I looked around for ways to do this, and I'm not sure, but is plotrix
> capable of doing it using the barb function?  Does anyone have
> experience
> with this kind of plot?
> 
> Thanks.
> 
> --
> Kevin Turner
> Department of Geography
> and Environmental Studies
> Wilfrid Laurier University
> Waterloo, Ontario

__
R-help@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.


[R] failing to select a subset of observations based on variable values [Sec: UNCLASSIFIED]

2010-04-26 Thread Gosse, Michelle
Greetings all.

I'm starting analysis in R on a reasonably sized pre-existing dataset, of 583 
variables and 1127 observations. This was an SPSS datafile, which I read in 
using the read.spss command using the foreign package, and the data was 
assigned to a data.frame when it was read in. The defaults in read.spss were 
used, except I set to.data.frame = TRUE.

The data is a survey dataset (each observation/case = one participant), and 
many of the variables are participants' responses to Likert scale items. These 
have been coded on a 1 to 7 scale, with "8" used to code "Don't know" 
responses. The assumption is that the 1-7 responses are at least interval 
level, however the response "8" is clearly not. For many analyses, this doesn't 
matter because I'm only doing chi-square tests. However, for a between-group 
comparison crosstab I would like to exclude those who gave "8" responses 
because I am only interesting in testing differences for the participants who 
gave responses measured on the Likert scale proper.

I have encountered problems when I need to exclude the observations from 
analysis, where they gave an "8" response to either of two questions (Question 
1A and Question 1B), which relate to columns 72 and 73 of the dataframe. The 
chi-square I am trying to do is based on two other variables (mean of Q1A+Q1B 
for each participant) and a grouping variable, which are contained in columns 8 
and 80 of the dataframe, respectively. The reason I am excluding anyone who 
gave an "8" ("Don't know) response on questions 1A and 1B is that their mean on 
these two questions cannot be interpreted as the value "8" is nominal rather 
than interval/ratio and therefore cannot be used in a mathematical expression.

I've been trying to use an if-or combination, and I can't get it to work. The 
chi-square test without the attempt to subset using "if" is working fine, I 
don't understand what I am doing wrong in my attempts to subset.

I have tried to reference the variables like this:
> if ("Q1A"!=8 | "Q1B"!=8)
+ (table(micronutrients[,8,80]))

> chisq.test(table(micronutrients[,8,80]))

The group counts returned from the table statement show me that no observations 
are being excluded from the analysis. The chisq.test works fine on 
(table(micronutrients[,8,80])) but, of course, it is being performed on the 
entire dataset as I have been unsuccessful in subsetting the data.

I tried to see if the column names were objects and I got these errors:
> object("Q1A")
Error: could not find function "object"
> Q1A
Error: object 'Q1A' not found
I'm not sure if this is important.

So I tried to do the if-or using the column number, but that didn't work either:
> if (micronutrients[,72]!=8 | micronutrients[,73]!=8)
+ (table(micronutrients[,8,80]))

Warning message:
In if (micronutrients[, 72] != 8 | micronutrients[, 73] != 8) 
(table(micronutrients[,  :
  the condition has length > 1 and only the first element will be used

I got exactly the same chi-square output as in my previous attempt.

If any of you know SPSS, what I am trying to do in R is equivalent to: 
temporary. select if not (Q1A=8 or Q1B=8). In SAS, it would be the same as a 
subsetting if that lasted only for the particular analysis, or a where, e.g. 
proc tabulate; where Q1A ne 8 or Q1B ne 8;

How can I subset the data? I would prefer not to create another variable to 
hold the recodes as the dataset is already complex.

I only wish the subsetting condition to hold for the test immediately following 
the instruction to subset (I need to subset the data in different ways for 
different question combinations). Because the instruction is complete once the 
table() command is issued, I am assuming that the if statement only relates to 
the table() command and therefore only indirectly to the chisq.test() command 
following (as this is being performed on the subsetted table) - which is 
exactly what I want.

Cheers
Michelle

**
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.clearswift.com
**



[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] formatted output facilities ... was ..Oddity with internet access and R 11.0 - solved

2010-04-26 Thread Greg Snow
If you like the idea of ODFWeave, but don't want to trasition to open office 
then you may want to look at sword from the same group that brought us RExcel 
(http://rcom.univie.ac.at/download.html).  It looks like Sword is still in 
beta, but it plans to do the same for MSWord as ODFWeave does for OpenOffice.

Another alternative along the lines of what you are looking for is the R-Plus 
GUI by Xlsolutions corp.  You can see a short demo here: 
http://www.youtube.com/watch?v=1qsv1MdB4tk


-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of chrish...@psyctc.org
> Sent: Saturday, April 24, 2010 12:34 PM
> To: David Winsemius; r-help@r-project.org
> Cc: r-c...@r-project.org
> Subject: Re: [R] formatted output facilities ... was ..Oddity with
> internet access and R 11.0 - solved
> 
> David Winsemius sent the following  at 24/04/2010 18:24:
> >> Now that I'm here, courtesy of my time slip, what I'd really love to
> see
> >> in R 10.0.0, or even 2.12.0, is the choice to have output either in
> the
> >> current plain text or to some simple formatting primitives that
> would
> >> have default tabs & tables for matrices etc. and allow embedded
> >> graphics.  I'd love to be able to opt to save that as HTML, XML,
> TeX,
> >> RTF, ODF wihthout the complexities of Sweave, ODFWeave, R2HTML etc.
> >>
> >> I know the complexities of Sweave etc. are child's play to
> numerically
> >> and computer gifted people such as yourself Professor, and the R
> core
> >> team, but for those of us who proselytise for R to mere
> psychologists,
> >> doctors, psychotherapists etc., that complexity is hard and the
> hassles
> >> of reformatting text to nice tables etc. discourages people from
> coming
> >> across from SPSS I know.
> >
> > --
> >> require(xtable)
> > Loading required package: xtable
> >> ?xtable
> >
> > --
> > David (a mere doctor).
> 
> Not "mere" to me David.
> 
> Yes, I know xtable and use it a bit, well, quite a lot when I was
> writing R things for cgi use on the web.  I'm sure it's evolved (quick
> check suggests it has and great to see that aov, lm etc. are all
> covered).  However, it really does underline my point: you have to know
> it exists, you have to load it, then what you get on screen is either
> TeX or HTML formatted things and it doesn't embed graphics.  As I
> generally (boo hiss) have to get things to end up in Word documents it
> means I have to save to HTML and import from there.
> 
> I did also work a bit with ODFweave and really liked it but kept
> hitting
> problems and found the extra layer between me and debugging my very bad
> R coding meant that I didn't really make the leap from using ESS & R
> and
> raw output.  Not helped by work restrictions ensuring I couldn't really
> make the leap from Word to Open Office but the main problems were more
> of a feeling of more layers between me and R.  I've got used to ESS and
> love it but that leaves me stuck with these output reformatting
> challenges.
> 
> Xtable is wonderful and surely provides a lot of the functions that I'd
> love to see embedded into the R core.  If we get into my R tardis, and
> go to R 10.0.0, or could it only be R 2.13.0 say, those things would
> support an option to stream R output into lightly formatted form AND
> render and save that.  I'm looking for table handling such as xtable
> provides, tabs and embedding of graphics though if that last didn't
> come
> for years, I'd still be happy to have the text formatting and I'd love
> to be able to chose saving to at least a couple of ODF, RTF, HTML, Tex.
> 
> As well as the code in xtable, I'm sure other resources are in
> ODFweave,
> Sweave that would help this.  I know it's a significant programming
> challenge to do that, particularly in a program that so brilliantly
> embraces so many different platforms.
> 
> One of my guesses is that just allowing addition of tabs into the
> routine R output and encouraging us all to start using them, would be a
> huge step forward.
> 
> Thanks,
> 
> Chris
> 
> P.S. I'm cc'g to r-core as this is really a plea to the core team.
> Sorry if that's a breach of R etiquette.
> 
> --
> Chris Evans  Skype: chris-psyctc
> Consultant Psychiatrist in Psychotherapy, Notts. PDD network;
> Trust Research Governance Lead and Clinical Director, Psychological
>   Therapies Directorate in Local Services, Nottinghamshire NHS Trust;
> Professor, Psychotherapy, Nottingham University
> *If I am writing from one of those roles, it will be clear. Otherwise*
> *my views are my own and not representative of those institutions*
> If you have difficulty Emailing me on this address or getting a reply,
> send again but cc to:   chris dot evans at nottshc dot nhs dot uk
> and to: c dot evans at nottingham dot ac dot uk
> 
> __

[R] lm.ridge {MASS} intercept questions

2010-04-26 Thread Jimmy Purnell
I am trying to understand the code for lm.ridge from the MASS package.
Here is the part I am having trouble understanding:

if(Inter <- attr(Terms, "intercept"))
{
Xm <- colMeans(X[, -Inter])
Ym <- mean(Y)
p <- p - 1
X <- X[, -Inter] - rep(Xm, rep(n, p))
Y <- Y - Ym
} else Ym <- Xm <- NA
Xscale <- drop(rep(1/n, n) %*% X^2)^0.5
X <- X/rep(Xscale, rep.int(n, p))

(the full code is on page 24 here:
http://www.stats.ox.ac.uk/pub/MASS4/VR4ex.pdf )

If there is an intercept term, lm.ridge removes it and centers the
remaining X columns by subtracting each column's mean from all the
values. Then it divides the centered X's by Xscale, which is the
standard deviation (of the population). This all makes sense to me.

What I don't understand is the case where there is no intercept term.
In that case, lm.ridge does not center the X columns, and divides by
an Xscale that is not equal to the standard deviation (because the 'X'
in the Xscale formula is different). What is the reason for this
different approach? I would have thought that the X columns should be
centered and divided by their standard deviations regardless of
whether there was an intercept term.

My other question is about the case where there is an intercept term.
If one uses coef() on the results of lm.ridge, it lists the value of
the intercept along with the value of the (original scale)
coefficients. However, I cannot see any place in the lm.ridge code
where the intercept value is calculated, or how to access it from
within the code (e.g. fit$coef returns the scaled coefficients but no
intercept value, and fit$Inter just returns whether there was an
intercept or not).

Thanks,
Jimmy

__
R-help@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.


Re: [R] reordering of matrix rows to maximize the sum of the diagonal

2010-04-26 Thread Ravi Varadhan
Jonathan,

You can find the permutation of A that maximizes its trace by minimizing
||PA - I|| in Frobenius norm, where P is the permutation matrix, A is a
square matrix, and I is the identity matrix.

Here is the code that solves the abovementioned problem:

pMatrix.min <- function(A, B) {
# finds the permutation P of A such that ||PA - B|| is minimum in Frobenius
norm 
# Uses the linear-sum assignment problem (LSAP) solver in the "clue" package

# Returns P%*%A and the permutation vector `pvec' such that 
# A[pvec, ] is the permutation of A closest to B
n <- nrow(A)
D <- matrix(NA, n, n)
for (i in 1:n) {
for (j in 1:n) {
D[j, i] <- (sum((B[j, ] - A[i, ])^2))
} }
vec <- c(solve_LSAP(D))
list(A=A[vec,], pvec=vec)
}

require(clue)  # need this package to solve the LSAP 

A <- matrix(sample(1:25, size=25, rep=FALSE),  5,  5)

B <- diag(1, nrow(A)) # this choice of B maximizes the trace of permuted A

X <- pMatrix.min(A,B)

A  # original square matrix

X$A  # permuted A such that its trace is maximum among all permutations


Hope this helps,
Ravi.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Jonathan
Sent: Monday, April 26, 2010 2:53 PM
To: Dennis Murphy
Cc: r-help
Subject: Re: [R] reordering of matrix rows to maximize the sum of the
diagonal

Hi Dennis,
   Thanks for the idea, but the order of the rowSums does not
necessarily correspond to the order of rows that maximizes the "rank"
of the matrix.

Ex:
> a[1:9]<-c(1,1,30,50,1,1,1,20,1)

> a
 [,1] [,2] [,3]
[1,]1   501
[2,]11   20
[3,]   3011

> a[order(rowSums(a)),]

 [,1] [,2] [,3]
[1,]11   20
[2,]   3011
[3,]1   501


In this case, I would like to rearrange the original matrix into:

 [,1] [,2] [,3]
[1,]   3011
[2,]1   501
[3,]11   20

Best,
Jonathan

On Sat, Apr 24, 2010 at 1:24 AM, Dennis Murphy  wrote:
> Hi:
>
> How about this? Calling your matrix a,
>
> a[order(rowSums(a)), ]
>  [,1] [,2] [,3]
> [1,]    9    1    2
> [2,]    2   11    1
> [3,]    3    4   13
>
> HTH,
> Dennis
>
>
> On Fri, Apr 23, 2010 at 1:10 PM, Jonathan  wrote:
>>
>> Hi r-help community,
>>    This question isn't so much a syntax/coding one, but here goes:
>>
>> Let's say I have matrix of arbitrary dimensions and I'd like to
>> reorder the rows in such a way that I could maximize the sum of the
>> entries along the diagonal.
>>
>> For example, for this 3x3 matrix:
>>
>>
>>     [,1] [,2] [,3]
>> [1,]    3    4   13
>> [2,]    9    1    2
>> [3,]    2   11    1
>>
>> rearranging the rows to maximize the sum along the diagonal would
>> produce this matrix:
>>
>>     [,1] [,2] [,3]
>> [1,]    9    1    2
>> [2,]    2   11    1
>> [3,]    3    4   13
>>
>>
>> I've been experimenting with some scripts of my own, but I figured I'd
>> ask if one of you R-ninjas might know of an existing function (or
>> algorithm I could look up and then code) that can do this somewhat
>> efficiently (or even just correctly!).
>>
>> Best,
>> Jonathan
>>
>> __
>> R-help@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.
>
>

__
R-help@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.

__
R-help@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.


Re: [R] RServe across network

2010-04-26 Thread Cedrick W. Johnson
Is it [server/rserve] running on Windows or Linux?

-c
On 4/26/2010 2:19 PM, Nupur Gupta wrote:
> Hi,
> I am trying to connect to RServe across a network.
>
> I had put RServe on my local machine and it worked just fine. When am try to
> connect to it across a network - it is able to go through the handshake and
> get in. However , when it gets to the 'request' method in the RTalk class,
> it hangs. Any idea what is happening?
>
> Any inout much appreciated.
>
> Nupur
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] Dropping "trailing zeroes" in longitudinal data

2010-04-26 Thread David Atkins


Background: Our research group collected data from students via the web 
about their drinking habits (alcohol) over the last 90 days.  As you 
might guess, some students seem to have lost interest and completed some 
information but not all.  Unfortunately, the survey was programmed to 
"pre-populate" the fields with zeroes (to make it easier for students to 
complete).


Obviously, when we see a stretch of zeroes, we've no idea whether this 
is "true" data or not, but we'd like to at least do some sensitivity 
analyses by dropping "trailing zeroes" (ie, when there are non-zero 
responses for some duration of the data that then "flat line" into all 
zeroes to the end of the time period)


I've included a toy dataset below.

Basically, we have the data in the "long" format, and what I'd like to 
do is subset the data.frame by deleting rows that occur at the end of a 
person's data that are all zeroes.  In a nutshell, select rows from a 
person that are continuously zero, up to first non-zero, starting at the 
end of their data (which, below, would be time = 10).


With the toy data, this would be the last 6 rows of ids #10 and #8 (for 
example).  I can begin to think about how I might do this via 
grep/regexp but am a bit stumped about how to translate that to this 
type of data.


Any thoughts appreciated.

cheers, Dave

### toy dataset
set.seed(123)
toy.df <- data.frame(id = factor(rep(1:10, each=10)),
time = rep(1:10, 10),
   dv = rnbinom(100, mu = 0.5, size = 
100))
toy.df

library(lattice)

xyplot(dv ~ time | id, data = toy.df, type = c("g","l"))

--
Dave Atkins, PhD
Research Associate Professor
Department of Psychiatry and Behavioral Science
University of Washington
datk...@u.washington.edu

Center for the Study of Health and Risk Behaviors (CSHRB)   
1100 NE 45th Street, Suite 300  
Seattle, WA  98105  
206-616-3879
http://depts.washington.edu/cshrb/
(Mon-Wed)   

Center for Healthcare Improvement, for Addictions, Mental Illness,
  Medically Vulnerable Populations (CHAMMP)
325 9th Avenue, 2HH-15
Box 359911
Seattle, WA 98104?
206-897-4210
http://www.chammp.org
(Thurs)

__
R-help@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.


[R] change the size of matrix

2010-04-26 Thread anderson nuel
Dear r-help,

Could you help me to find the function which change the size of matrix .


Best Regards

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] How do you change library location ? (in R under windows XP)

2010-04-26 Thread Tal Galili
Thank you Mike,
That is indeed what I used in the code eventually.
http://www.r-statistics.com/2010/04/changing-your-r-upgrading-strategy-and-the-r-code-to-do-it-on-windows/

Thanks for answering,
Tal

Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Mon, Apr 26, 2010 at 9:31 PM, Mike Prager  wrote:

> On Fri, 23 Apr 2010 15:22:45 +0300, Tal Galili 
> wrote:
>
> >Due to the new R 2.11 release, I want to implement Dirk's suggestion
> >here<
> http://stackoverflow.com/questions/1401904/painless-way-to-install-a-new-version-of-r
> >
> >.
> >
> >So for that I am asking - How can I (permanently) change R's library path?
> >(The best solution would be one that can be run from within R)
>
> To me, it seemed more straightforward to do this outside R.
>
> Just set the environment variable R_LIBS in Windows to something like
>
> R_LIBS=c:/R/Library
>
> Then, delete your R installation. Install the new version and all
> desired packages.  The add-on packages will be located according to
> your environment setting, and future updates will not require add-on
> packages to be copied or reloaded.
>
> HTH
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] R.GBM package

2010-04-26 Thread Changbin Du
Got it, thanks so much! Greg.


On Mon, Apr 26, 2010 at 11:02 AM, Ridgeway, Greg  wrote:

>  Y~X1+X2+X3 is the standard R formula syntax. It simply means "Y is
> predicted by X1 and X2 and X3".
>
> Greg
>
>  --
> *From:* Changbin Du [mailto:changb...@gmail.com]
> *Sent:* Monday, April 26, 2010 10:21 AM
> *To:* Ridgeway, Greg
> *Cc:* r-help@r-project.org
> *Subject:* Re: R.GBM package
>
> Thanks so much, Greg!
>
> On the demo(bernoulli), I FOUND  the following information: IT is used for
> logistic regression.
>
>
> My question is: when I define a decision tree, can I still use the formula
> Y~X1+X2+X3,# formula, even though I dont know the detailed
> formula of decision tree.
>
> Thanks!
>
>
>
>
>
> demo(bernoulli)
>  ~
>
> Type   to start :
>
> > # LOGISTIC REGRESSION EXAMPLE
> >
> > cat("Running logistic regression example.\n")
> Running logistic regression example.
>
> > # create some data
> > N <- 1000
>
> > X1 <- runif(N)
>
> > X2 <- runif(N)
>
> > X3 <- factor(sample(letters[1:4],N,replace=T))
>
> > mu <- c(-1,0,1,2)[as.numeric(X3)]
>
> > p <- 1/(1+exp(-(sin(3*X1) - 4*X2 + mu)))
>
> > Y <- rbinom(N,1,p)
>
> > # random weights if you want to experiment with them
> > w <- rexp(N)
>
> > w <- N*w/sum(w)
>
> > data <- data.frame(Y=Y,X1=X1,X2=X2,X3=X3)
>
> > # fit initial model
> > gbm1 <- gbm(Y~X1+X2+X3,# formula
> + data=data, # dataset
> + weights=w,
> + var.monotone=c(0,0,0), # -1: monotone decrease, +1:
> monotone increase, 0: no monotone restrictions
> + distribution="bernoulli",
> + n.trees=3000,  # number of trees
> + shrinkage=0.001,   # shrinkage or learning rate,
> 0.001 to 0.1 usually work
> + interaction.depth=3,   # 1: additive model, 2: two-way
> interactions, etc
> + bag.fraction = 0.5,# subsampling fraction, 0.5 is
> probably best
> + train.fraction = 0.5,  # fraction of data for training,
> first train.fraction*N used for training
> + cv.folds=5,# do 5-fold cross-validation
> + n.minobsinnode = 10)   # minimum total weight needed in
> each node
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Mon, Apr 26, 2010 at 9:50 AM, Ridgeway, Greg  wrote:
>
>>  GBM implements boosted trees. It works for 0/1 outcomes, count outcomes,
>> continuous outcomes and a few others. You do not need to combine rpart and
>> gbm. You're best bet is to just load the package and run a demo
>> >demo(bernoulli).
>>
>>  --
>> *From:* Changbin Du [mailto:changb...@gmail.com]
>> *Sent:* Monday, April 26, 2010 9:48 AM
>> *To:* r-help@r-project.org
>> *Cc:* Ridgeway, Greg
>> *Subject:* R.GBM package
>>
>>   HI, Dear Greg,
>>
>> I AM A NEW to GBM package. Can boosting decision tree be implemented in
>> 'gbm' package?   Or 'gbm' can only be used for regression?
>>
>> IF can, DO I need to combine the rpart and gbm command?
>>
>> Thanks so much!
>>
>>
>>
>> --
>> Sincerely,
>> Changbin
>> --
>>
>>
>>
>> __
>>
>> This email message is for the sole use of the intended recipient(s) and
>> may contain confidential information. Any unauthorized review, use,
>> disclosure or distribution is prohibited. If you are not the intended
>> recipient, please contact the sender by reply email and destroy all copies
>> of the original message.
>>
>>
>
>
> --
> Sincerely,
> Changbin
> --
>
> Changbin Du
> DOE Joint Genome Institute
> Bldg 400 Rm 457
> 2800 Mitchell Dr
> Walnut Creet, CA 94598
> Phone: 925-927-2856
>
>
> __
>
> This email message is for the sole use of the intended...{{dropped:24}}

__
R-help@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.


Re: [R] Upgrading R using the "global library folder" strategy - what do you think about it?

2010-04-26 Thread Mike Prager
I think it makes more sense for most users to have a global library
(as you call it), rather than put the library under the current
installation.  I have been doing that for years, and it saves a lot of
trouble.

When I have helped people learn R, the need to copy the library when
updating is a regular source of confusion and questions. Many users
are not particularly computer-savvy.

Given that, it would seem desirable for the R installation to default
to a global library location.

__
R-help@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.


Re: [R] reordering of matrix rows to maximize the sum of the diagonal

2010-04-26 Thread Jonathan
Hi Dennis,
   Thanks for the idea, but the order of the rowSums does not
necessarily correspond to the order of rows that maximizes the "rank"
of the matrix.

Ex:
> a[1:9]<-c(1,1,30,50,1,1,1,20,1)

> a
 [,1] [,2] [,3]
[1,]1   501
[2,]11   20
[3,]   3011

> a[order(rowSums(a)),]

 [,1] [,2] [,3]
[1,]11   20
[2,]   3011
[3,]1   501


In this case, I would like to rearrange the original matrix into:

 [,1] [,2] [,3]
[1,]   3011
[2,]1   501
[3,]11   20

Best,
Jonathan

On Sat, Apr 24, 2010 at 1:24 AM, Dennis Murphy  wrote:
> Hi:
>
> How about this? Calling your matrix a,
>
> a[order(rowSums(a)), ]
>  [,1] [,2] [,3]
> [1,]    9    1    2
> [2,]    2   11    1
> [3,]    3    4   13
>
> HTH,
> Dennis
>
>
> On Fri, Apr 23, 2010 at 1:10 PM, Jonathan  wrote:
>>
>> Hi r-help community,
>>    This question isn't so much a syntax/coding one, but here goes:
>>
>> Let's say I have matrix of arbitrary dimensions and I'd like to
>> reorder the rows in such a way that I could maximize the sum of the
>> entries along the diagonal.
>>
>> For example, for this 3x3 matrix:
>>
>>
>>     [,1] [,2] [,3]
>> [1,]    3    4   13
>> [2,]    9    1    2
>> [3,]    2   11    1
>>
>> rearranging the rows to maximize the sum along the diagonal would
>> produce this matrix:
>>
>>     [,1] [,2] [,3]
>> [1,]    9    1    2
>> [2,]    2   11    1
>> [3,]    3    4   13
>>
>>
>> I've been experimenting with some scripts of my own, but I figured I'd
>> ask if one of you R-ninjas might know of an existing function (or
>> algorithm I could look up and then code) that can do this somewhat
>> efficiently (or even just correctly!).
>>
>> Best,
>> Jonathan
>>
>> __
>> R-help@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.
>
>

__
R-help@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.


Re: [R] R and S-Plus: Two programs separated by a common language?

2010-04-26 Thread Mike Prager
On Thu, 22 Apr 2010 12:00:13 -0700 (PDT), Paul Miller
 wrote:

>I was just wondering if anyone could give me some advice about the wisdom or 
>folly of trying to use both [R and S-Plus].

I suspect that trying to use both will give you heartburn. When I
switched from S-Plus to R, the most significant differences (for my
purposes) were in graphics. The languages differ in the way they
approach graphics, and even where the languages appear the same,
interpretation of some parameters (such as cex) can be different. 

Also, the way data are stored differs considerably. Because S-Plus
stores data on disk, while R keeps data in memory, S-Plus can have an
edge when analyzing huge data sets. (That reflects my understanding of
the situation about 5 or 6 yr ago.) 

I have gone back to old projects and tried to execute my S-Plus code
in R. In general, the code needed minor to major massaging to make
that happen, especially when the output was carefully annotated
graphs.

I would recommend that you concentrate on R, where much active
development is taking place.  Support from this newsgroup is better
than support from most commercial vendors, though perhaps not always
as sweet-natured.  As noted by others, Revolution R is available with
commercial support, if you need it.

__
R-help@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.


Re: [R] How do you change library location ? (in R under windows XP)

2010-04-26 Thread Mike Prager
On Fri, 23 Apr 2010 15:22:45 +0300, Tal Galili 
wrote:

>Due to the new R 2.11 release, I want to implement Dirk's suggestion
>here
>.
>
>So for that I am asking - How can I (permanently) change R's library path?
>(The best solution would be one that can be run from within R)

To me, it seemed more straightforward to do this outside R.  

Just set the environment variable R_LIBS in Windows to something like

R_LIBS=c:/R/Library

Then, delete your R installation. Install the new version and all
desired packages.  The add-on packages will be located according to
your environment setting, and future updates will not require add-on
packages to be copied or reloaded.

HTH

__
R-help@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.


Re: [R] Why am I getting different results from cor VS ccf ?

2010-04-26 Thread Tal Galili
The dear mark leeds 
Has pointed me that the answer to my question was in the MASS book, in page
390
Where it is said that acf works by dividing the covariance with N instead of
N-t
so to insure that the covariance sequence is positive definite.

Although I am not sure if to my purposes it means I should use the one over
the other.

Thanks again to Mark,

Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Mon, Apr 26, 2010 at 8:49 PM, Tal Galili  wrote:

> Hi all,
>
> I am getting different results from ccf and cor,
> Here is a simple example:
>
> set.seed(100)
> N <- 100
> x1 <- sample(N)
> x2 <- x1 + rnorm(N,0,5)
> ccf(x1,x2)$acf[ccf(x1,x2)$lag == -1]
> cor(x1[-N], x2[-1])
>
>
> Results:
>
> > ccf(x1,x2)$acf[ccf(x1,x2)$lag == -1]
> [1] -0.128027
> > cor(x1[-N], x2[-1])
> [1] -0.1301427
>
>
> Thanks,
> Tal
>
>
>
>
> Contact
> Details:---
> Contact me: tal.gal...@gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>
> --
>
>
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] RServe across network

2010-04-26 Thread Nupur Gupta
Hi,
I am trying to connect to RServe across a network.

I had put RServe on my local machine and it worked just fine. When am try to
connect to it across a network - it is able to go through the handshake and
get in. However , when it gets to the 'request' method in the RTalk class,
it hangs. Any idea what is happening?

Any inout much appreciated.

Nupur

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] help with code

2010-04-26 Thread Sarah Goslee
Hi Randy,

> The SAS code for what I want to do is:
> /*
>
>  if FTIStandKey=" NAH6253-003" then do;
>
>   CoverType=" XSOP--C ";
>
>   V_SpGrp="T";
>
>   V_Origin="T";
>
>  end;
>

I admit I didn't read all the sample code you added, but this is what
I *think* you're trying to accomplish.

mydataframe[mydataframe$FTIStandKey == "NAH6253-003", "CoverType"] <-
"XSOP--C"

etc.

> # create a toy dataframe
> mydataframe <- data.frame(A = c("var1", "var2", "var3", "var3"), B = c(10, 
> 11, 12, 13), C = c("y1", "y3", "y8", "y3"), stringsAsFactors = FALSE)
> mydataframe
 A  B  C
1 var1 10 y1
2 var2 11 y3
3 var3 12 y8
4 var3 13 y3
>
> # where A is "var3", add 10 to the value in the B column
> mydataframe[mydataframe$A == "var3", "B"] <- mydataframe[mydataframe$A == 
> "var3", "B"] + 10
> mydataframe
 A  B  C
1 var1 10 y1
2 var2 11 y3
3 var3 22 y8
4 var3 23 y3
>
> # where A is "var2", change the value in column C to "other"
> mydataframe[mydataframe$A == "var2", "C"] <- "other"
> mydataframe
 A  B C
1 var1 10y1
2 var2 11 other
3 var3 22y8
4 var3 23y3


There are other ways to do the same thing, of course. I find this one
easy to remember. You might want to read some documentation on
subsetting.

Please don't repost your question right away. Most of us are busy and will
answer as soon as we can.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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.


Re: [R] Help with replacement of certain values in dataset with SAS code equivalent

2010-04-26 Thread Erik Iverson



What I want to do is to be able to select certain FTIStandKey's and change
values in the dataset.  For example, I would like to select by
FTIStandKey=="NAH6253-003", and change the entries for CoverType="
XSOP--C " and change the V_SpGrp=="T", and also change V_Origin=="T".  I
only want to change the record for the one FTIStandKey.  All the other
records need to remain the exact same.  I have spent a good bit of time
trying to figure this out but with no success.   Any help would be greatly
appreciated.


Do not know if the following will work, and it is not tested since you 
don't give a reproducible example, see ?dput and the Posting Guide for 
this list. There are several ways of doing what you want, some of which 
are  possibly more transparent than this:


mydata[mydata$FTIStandKey == "NAH6253-003",
   c("CoverType", "V_SpGrp", "V_Origin")] <-
   list(" XSOP--C ", "T", "T")


This relies on the fact that if your variables are factors, that they 
include the replacement levels already (including the fact that you have 
spaces on either side of the string for CoverType... You might also see 
?ifelse for another method of dealing with stuff like this.


__
R-help@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.


Re: [R] Sweave

2010-04-26 Thread Jimmy Söderly
Thanks !!!

2010/4/26 Gabor Grothendieck 

> Sorry, typo. Try this:
>
> file.path(R.home(), "share", "texmf", "Sweave.sty")
>
> On Mon, Apr 26, 2010 at 1:18 PM, Gabor Grothendieck
>  wrote:
> > Its at this path (this command is issued from within R):
> >
> >   file.path(R.home(), "share", "textmf", "Sweave.sty")
> >
> > You can add it to your MiKTeX installation or just put it in the same
> > directory as your Rnw file.
> >
> >
> > On Mon, Apr 26, 2010 at 1:10 PM, Jimmy Söderly 
> wrote:
> >> Hi everybody,
> >>
> >> I wanted to use Sweave but I do not have the Latex package:
> >>
> >> "LaTeX Error: File  'Sweave.sty' not found."
> >>
> >> I cannot find it with MiKTeX :-(
> >>
> >> Can somebody help me ?
> >>
> >> Thanks a lot,
> >> Jimmy
> >>
> >>[[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@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.
> >>
> >
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] Why am I getting different results from cor VS ccf ?

2010-04-26 Thread Tal Galili
Hi all,

I am getting different results from ccf and cor,
Here is a simple example:

set.seed(100)
N <- 100
x1 <- sample(N)
x2 <- x1 + rnorm(N,0,5)
ccf(x1,x2)$acf[ccf(x1,x2)$lag == -1]
cor(x1[-N], x2[-1])


Results:

> ccf(x1,x2)$acf[ccf(x1,x2)$lag == -1]
[1] -0.128027
> cor(x1[-N], x2[-1])
[1] -0.1301427


Thanks,
Tal




Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] problems accessing MS Access 2003 database with RODBC

2010-04-26 Thread Marc Schwartz
On Apr 26, 2010, at 12:40 PM, Marc Schwartz wrote:

> On Apr 26, 2010, at 12:11 PM, boris.vasil...@forces.gc.ca wrote:
> 
>> Dear users,
>> 
>> I am trying to access a Microsoft Access database from R using RODBC
>> package 
>> but I have had little success.  The setup works with isql, RODBC seems
>> to 
>> connect to the database, but RODBC does not recognize the data in the
>> database.  Can anybody advise where I am going wrong?
>> 
>> I am using R version 2.10.1 on Ubuntu 8.04. ODBC version is 2.2.11.
>> Mdbtools 
>> version is 0.6pre1. RODBC version is 1.3.1.  Test database  with one
>> table
>> was created in MS Access 2003.
>> 
>> The ODBC configuration files are
>> 
>> /etc/odbcinst.ini:
>> [Microsoft Access Driver (*.mdb)]
>> Description = MDB Tools ODBC drivers
>> Driver = /usr/lib/libmdbodbc.so.0
>> Setup =
>> FileUsage = 1
>> CPTimeout = 
>> CRReuse =
>> 
>> /home/vasiliev/.odbc.ini:
>> [test_db]
>> Description = test events database
>> Driver = Microsoft Access Driver (*.mdb)
>> Database = /home/vasiliev/siginci/data/test_db.mdb
>> Trace = Yes
>> TraceFile = /home/vasiliev/odbc.log
>> 
>> When I test the set-up with isql it seems to work:
>> 
>> isql -v -m10 test_db
>> +---+
>> | Connected!|
>> |   |
>> | sql-statement |
>> | help [tablename]  |
>> | quit  |
>> |   |
>> +---+
>> SQL> help
>> +---+---+---+---+---+
>> | TABLE_CAT | TABLE_SCHE| TABLE_NAME| TABLE_TYPE| REMARKS   |
>> +---+---+---+---+---+
>> |   |   | MSysObject| SYSTEM TAB|   |
>> |   |   | MSysACEs  | SYSTEM TAB|   |
>> |   |   | MSysQuerie| SYSTEM TAB|   |
>> |   |   | MSysRelati| SYSTEM TAB|   |
>> |   |   | MSysAccess| SYSTEM TAB|   |
>> |   |   | tblA1 | TABLE |   |
>> |   |   | MSysAccess| SYSTEM TAB|   |
>> +---+---+---+---+---+
>> SQLRowCount returns 7
>> 7 rows fetched
>> SQL> help tblA1
>> +---+---+---+---+--+---+
>> ---+
>> | TABLE_CAT | TABLE_SCHE| TABLE_NAME| COLUMN_NAM| DATA_TYPE| TYPE_NAME |
>> COLUMN_SIZ|
>> +---+---+---+---+--+---+
>> ---+
>> |   |   | tblA1 | ID| 4| FIX ME|
>> |
>> |   |   | tblA1 | Row   | 5| FIX ME|
>> |
>> |   |   | tblA1 | Value | 4| FIX ME|
>> |
>> +---+---+---+---+--+---+
>> ---+
>> SQLRowCount returns 3
>> 3 rows fetched
>> SQL> select * from tblA1
>> +---+---+---+
>> | ID| Row   | Value |
>> +---+---+---+
>> | 1 | 1 | 2 |
>> | 2 | 10| 10|
>> | 3 | 30| 30|
>> | 4 | 40| 40|
>> +---+---+---+
>> SQLRowCount returns 4
>> 4 rows fetched
>> 
>> However, when the connection is opened in R, it appears to be empty.
>> DBMS details
>> are not recognized; table and data are unavailable:
>> 
>>> ch <- odbcConnect("test_db")
>>> odbcGetInfo(ch)
>>  DBMS_Name DBMS_Ver  Driver_ODBC_Ver Data_Source_Name 
>> ""   ""   """test_db" 
>>Driver_Name   Driver_Ver ODBC_Ver  Server_Name 
>>  "test_db""test_db"  "03.52"  "03.52" 
>>> sqlTables(ch)
>> [1] TABLE_CAT   TABLE_SCHEM TABLE_NAME  TABLE_TYPE  REMARKS
>> <0 rows> (or 0-length row.names)
>> 
>> Does anybody know what I am doing incorrectly? 
>> Sincerely,
>> Boris.
> 
> 
> As far as I know, the use of mdb-tools for Access via RODBC on Linux is not 
> supported. A search of the archives reveals this post from Prof. Ripley from 
> 2004:
> 
>  http://tolstoy.newcastle.edu.au/R/help/04/11/6585.html
> 
> I am presuming that this is still the case, though I am cc:ing Prof. Ripley 
> for confirmation.
> 
> In that same thread, there is a post from David Whiting that you might find 
> helpful as an alternative, presuming that the information is still of value 6 
> years hence.


FYI, I found another possible option which is the mdb.get() function in Frank 
Harrell's Hmisc package on CRAN.

Note that at the moment, some of the CRAN network is down:

  https://stat.ethz.ch/pipermail/r-help/2010-April/236583.html

HTH,

Marc

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.or

Re: [R] Sweave: centering with echo=TRUE

2010-04-26 Thread Duncan Murdoch

On 26/04/2010 7:07 AM, David.Epstein wrote:

In a .Rnw file I want to insert the R command
pairs(mydataframe)
and achieve the following effects

1. the command itseld is echoed into the tex document generated by Sweave
<>=
2. The graphics generated appears in the tex document, with the graphics
centred.
3. The R command > pairs(mydataframe) is not centered.
  

That is what I see when I do this:

\begin{center}
<>=
mydataframe <- data.frame(a=1:10,
 b=rnorm(10),
 c=rnorm(10))
pairs(mydataframe)
@
\end{center}*

*Are you seeing the echoed source being centred?

Duncan Murdoch


Sweave-manual.pdf gives the following code chunk

<>= 
for(i in 1:4){ 
file=paste("myfile", i, ".eps", sep="") 
postscript(file=file, paper="special", width=6, height=6) 
plot(rnorm(100)+i) 
dev.off() 
cat("\\includegraphics{", file, "}\n\n", sep="") 
} 
@ 


This could obviously be adapted to my centering problem, but is it the
simplest way? It seems complicated compared with just pairs(mydataframe).
Also, Sweave will normally make both postscript and pdf plots, but this
would involve further complication in the code. I'm sure it's completely
standard to produce two copies of graphics, one a pdf and one an eps, but
it's another obstacle in my way when I want to get on with writing the
program and its latex description.

Thanks
David



__
R-help@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.


Re: [R] R.GBM package

2010-04-26 Thread Ridgeway, Greg
GBM implements boosted trees. It works for 0/1 outcomes, count outcomes,
continuous outcomes and a few others. You do not need to combine rpart
and gbm. You're best bet is to just load the package and run a demo
>demo(bernoulli).



From: Changbin Du [mailto:changb...@gmail.com] 
Sent: Monday, April 26, 2010 9:48 AM
To: r-help@r-project.org
Cc: Ridgeway, Greg
Subject: R.GBM package


HI, Dear Greg,

I AM A NEW to GBM package. Can boosting decision tree be implemented in
'gbm' package?   Or 'gbm' can only be used for regression?

IF can, DO I need to combine the rpart and gbm command?

Thanks so much!



-- 
Sincerely,
Changbin 
--





__

This email message is for the sole use of the intended r...{{dropped:9}}

__
R-help@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.


Re: [R] data frame

2010-04-26 Thread jim holtman
Is this what you want:

> x <- read.table(textConnection("variable
YEAR  VAR
+ EC01  2006 100
+
+ EC01  2007  200
+
+ EC02   2006 500
+
+ EC02   2007  450
+
+ PROD   2006  567
+
+ PROD   2007  543"),
header=TRUE, as.is=TRUE)
> closeAllConnections()
> # split by year and then determine if there is a PROD in the year
> result <- do.call(rbind, lapply(split(x, x$YEAR), function(.year){
+ prod.indx <- which(.year$variable == "PROD")
+ if (length(prod.indx) != 1){
+ cat('missing or incorrect number of PRODs for:', .year$YEAR[1L],
'\n')
+ return(NULL)
+ }
+ prod.value <- .year$VAR[prod.indx]
+ # remove PROD from result
+ .year <- .year[-prod.indx,,drop=FALSE]
+ .year$VAR <- .year$VAR / prod.value
+ .year  # return updated results
+ }))
> result
   variable YEAR   VAR
2006.1 EC01 2006 0.1763668
2006.3 EC02 2006 0.8818342
2007.2 EC01 2007 0.3683241
2007.4 EC02 2007 0.8287293
>


On Mon, Apr 26, 2010 at 11:07 AM, n.via...@libero.it wrote:

>
> Dear list,
> I have a big data frame which looks like this:
> variable YEAR  VAR
> EC01  2006 100
>
> EC01  2007  200
>
> EC02   2006 500
>
> EC02   2007  450
>
> PROD   2006  567
>
> PROD   2007  543
>
> What I would like to do is to divide each variables by PROD,namely:
> EC01(2006)/PROD(2006)
> EC01(2007)/PROD(2007)
> EC02(2006)/PROD(2006)
> EC02(2007)/PROD(2007)
> Anyone knows how to do it??
> THANKS!!!
>
>[[alternative HTML version deleted]]
>
> __
> R-help@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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] problems accessing MS Access 2003 database with RODBC

2010-04-26 Thread Marc Schwartz
On Apr 26, 2010, at 12:11 PM, boris.vasil...@forces.gc.ca wrote:

> Dear users,
> 
> I am trying to access a Microsoft Access database from R using RODBC
> package 
> but I have had little success.  The setup works with isql, RODBC seems
> to 
> connect to the database, but RODBC does not recognize the data in the
> database.  Can anybody advise where I am going wrong?
> 
> I am using R version 2.10.1 on Ubuntu 8.04. ODBC version is 2.2.11.
> Mdbtools 
> version is 0.6pre1. RODBC version is 1.3.1.  Test database  with one
> table
> was created in MS Access 2003.
> 
> The ODBC configuration files are
> 
> /etc/odbcinst.ini:
> [Microsoft Access Driver (*.mdb)]
> Description = MDB Tools ODBC drivers
> Driver = /usr/lib/libmdbodbc.so.0
> Setup =
> FileUsage = 1
> CPTimeout = 
> CRReuse =
> 
> /home/vasiliev/.odbc.ini:
> [test_db]
> Description = test events database
> Driver = Microsoft Access Driver (*.mdb)
> Database = /home/vasiliev/siginci/data/test_db.mdb
> Trace = Yes
> TraceFile = /home/vasiliev/odbc.log
> 
> When I test the set-up with isql it seems to work:
> 
> isql -v -m10 test_db
> +---+
> | Connected!|
> |   |
> | sql-statement |
> | help [tablename]  |
> | quit  |
> |   |
> +---+
> SQL> help
> +---+---+---+---+---+
> | TABLE_CAT | TABLE_SCHE| TABLE_NAME| TABLE_TYPE| REMARKS   |
> +---+---+---+---+---+
> |   |   | MSysObject| SYSTEM TAB|   |
> |   |   | MSysACEs  | SYSTEM TAB|   |
> |   |   | MSysQuerie| SYSTEM TAB|   |
> |   |   | MSysRelati| SYSTEM TAB|   |
> |   |   | MSysAccess| SYSTEM TAB|   |
> |   |   | tblA1 | TABLE |   |
> |   |   | MSysAccess| SYSTEM TAB|   |
> +---+---+---+---+---+
> SQLRowCount returns 7
> 7 rows fetched
> SQL> help tblA1
> +---+---+---+---+--+---+
> ---+
> | TABLE_CAT | TABLE_SCHE| TABLE_NAME| COLUMN_NAM| DATA_TYPE| TYPE_NAME |
> COLUMN_SIZ|
> +---+---+---+---+--+---+
> ---+
> |   |   | tblA1 | ID| 4| FIX ME|
> |
> |   |   | tblA1 | Row   | 5| FIX ME|
> |
> |   |   | tblA1 | Value | 4| FIX ME|
> |
> +---+---+---+---+--+---+
> ---+
> SQLRowCount returns 3
> 3 rows fetched
> SQL> select * from tblA1
> +---+---+---+
> | ID| Row   | Value |
> +---+---+---+
> | 1 | 1 | 2 |
> | 2 | 10| 10|
> | 3 | 30| 30|
> | 4 | 40| 40|
> +---+---+---+
> SQLRowCount returns 4
> 4 rows fetched
> 
> However, when the connection is opened in R, it appears to be empty.
> DBMS details
> are not recognized; table and data are unavailable:
> 
>> ch <- odbcConnect("test_db")
>> odbcGetInfo(ch)
>   DBMS_Name DBMS_Ver  Driver_ODBC_Ver Data_Source_Name 
>  ""   ""   """test_db" 
> Driver_Name   Driver_Ver ODBC_Ver  Server_Name 
>   "test_db""test_db"  "03.52"  "03.52" 
>> sqlTables(ch)
> [1] TABLE_CAT   TABLE_SCHEM TABLE_NAME  TABLE_TYPE  REMARKS
> <0 rows> (or 0-length row.names)
> 
> Does anybody know what I am doing incorrectly? 
> Sincerely,
> Boris.


As far as I know, the use of mdb-tools for Access via RODBC on Linux is not 
supported. A search of the archives reveals this post from Prof. Ripley from 
2004:

  http://tolstoy.newcastle.edu.au/R/help/04/11/6585.html

I am presuming that this is still the case, though I am cc:ing Prof. Ripley for 
confirmation.

In that same thread, there is a post from David Whiting that you might find 
helpful as an alternative, presuming that the information is still of value 6 
years hence.

HTH,

Marc Schwartz

__
R-help@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.


Re: [R] data frame

2010-04-26 Thread Tal Galili
you can do this:

a <- tapply(VAR, YEAR, prod)

The use "merge" to create a new variable of the length of your original VAR,
and just do
VAR/prod.VAR




Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Mon, Apr 26, 2010 at 6:07 PM, n.via...@libero.it wrote:

> PROD

[[alternative HTML version deleted]]

__
R-help@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.


[R] help with code

2010-04-26 Thread Randy Cass
I am new to R and have tried for a good while to figure out how to code this
in R.  The dataset below:

 


FTIStandKey

State

County

FTITract

CoverType

Ver_CT

V_Origin

V_SpGrp




NAH6005-001

Texas

Jasper

NAH6005

PPLB-2000-U

PPLB-2000-U

P

P




NAH6005-002

Texas

Jasper

NAH6005

NHHX-1950-O

NHHX-1950-I

N

H




NAH6253-001

Texas

Tyler

NAH6253

PPLB-2001-U

PPLB-2001-U

P

P




NAH6253-002

Texas

Tyler

NAH6253

PPLB-1993-U

PPLB-1993-U

P

P




NAH6253-003

Texas

Tyler

NAH6253

PPLB-2003-U

PPLB-2003-U

P

P




NAH6253-005

Texas

Tyler

NAH6253

XSOP--C

XSOP--C

X

S




NAH6253-008

Texas

Tyler

NAH6253

NPLB-1975-O

NPLB-1975-O

N

P




 

The SAS code for what I want to do is:

 

/*

 if FTIStandKey=" NAH6253-003" then do;

   CoverType=" XSOP--C ";

   V_SpGrp="T";

   V_Origin="T";

 end;

 

What I want to do is to be able to select certain FTIStandKey's and change
values in the dataset.  For example, I would like to select by
FTIStandKey=="NAH6253-003", and change the entries for CoverType="
XSOP--C " and change the V_SpGrp=="T", and also change V_Origin=="T".  I
only want to change the record for the one FTIStandKey.  All the other
records need to remain the exact same.  I have spent a good bit of time
trying to figure this out but with no success.   Any help would be greatly
appreciated.

 

The only thing I could find even close to what I wanted to do is listed
below:

 

# R Program for Multiple Conditional Transformations.

# Read the file into a data frame and print it.

load(file="c:\\mydata.Rdata")

print(mydata)

 

# Use column bind to add two new columns to mydata.

# Not necessary for this example, but handy to know.

 

mydata <- cbind(mydata, score1 = 0, score2 = 0)

 

attach(mydata)

mydata$guys <- gender=="m" #Creates a logical vector for males.

mydata$gals <- gender=="f" #Creates another for females.

print(mydata)

 

# Applies basic math to the group selected by the logic.

 

mydata$score1[gals]<- 2*q1[gals] + q2[gals]

mydata$score2[gals]<- 3*q1[gals] + q2[gals]

mydata$score1[guys]<-20*q1[guys] + q2[guys]

mydata$score2[guys]<-30*q1[guys] + q2[guys]

print(mydata)

 

# This step uses NULL to delete the guys & gals vars.

mydata$gals <- mydata$guys <- NULL

print(mydata)

 

Thanks,

 

Randy Cass

 


[[alternative HTML version deleted]]

__
R-help@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.


[R] mvpart : Printing response values at terminal nodes

2010-04-26 Thread S, Manjunath (GE, Research)
 
I have created a multivariate regression tree using mvpart, with 3-4
responses.  Though the plot shows bargraphs for each response, I would
like to have the VALUES of the responses
printed or indicated (via a scale or something) alongside the bargraph.
 
Is this possible ??
 
Thanks,
Manjunath
 
 

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Sweave

2010-04-26 Thread Gabor Grothendieck
Sorry, typo. Try this:

file.path(R.home(), "share", "texmf", "Sweave.sty")

On Mon, Apr 26, 2010 at 1:18 PM, Gabor Grothendieck
 wrote:
> Its at this path (this command is issued from within R):
>
>   file.path(R.home(), "share", "textmf", "Sweave.sty")
>
> You can add it to your MiKTeX installation or just put it in the same
> directory as your Rnw file.
>
>
> On Mon, Apr 26, 2010 at 1:10 PM, Jimmy Söderly  
> wrote:
>> Hi everybody,
>>
>> I wanted to use Sweave but I do not have the Latex package:
>>
>> "LaTeX Error: File  'Sweave.sty' not found."
>>
>> I cannot find it with MiKTeX :-(
>>
>> Can somebody help me ?
>>
>> Thanks a lot,
>> Jimmy
>>
>>        [[alternative HTML version deleted]]
>>
>> __
>> R-help@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.
>>
>

__
R-help@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.


Re: [R] R.GBM package

2010-04-26 Thread Changbin Du
Thanks so much, Greg!

On the demo(bernoulli), I FOUND  the following information: IT is used for
logistic regression.


My question is: when I define a decision tree, can I still use the formula
Y~X1+X2+X3,# formula, even though I dont know the detailed
formula of decision tree.

Thanks!





demo(bernoulli)
 ~

Type   to start :

> # LOGISTIC REGRESSION EXAMPLE
>
> cat("Running logistic regression example.\n")
Running logistic regression example.

> # create some data
> N <- 1000

> X1 <- runif(N)

> X2 <- runif(N)

> X3 <- factor(sample(letters[1:4],N,replace=T))

> mu <- c(-1,0,1,2)[as.numeric(X3)]

> p <- 1/(1+exp(-(sin(3*X1) - 4*X2 + mu)))

> Y <- rbinom(N,1,p)

> # random weights if you want to experiment with them
> w <- rexp(N)

> w <- N*w/sum(w)

> data <- data.frame(Y=Y,X1=X1,X2=X2,X3=X3)

> # fit initial model
> gbm1 <- gbm(Y~X1+X2+X3,# formula
+ data=data, # dataset
+ weights=w,
+ var.monotone=c(0,0,0), # -1: monotone decrease, +1:
monotone increase, 0: no monotone restrictions
+ distribution="bernoulli",
+ n.trees=3000,  # number of trees
+ shrinkage=0.001,   # shrinkage or learning rate, 0.001
to 0.1 usually work
+ interaction.depth=3,   # 1: additive model, 2: two-way
interactions, etc
+ bag.fraction = 0.5,# subsampling fraction, 0.5 is
probably best
+ train.fraction = 0.5,  # fraction of data for training,
first train.fraction*N used for training
+ cv.folds=5,# do 5-fold cross-validation
+ n.minobsinnode = 10)   # minimum total weight needed in
each node















On Mon, Apr 26, 2010 at 9:50 AM, Ridgeway, Greg  wrote:

>  GBM implements boosted trees. It works for 0/1 outcomes, count outcomes,
> continuous outcomes and a few others. You do not need to combine rpart and
> gbm. You're best bet is to just load the package and run a demo
> >demo(bernoulli).
>
>  --
> *From:* Changbin Du [mailto:changb...@gmail.com]
> *Sent:* Monday, April 26, 2010 9:48 AM
> *To:* r-help@r-project.org
> *Cc:* Ridgeway, Greg
> *Subject:* R.GBM package
>
> HI, Dear Greg,
>
> I AM A NEW to GBM package. Can boosting decision tree be implemented in
> 'gbm' package?   Or 'gbm' can only be used for regression?
>
> IF can, DO I need to combine the rpart and gbm command?
>
> Thanks so much!
>
>
>
> --
> Sincerely,
> Changbin
> --
>
>
>
> __
>
> This email message is for the sole use of the intended...{{dropped:24}}

__
R-help@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.


Re: [R] Sweave

2010-04-26 Thread Gabor Grothendieck
Its at this path (this command is issued from within R):

   file.path(R.home(), "share", "textmf", "Sweave.sty")

You can add it to your MiKTeX installation or just put it in the same
directory as your Rnw file.


On Mon, Apr 26, 2010 at 1:10 PM, Jimmy Söderly  wrote:
> Hi everybody,
>
> I wanted to use Sweave but I do not have the Latex package:
>
> "LaTeX Error: File  'Sweave.sty' not found."
>
> I cannot find it with MiKTeX :-(
>
> Can somebody help me ?
>
> Thanks a lot,
> Jimmy
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@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.
>

__
R-help@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.


Re: [R] data frame

2010-04-26 Thread Henrique Dallazuanna
Try this:

sweep(with(x, tapply(VAR, list(variable, YEAR), FUN = prod)), 2, with(x,
tapply(VAR, YEAR, FUN = prod)), FUN = "/")

On Mon, Apr 26, 2010 at 12:07 PM, n.via...@libero.it wrote:

>
> Dear list,
> I have a big data frame which looks like this:
> variable YEAR  VAR
> EC01  2006 100
>
> EC01  2007  200
>
> EC02   2006 500
>
> EC02   2007  450
>
> PROD   2006  567
>
> PROD   2007  543
>
> What I would like to do is to divide each variables by PROD,namely:
> EC01(2006)/PROD(2006)
> EC01(2007)/PROD(2007)
> EC02(2006)/PROD(2006)
> EC02(2007)/PROD(2007)
> Anyone knows how to do it??
> THANKS!!!
>
>[[alternative HTML version deleted]]
>
> __
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@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.


[R] Help with replacement of certain values in dataset with SAS code equivalent

2010-04-26 Thread Randy Cass
I am new to R and have tried for a good while to figure out how to code this
in R.  The dataset below:

 


FTIStandKey

State

County

FTITract

CoverType

Ver_CT

V_Origin

V_SpGrp




NAH6005-001

Texas

Jasper

NAH6005

PPLB-2000-U

PPLB-2000-U

P

P




NAH6005-002

Texas

Jasper

NAH6005

NHHX-1950-O

NHHX-1950-I

N

H




NAH6253-001

Texas

Tyler

NAH6253

PPLB-2001-U

PPLB-2001-U

P

P




NAH6253-002

Texas

Tyler

NAH6253

PPLB-1993-U

PPLB-1993-U

P

P




NAH6253-003

Texas

Tyler

NAH6253

PPLB-2003-U

PPLB-2003-U

P

P




NAH6253-005

Texas

Tyler

NAH6253

XSOP--C

XSOP--C

X

S




NAH6253-008

Texas

Tyler

NAH6253

NPLB-1975-O

NPLB-1975-O

N

P




 

The SAS code for what I want to do is:

 

/*

 if FTIStandKey=" NAH6253-003" then do;

   CoverType=" XSOP--C ";

   V_SpGrp="T";

   V_Origin="T";

 end;

 

What I want to do is to be able to select certain FTIStandKey's and change
values in the dataset.  For example, I would like to select by
FTIStandKey=="NAH6253-003", and change the entries for CoverType="
XSOP--C " and change the V_SpGrp=="T", and also change V_Origin=="T".  I
only want to change the record for the one FTIStandKey.  All the other
records need to remain the exact same.  I have spent a good bit of time
trying to figure this out but with no success.   Any help would be greatly
appreciated.

 

The only thing I could find even close to what I wanted to do is listed
below:

 

# R Program for Multiple Conditional Transformations.

# Read the file into a data frame and print it.

load(file="c:\\mydata.Rdata")

print(mydata)

 

# Use column bind to add two new columns to mydata.

# Not necessary for this example, but handy to know.

 

mydata <- cbind(mydata, score1 = 0, score2 = 0)

 

attach(mydata)

mydata$guys <- gender=="m" #Creates a logical vector for males.

mydata$gals <- gender=="f" #Creates another for females.

print(mydata)

 

# Applies basic math to the group selected by the logic.

 

mydata$score1[gals]<- 2*q1[gals] + q2[gals]

mydata$score2[gals]<- 3*q1[gals] + q2[gals]

mydata$score1[guys]<-20*q1[guys] + q2[guys]

mydata$score2[guys]<-30*q1[guys] + q2[guys]

print(mydata)

 

# This step uses NULL to delete the guys & gals vars.

mydata$gals <- mydata$guys <- NULL

print(mydata)

 

This is how I modified the code from above to try to do what I wanted:

 

StandFTI <- cbind(StandFTI, score1 = NA, score2 = NA)

 attach(StandFTI)

StandFTI$Stand <- FTIStandKey=="NAH6005-001" #Creates a logical vector for
males.

StandFTI$score1[Stand]<- "TEST"

print(StandFTI)

 

But I get the warning message: 

 

In `[<-.factor`(`*tmp*`, guys, value = "TEST") :

  invalid factor level, NAs generated

 

Any help will be greatly appreciated!

 

Thanks,

 

Randy Cass

 

 


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Sweave

2010-04-26 Thread Sarah Goslee
You'll find that this is a very common question, and 30 seconds with google
will get you many nice explanations and solutions.

The quickest is to copy Sweave.sty from the package directory to your
working directory.

Sarah

On Mon, Apr 26, 2010 at 1:10 PM, Jimmy Söderly  wrote:
> Hi everybody,
>
> I wanted to use Sweave but I do not have the Latex package:
>
> "LaTeX Error: File  'Sweave.sty' not found."
>
> I cannot find it with MiKTeX :-(
>
> Can somebody help me ?
>
> Thanks a lot,
> Jimmy
>
-- 
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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.


Re: [R] Sweave

2010-04-26 Thread Doran, Harold
If you have the package you have this file. Maybe check FAQ A.12

http://www.stat.uni-muenchen.de/~leisch/Sweave/FAQ.html


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Jimmy Söderly
Sent: Monday, April 26, 2010 1:10 PM
To: r-help@r-project.org
Subject: [R] Sweave

Hi everybody,

I wanted to use Sweave but I do not have the Latex package:

"LaTeX Error: File  'Sweave.sty' not found."

I cannot find it with MiKTeX :-(

Can somebody help me ?

Thanks a lot,
Jimmy

[[alternative HTML version deleted]]

__
R-help@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.

__
R-help@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.


[R] problems accessing MS Access 2003 database with RODBC

2010-04-26 Thread Boris.Vasiliev
Dear users,

I am trying to access a Microsoft Access database from R using RODBC
package 
but I have had little success.  The setup works with isql, RODBC seems
to 
connect to the database, but RODBC does not recognize the data in the
database.  Can anybody advise where I am going wrong?

I am using R version 2.10.1 on Ubuntu 8.04. ODBC version is 2.2.11.
Mdbtools 
version is 0.6pre1. RODBC version is 1.3.1.  Test database  with one
table
was created in MS Access 2003.

The ODBC configuration files are

/etc/odbcinst.ini:
[Microsoft Access Driver (*.mdb)]
Description = MDB Tools ODBC drivers
Driver = /usr/lib/libmdbodbc.so.0
Setup =
FileUsage = 1
CPTimeout = 
CRReuse =

/home/vasiliev/.odbc.ini:
[test_db]
Description = test events database
Driver = Microsoft Access Driver (*.mdb)
Database = /home/vasiliev/siginci/data/test_db.mdb
Trace = Yes
TraceFile = /home/vasiliev/odbc.log

When I test the set-up with isql it seems to work:

isql -v -m10 test_db
+---+
| Connected!|
|   |
| sql-statement |
| help [tablename]  |
| quit  |
|   |
+---+
SQL> help
+---+---+---+---+---+
| TABLE_CAT | TABLE_SCHE| TABLE_NAME| TABLE_TYPE| REMARKS   |
+---+---+---+---+---+
|   |   | MSysObject| SYSTEM TAB|   |
|   |   | MSysACEs  | SYSTEM TAB|   |
|   |   | MSysQuerie| SYSTEM TAB|   |
|   |   | MSysRelati| SYSTEM TAB|   |
|   |   | MSysAccess| SYSTEM TAB|   |
|   |   | tblA1 | TABLE |   |
|   |   | MSysAccess| SYSTEM TAB|   |
+---+---+---+---+---+
SQLRowCount returns 7
7 rows fetched
SQL> help tblA1
+---+---+---+---+--+---+
---+
| TABLE_CAT | TABLE_SCHE| TABLE_NAME| COLUMN_NAM| DATA_TYPE| TYPE_NAME |
COLUMN_SIZ|
+---+---+---+---+--+---+
---+
|   |   | tblA1 | ID| 4| FIX ME|
|
|   |   | tblA1 | Row   | 5| FIX ME|
|
|   |   | tblA1 | Value | 4| FIX ME|
|
+---+---+---+---+--+---+
---+
SQLRowCount returns 3
3 rows fetched
SQL> select * from tblA1
+---+---+---+
| ID| Row   | Value |
+---+---+---+
| 1 | 1 | 2 |
| 2 | 10| 10|
| 3 | 30| 30|
| 4 | 40| 40|
+---+---+---+
SQLRowCount returns 4
4 rows fetched

However, when the connection is opened in R, it appears to be empty.
DBMS details
are not recognized; table and data are unavailable:

> ch <- odbcConnect("test_db")
> odbcGetInfo(ch)
   DBMS_Name DBMS_Ver  Driver_ODBC_Ver Data_Source_Name 
  ""   ""   """test_db" 
 Driver_Name   Driver_Ver ODBC_Ver  Server_Name 
   "test_db""test_db"  "03.52"  "03.52" 
> sqlTables(ch)
[1] TABLE_CAT   TABLE_SCHEM TABLE_NAME  TABLE_TYPE  REMARKS
<0 rows> (or 0-length row.names)

Does anybody know what I am doing incorrectly? 
Sincerely,
Boris.

__
R-help@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.


[R] Sweave

2010-04-26 Thread Jimmy Söderly
Hi everybody,

I wanted to use Sweave but I do not have the Latex package:

"LaTeX Error: File  'Sweave.sty' not found."

I cannot find it with MiKTeX :-(

Can somebody help me ?

Thanks a lot,
Jimmy

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Finding First of a Type in a Sequence

2010-04-26 Thread David Winsemius


On Apr 26, 2010, at 12:29 PM, Su Chu wrote:


Hi there,

I am working on a project that requires me to find the point at  
which values

become negative in a sequence about the max.

For example, say I have some sequence:

x=c(-12, -2,-19, 0, -14, -2, 9,10,20,35,56,89,60,39,12,8,-5,-2,0,10)


> x[ c( which.max(x) -min(which(x[which.max(x):1] < 0)) +1,
+ which.max(x) +min(which(x[which.max(x):length(x)] < 0)) -1) ]
[1] -2 -5



In this sequence, the max is 89, and I need to identify that -2 and  
-5 are
the points at which the values* first *become negative about the max  
and

retrieve their index values.

I was hoping for some help in finding a way to automate this  
procedure, as I
have over 100 vectors of this kind where I must find the two values  
about

the max.

Could anyone help? I would really, really appreciate it!


Thank you so much!

Best,
Su

[[alternative HTML version deleted]]

__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] Finding First of a Type in a Sequence

2010-04-26 Thread Tal Galili
Try this:



func <- function(x)
{
which.negative <- which(x<0)
index.to.return <- which.negative[which.negative > which.max(x)][1]
return(index.to.return)
}

func(x)


Best,
Tal

Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Mon, Apr 26, 2010 at 7:29 PM, Su Chu  wrote:

> Hi there,
>
> I am working on a project that requires me to find the point at which
> values
> become negative in a sequence about the max.
>
> For example, say I have some sequence:
>
> x=c(-12, -2,-19, 0, -14, -2, 9,10,20,35,56,89,60,39,12,8,-5,-2,0,10)
>
> In this sequence, the max is 89, and I need to identify that -2 and -5 are
> the points at which the values* first *become negative about the max and
> retrieve their index values.
>
> I was hoping for some help in finding a way to automate this procedure, as
> I
> have over 100 vectors of this kind where I must find the two values about
> the max.
>
> Could anyone help? I would really, really appreciate it!
>
>
> Thank you so much!
>
> Best,
> Su
>
>[[alternative HTML version deleted]]
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] R.GBM package

2010-04-26 Thread Changbin Du
HI, Dear Greg,

I AM A NEW to GBM package. Can boosting decision tree be implemented in
'gbm' package?   Or 'gbm' can only be used for regression?

IF can, DO I need to combine the rpart and gbm command?

Thanks so much!



-- 
Sincerely,
Changbin
--

[[alternative HTML version deleted]]

__
R-help@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.


  1   2   >