Re: [R] Namibia becoming NA

2010-07-17 Thread Joshua Wiley
Hi Suresh,

I think you will need to use read.table() rather than the read.csv()
wrapper for it.  Try:

input <- read.table(file = "padded.csv", sep = ",", header = TRUE,
na.strings = NULL)

HTH,

Josh

On Sat, Jul 17, 2010 at 10:47 PM, Suresh Singh  wrote:
> I have a data file in which one of the columns is country code and NA is the
> code for Namibia.
> When I read the data file using read.csv, NA for Namibia is being treated as
> null or "NA"
>
> How can I prevent this from happening?
>
> I tried the following but it didn't work
> input <- read.csv("padded.csv",header = TRUE,as.is = c("code2"))
>
> thanks,
> Suresh
>
>        [[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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] Namibia becoming NA

2010-07-17 Thread Suresh Singh
I have a data file in which one of the columns is country code and NA is the
code for Namibia.
When I read the data file using read.csv, NA for Namibia is being treated as
null or "NA"

How can I prevent this from happening?

I tried the following but it didn't work
input <- read.csv("padded.csv",header = TRUE,as.is = c("code2"))

thanks,
Suresh

[[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] loop troubles

2010-07-17 Thread Joe P King
Hi all, I appreciate the help this list has given me before. I have a
question which has been perplexing me. I have been working on doing a
Bayesian calculating inserting studies sequentially after using a
non-informative prior to get a meta-analysis type result. I created a
function using three iterations of this, my code is below. I insert prior
mean and precision (I add precision manually because I want it to be zero
but if I include zero as prior variance I get an error cant divide by zero.
Now my question is instead of having the three iterations below, is there
anyway to create a loop, the only problem is I want to have elements from
the previous posterior to be the new prior and now I cant figure out how to
do the code below in a loop. The data below is dummy data, I used a starting
mu of 1, and starting precision of 0.

 

bayes.analysis.treat<-function(mu0,p0){

n1 = 5

n2 = 10

n3 = 15

ybar1 = 12

ybar2 = 13

ybar3 = 14

sd1 = 2

sd2 = 3

sd3 = 4

#posterior 1

var1 = sd1^2 #sample variance

p1 = n1/var1 #sample precision

p1n = p0+p1

mu1 = ((p0)/(p1n)*mu0)+((p1)/(p1n))*ybar1

sigma1 = 1/sqrt(p1n)

#posterior 2

var2 = sd2^2 #sample variance

p2 = n2/var2 #sample precision

p2n = p1n+p2

mu2 = ((p1n)/(p2n)*mu1)+((p2)/(p2n))*ybar2

sigma2 = 1/sqrt(p2n)

#posterior 3

var3 = sd3^2 #sample variance

p3 = n3/var3 #sample precision

p3n = p2n+p3

mu3 = ((p2n)/(p3n)*mu2)+((p3)/(p3n))*ybar3

sigma3 = 1/sqrt(p3n)

posterior<-cbind(rbind(mu1,mu2,mu3),rbind(sigma1,sigma2,sigma3))

rownames(posterior)<-c("Posterior 1", "Posterior 2", "Posterior 3")

colnames(posterior)<-c("Mu", "SD")

return(posterior)}

 

---

Joe King, M.A.

Ph.D. Student 

University of Washington - Seattle

206-913-2912  

  j...@joepking.com

---

"Never throughout history has a man who lived a life of ease left a name
worth remembering." --Theodore Roosevelt

 


[[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 a problem

2010-07-17 Thread Joshua Wiley
Hi Michael,

The days in your example do not look continuous (at least from my
thinking), so you may have extra requirements in mind, but take a look
at this code.  My general thought was first to turn each column into a
logical vector (c1 >= 100 and c2 >= 8).  Taking advantage of the fact
that R treats TRUE as 1 and FALSE as 0, compute a rolling mean.  If
(and only if) 5 consecutive values are TRUE, the mean will be 1.  Next
I added the rolling means for each column, and then tested whether any
were 2 (i.e., 1 + 1).

Cheers,

Josh

###
#Load required package
library(zoo)

#Your data with ds converted to Date
#from dput()
dat <-
structure(list(ds = structure(c(14702, 14729, 14730, 14731, 14732,
14733, 14734, 14735, 14736, 14737, 14738, 14739, 14740, 14741,
14742, 14743, 14744), class = "Date"), c1 = c(100L, 11141L, 3L,
7615L, 6910L, 5035L, 3007L, 4L, 8335L, 2897L, 6377L, 3177L, 7946L,
8705L, 9030L, 8682L, 8440L), c2 = c(0L, 15L, 16L, 14L, 17L, 3L,
15L, 14L, 17L, 13L, 17L, 17L, 15L, 0L, 16L, 16L, 1L)), .Names = c("ds",
"c1", "c2"), row.names = c(NA, -17L), class = "data.frame")

#Order by ds
dat <- dat[order(dat$ds), ]

yourvar <- 0

#Test that 5 consecutive values from c1 AND c2 meet requirements
if(any(
 c(rollmean(dat$c1 >= 100, 5) + rollmean(dat$c2 >= 8, 5)) == 2)
   ) {yourvar <- 1}

###

On Sat, Jul 17, 2010 at 2:38 PM, Michael Hess  wrote:
> Sorry for not being clear.
>
> In the dataset there are around 100 or so days of data (in the case also rows 
> of data)
>
> I need to make sure that the person meets that c1 is at least 100 AND c2 is 
> at least 8 for 5 of 7 continuous days.
>
> I will play with what I have and see if I can find out how to do this.
>
> Thanks for the help!
>
> Michael
>
 Stephan Kolassa  07/17/10 4:50 PM >>>
> Mike,
>
> I am slightly unclear on what you want to do. Do you want to check rows
> 1 and 7 or 1 *to* 7? Should c1 be at least 100 for *any one* or *all*
> rows you are looking at, and same for c2?
>
> You can sort your data like this:
> data <- data[order(data$ds),]
>
> Type ?order for help. But also do this for added enlightenment...:
>
> library(fortunes)
> fortune("dog")
>
> Next, your analysis on the sorted data frame. As I said, I am not
> entirely clear on what you are looking at, but the following may solve
> your problem with choices "1 to 7" and "any one" above.
>
> foo <- 0
> for ( ii in 1:(nrow(data)-8) ) {
>   if (any(data$c1[ii+seq(0,6)]>=100) & any(data$c2[ii+seq(0,6)]>=8)) {
>     foo <- 1
>     break
>   }
> }
>
> The variable "foo" should contain what you want it to. Look at ?any
> (and, if this does not do what you want it to, at ?all) for further info.
>
> No doubt this could be vectorized, but I think the loop is clear enough.
>
> Good luck!
> Stephan
>
>
>
> Michael Hess schrieb:
>> Hello R users,
>>
>> I am a researcher at the University of Michigan looking for a solution to an 
>> R problem.  I have loaded my data in from a mysql database and it looks like 
>> this
>>
>>> data
>>            ds c1 c2
>> 1  2010-04-03        100           0
>> 2  2010-04-30      11141          15
>> 3  2010-05-01      3          16
>> 4  2010-05-02       7615          14
>> 5  2010-05-03       6910          17
>> 6  2010-05-04       5035          3
>> 7  2010-05-05       3007          15
>> 8  2010-05-06       4          14
>> 9  2010-05-07       8335          17
>> 10 2010-05-08       2897          13
>> 11 2010-05-09       6377          17
>> 12 2010-05-10       3177          17
>> 13 2010-05-11       7946          15
>> 14 2010-05-12       8705          0
>> 15 2010-05-13       9030          16
>> 16 2010-05-14       8682          16
>> 17 2010-05-15       8440          15
>>
>>
>> What I am trying to do is sort by ds, and take rows 1,7, see if c1 is at 
>> least 100 AND c2 is at least 8. If it is not, start with check rows 2,8 and 
>> if not there 3,9until it loops over the entire file.   If it finds a set 
>> that matches, set a new variable equal to 1, if never finds a match, set it 
>> equal to 0.
>>
>> I have done this in stata but on this project we are trying to use R.  Is 
>> this something that can be done in R, if so, could someone point me in the 
>> correct direction.
>>
>> Thanks,
>>
>> Michael Hess
>> University of Michigan
>> Health System
>>
>> **
>> Electronic Mail is not secure, may not be read every day, and should not be 
>> used for urgent or sensitive issues
>>
>> __
>> 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.
>>
>
>
> **
> Electronic Mail is not secure, may not be read every day, and should not be 
> used for urgent or sensitive issues
>
> ___

Re: [R] how to collapse categories or re-categorize variables?

2010-07-17 Thread Ista Zahn
On Sat, Jul 17, 2010 at 9:03 PM, Peter Dalgaard  wrote:
> Ista Zahn wrote:
>> Hi,
>> On Fri, Jul 16, 2010 at 5:18 PM, CC  wrote:
>>> I am sure this is a very basic question:
>>>
>>> I have 600,000 categorical variables in a data.frame - each of which is
>>> classified as "0", "1", or "2"
>>>
>>> What I would like to do is collapse "1" and "2" and leave "0" by itself,
>>> such that after re-categorizing "0" = "0"; "1" = "1" and "2" = "1" --- in
>>> the end I only want "0" and "1" as categories for each of the variables.
>>
>> Something like this should work
>>
>> for (i in names(dat)) {
>> dat[, i]  <- factor(dat[, i], levels = c("0", "1", "2"), labels =
>> c("0", "1", "1))
>> }
>
> Unfortunately, it won't:
>
>> d <- 0:2
>> factor(d, levels=c(0,1,1))
> [1] 0    1    
> Levels: 0 1 1
> Warning message:
> In `levels<-`(`*tmp*`, value = c("0", "1", "1")) :
>  duplicated levels will not be allowed in factors anymore
>

I stand corrected. Thank you Peter.

>
> This effect, I have been told, goes way back to design choices in S
> (that you can have repeated level names) plus compatibility ever since.
>
> It would make more sense if it behaved like
>
> d <- factor(d); levels(d) <- c(0,1,1)
>
> and maybe, some time in the future, it will. Meanwhile, the above is the
> workaround.
>
> (BTW, if there are 60 variables, you probably don't want to iterate
> over their names, more likely "for(i in seq_along(dat))...")
>
> --
> Peter Dalgaard
> Center for Statistics, Copenhagen Business School
> Phone: (+45)38153501
> Email: pd@cbs.dk  Priv: pda...@gmail.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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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] slplot issue

2010-07-17 Thread Dennis Murphy
In which package would one find slplot? It's not in any of the 1800+
packages on my system...

Dennis

On Sat, Jul 17, 2010 at 1:28 PM, Shawn Way  wrote:

> In a prior life I was able to use slplot can change the xlim and ylim such
> that the ellipse was a perfect circle.  It seems that the xlim and ylim
> are no longer supported by the slplot function.  Any thoughts on how I can
> change this?
>
> Thank you kindly,
>
> --
> Shawn Way, PE
> MECO, Inc.
> (p) 281-276-7612
> (f)  281-313-0248
>
> http://www.meco.com/img/meco.gif"; />
> http://www.meco.com";>WWW.MECO.COM
>  
>This e-mail is for the use of the intended recipient(s) only. If you
> have
>received this e-mail in error, please notify the sender immediately
> and then
>delete it. If you are not the intended recipient, you must not use,
> disclose
>or distribute this e-mail without the author's prior permission.
> We have taken
>precautions to minimize the risk of transmitting software viruses,
> but we
>advise you to carry out your own virus checks on any attachment to
> this message. We
>cannot accept liability for any loss or damage caused by software
> viruses.
>
>
>[[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] save plot

2010-07-17 Thread Gavin Simpson
On Sat, 2010-07-17 at 14:52 -0400, linda.s wrote:
> > Open a new device before plotting, do your plotting, close the device.
> >
> > For example, using a PDF device via pdf():
> >
> > pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,
> >version = "1.4", onefile = TRUE)
> > for(i in 1:10) {
> >y <- rnorm(100)
> >x <- rnorm(100)
> >plot(y ~ x)
> > }
> > dev.off()
> >
> > The last line (dev.off() is very important as the file will not be valid
> > pdf without closing the device.
> >
> > HTH
> >
> > G
> 
> I got the error:
> > pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,
> +version = "1.4", onefile = TRUE)
> > for(i in 1:10) {
> +y <- rnorm(100)
> +x <- rnorm(100)
> +plot(y ~ x)
> + }
> > dev.off()
> null device
>   1

If by "error" you mean "null device \n 1", that is a notice informing
you what the now current plotting device is, i.e. in this cases there
isn't one.

Did you look in your current working directory (see what that is by
using getwd() ) for a pdf named "my_plots.pdf"?

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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] plot month and year

2010-07-17 Thread Gabor Grothendieck
On Sat, Jul 17, 2010 at 2:41 PM, linda.s  wrote:
> The X axis on the plot now starts from 2008.0; Since the data starts
> from January 2008, can I make it 2008.1, and also show 2009.12 on the
> axis?

See the example of a fancy X axis in this post:

   http://www.mail-archive.com/r-help@r-project.org/msg31060.html

and there is also a similar example in the examples section of ?plot.zoo

__
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] plot month and year

2010-07-17 Thread Dennis Murphy
Hi:

I'm a little more familiar with ggplot2 than zoo for graphing multivariate
time series, so my response is based on that bias.

On Sat, Jul 17, 2010 at 11:41 AM, linda.s  wrote:

> i am a beginner and tried to provide a reproducible example. is the
> following style a correct one?
>

It's beautiful. Thank you!


> Thanks.
>
> > dput(unem)
> > structure(list(a = c(10.2, 9.8, 9.5, 8.3, 7.9, 8.8, 8.9, 9.3,
> + 9.2, 9, 9.5, 12, 15.7, 16.1, 15.4, 14.7, 13.9, 15.3, 15.4, 15,
> + 13.8, 13.9, 14.1, 15.8), b = c(7, 6.7, 6.8, 6.1, 6.5, 7.4, 8.4,
> + 7.6, 7.5, 7.5, 7.8, 9.1, 11.2, 12.1, 12.2, 11.5, 11.5, 11.7,
> + 11.7, 11.2, 10.3, 10.7, 10.8, 11.6), c = c(6.5, 5.9, 5.9, 5.4,
> + 6.1, 6.6, 7.6, 7.2, 6.9, 7.1, 7.7, 8.4, 11.6, 11.3, 11, 10.9,
> + 12, 12.7, 12.8, 11, 10, 10.1, 10.3, 11.1), d = c(8.3, 7.6, 7.3,
> + 6.2, 6.2, 7.1, 8.5, 8.3, 7.7, 7.3, 8, 10.2, 13.9, 14.9, 14.8,
> + 13.1, 13.1, 13.3, 13.3, 12.1, 11.1, 11.3, 11.6, 12.7)), .Names = c("a",
> + "b", "c", "d"), class = "data.frame", row.names = c("JAN_08",
> + "FEB_08", "MAR_08", "APR_08", "MAY_08", "JUN_08", "JULY_08",
> + "AUG_08", "SEP_08", "OCT_08", "NOV_08", "DEC_08", "JAN_09", "FEB_09",
> + "MAR_09", "APR_09", "MAY_09", "JUN_09", "JUL_09", "AUG_09", "SEP_09",
> + "OCT_09", "NOV_09", "DEC_09"))
>   abcd
> JAN_08  10.2  7.0  6.5  8.3
> FEB_08   9.8  6.7  5.9  7.6
> MAR_08   9.5  6.8  5.9  7.3
> APR_08   8.3  6.1  5.4  6.2
> MAY_08   7.9  6.5  6.1  6.2
> JUN_08   8.8  7.4  6.6  7.1
> JULY_08  8.9  8.4  7.6  8.5
> AUG_08   9.3  7.6  7.2  8.3
> SEP_08   9.2  7.5  6.9  7.7
> OCT_08   9.0  7.5  7.1  7.3
> NOV_08   9.5  7.8  7.7  8.0
> DEC_08  12.0  9.1  8.4 10.2
> JAN_09  15.7 11.2 11.6 13.9
> FEB_09  16.1 12.1 11.3 14.9
> MAR_09  15.4 12.2 11.0 14.8
> APR_09  14.7 11.5 10.9 13.1
> MAY_09  13.9 11.5 12.0 13.1
> JUN_09  15.3 11.7 12.7 13.3
> JUL_09  15.4 11.7 12.8 13.3
> AUG_09  15.0 11.2 11.0 12.1
> SEP_09  13.8 10.3 10.0 11.1
> OCT_09  13.9 10.7 10.1 11.3
> NOV_09  14.1 10.8 10.3 11.6
> DEC_09  15.8 11.6 11.1 12.7
> > attach(unem)
> The following object(s) are masked from 'unem (position 3)':
>
>a, b, c, d
> The following object(s) are masked from 'unem (position 4)':
>
>a, b, c, d
>

This is one reason why attaching data frames that you created from objects
in your workspace is generally not a good idea. A cleaner approach is to use
with(df, {code}) instead, where {code} represents the function(s) you want
to apply to the (temporarily) attached data frame df. See ?with for details
and examples.

One way to create a multivariate ts object is as follows:

unemp <- ts(unem, start = c(2008, 1), end = c(2009, 12), freq = 12)
plot(unemp)

Unfortunately, the time labels are not what you wanted and an attempt to
suppress the x-axis on the multiple ts plot was futile. So, move on to plan
B.

> unem1 <- ts(unem$a, start = c(2008, 1), freq = 12)
> > plot(unem1, type = "o")
>
> Question:
> The X axis on the plot now starts from 2008.0; Since the data starts
> from January 2008, can I make it 2008.1, and also show 2009.12 on the
> axis?
>

2008.1 - 2009.12 doesn't thrill me; let's look at what we can get from the
graphics package ggplot2. If you don't already have it on your system,
install it from CRAN first.

library(ggplot2)

# Stack the time series into a vector labeled 'value' with series
identifiers
# put into a factor called 'variable'. This comes in handy when we
# plot and add the facet_grid() layer to the graph below.
munemp <- melt(unem)

# Create a vector of dates, convert them to class Date, and add to munemp
dts <- c(paste('2008-', 1:12, '-1', sep = ''), paste('2009-', 1:12, '-1',
sep = ''))
> dts   # what it looks like
 [1] "2008-1-1"  "2008-2-1"  "2008-3-1"  "2008-4-1"  "2008-5-1"  "2008-6-1"
 [7] "2008-7-1"  "2008-8-1"  "2008-9-1"  "2008-10-1" "2008-11-1" "2008-12-1"
[13] "2009-1-1"  "2009-2-1"  "2009-3-1"  "2009-4-1"  "2009-5-1"  "2009-6-1"
[19] "2009-7-1"  "2009-8-1"  "2009-9-1"  "2009-10-1" "2009-11-1" "2009-12-1"
dates <- as.Date(dts)   # convert to class Date
munemp$dates <- rep(dates, 4)  # repeat each time for the four series

# ggplot is a system of adding graphical layers to a plot.
# Create the 'scaffold' - data frame, x and y variables
p <- ggplot(munemp, aes(x = dates, y = value))
# Add layers - line plots stacked on top one another with axis labels
p + geom_line() + facet_grid(variable ~ .) + xlab('') +
ylab('Unemployment (%)')

I don't know about you, but I like the default labeling in ggplot2 better
than that from the first plot.

There is sure to be a nice way to do this in package zoo. As I'm in the
beginning phases of learning it, I'm looking forward to solutions from Achim
and/or Gabor to further my appreciation of their excellent package (no
pressure :).


HTH,
Dennis

Thanks.
>
> On Wed, Jul 14, 2010 at 9:49 AM, Achim Zeileis 
> wrote:
> > You do not provide a reproducible example, as the posting guide asks you
> to.
> > But I guess that your time series setup using ts() is insufficient, see
> ?ts

Re: [R] Help with a problem

2010-07-17 Thread Michael Hess
Sorry for not being clear.

In the dataset there are around 100 or so days of data (in the case also rows 
of data)

I need to make sure that the person meets that c1 is at least 100 AND c2 is at 
least 8 for 5 of 7 continuous days.

I will play with what I have and see if I can find out how to do this.

Thanks for the help!

Michael  

>>> Stephan Kolassa  07/17/10 4:50 PM >>>
Mike,

I am slightly unclear on what you want to do. Do you want to check rows 
1 and 7 or 1 *to* 7? Should c1 be at least 100 for *any one* or *all* 
rows you are looking at, and same for c2?

You can sort your data like this:
data <- data[order(data$ds),]

Type ?order for help. But also do this for added enlightenment...:

library(fortunes)
fortune("dog")

Next, your analysis on the sorted data frame. As I said, I am not 
entirely clear on what you are looking at, but the following may solve 
your problem with choices "1 to 7" and "any one" above.

foo <- 0
for ( ii in 1:(nrow(data)-8) ) {
   if (any(data$c1[ii+seq(0,6)]>=100) & any(data$c2[ii+seq(0,6)]>=8)) {
 foo <- 1
 break
   }
}

The variable "foo" should contain what you want it to. Look at ?any 
(and, if this does not do what you want it to, at ?all) for further info.

No doubt this could be vectorized, but I think the loop is clear enough.

Good luck!
Stephan



Michael Hess schrieb:
> Hello R users,
> 
> I am a researcher at the University of Michigan looking for a solution to an 
> R problem.  I have loaded my data in from a mysql database and it looks like 
> this
> 
>> data
>ds c1 c2
> 1  2010-04-03100   0
> 2  2010-04-30  11141  15
> 3  2010-05-01  3  16
> 4  2010-05-02   7615  14
> 5  2010-05-03   6910  17
> 6  2010-05-04   5035  3
> 7  2010-05-05   3007  15
> 8  2010-05-06   4  14
> 9  2010-05-07   8335  17
> 10 2010-05-08   2897  13
> 11 2010-05-09   6377  17
> 12 2010-05-10   3177  17
> 13 2010-05-11   7946  15
> 14 2010-05-12   8705  0
> 15 2010-05-13   9030  16
> 16 2010-05-14   8682  16
> 17 2010-05-15   8440  15
> 
> 
> What I am trying to do is sort by ds, and take rows 1,7, see if c1 is at 
> least 100 AND c2 is at least 8. If it is not, start with check rows 2,8 and 
> if not there 3,9until it loops over the entire file.   If it finds a set 
> that matches, set a new variable equal to 1, if never finds a match, set it 
> equal to 0.
> 
> I have done this in stata but on this project we are trying to use R.  Is 
> this something that can be done in R, if so, could someone point me in the 
> correct direction.
> 
> Thanks,
> 
> Michael Hess
> University of Michigan
> Health System
> 
> **
> Electronic Mail is not secure, may not be read every day, and should not be 
> used for urgent or sensitive issues 
> 
> __
> 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.
> 


**
Electronic Mail is not secure, may not be read every day, and should not be 
used for urgent or sensitive issues 

__
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 collapse categories or re-categorize variables?

2010-07-17 Thread Phil Spector

Please look at Peter Dalgaard's response a little more
carefully.  There's a big difference between the levels=
argument (which must be unique) and the labels= argument 
(which need not be).  Here are two ways

to do what you want:


d = 0:2
factor(d,levels=0:2,labels=c('0','1','1'))

[1] 0 1 1

library(car)
recode(d,"c(1,2)='1'")

[1] 0 1 1


- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Sat, 17 Jul 2010, Peter Dalgaard wrote:


Ista Zahn wrote:

Hi,
On Fri, Jul 16, 2010 at 5:18 PM, CC  wrote:

I am sure this is a very basic question:

I have 600,000 categorical variables in a data.frame - each of which is
classified as "0", "1", or "2"

What I would like to do is collapse "1" and "2" and leave "0" by itself,
such that after re-categorizing "0" = "0"; "1" = "1" and "2" = "1" --- in
the end I only want "0" and "1" as categories for each of the variables.


Something like this should work

for (i in names(dat)) {
dat[, i]  <- factor(dat[, i], levels = c("0", "1", "2"), labels =
c("0", "1", "1))
}


Unfortunately, it won't:


d <- 0:2
factor(d, levels=c(0,1,1))

[1] 01
Levels: 0 1 1
Warning message:
In `levels<-`(`*tmp*`, value = c("0", "1", "1")) :
 duplicated levels will not be allowed in factors anymore


This effect, I have been told, goes way back to design choices in S
(that you can have repeated level names) plus compatibility ever since.

It would make more sense if it behaved like

d <- factor(d); levels(d) <- c(0,1,1)

and maybe, some time in the future, it will. Meanwhile, the above is the
workaround.

(BTW, if there are 60 variables, you probably don't want to iterate
over their names, more likely "for(i in seq_along(dat))...")

--
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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-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 Reshaping from Wide to Long

2010-07-17 Thread Phil Spector

An alternative using the base reshape function:

one = 
reshape(accuracy,idvar='Subject',varying=list(c(2,3,4),c(5,6,7),c(8,9,10)),
  direction='long',timevar='shape')
two = reshape(one,idvar=c('Subject','shape'),varying=list(3:5),
  direction='long',timevar='color')
two$shape=factor(two$shape,labels=c('Circle','Square','Triangle'))
two$color=factor(two$color,labels=c('Blue','Red','Green'))
names(two)[4] = 'value'

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu



On Sat, 17 Jul 2010, Jeff Newmiller wrote:


Try this:

library(reshape)

accuracy <- structure(list(Subject = c(101L, 102L, 103L, 104L, 105L, 106L
), CircleBlue = c(95L, 80L, 80L, 85L, 70L, 70L), CircleRed = c(100L,
90L, 70L, 80L, 75L, 75L), CircleGreen = c(100L, 100L, 95L, 100L,
95L, 75L), SquareBlue = c(95L, 85L, 90L, 90L, 70L, 40L), SquareRed =
c(100L,
90L, 100L, 90L, 75L, 60L), SquareGreen = c(100L, 100L, 100L, 90L,
85L, 85L), TriangleBlue = c(60L, 55L, 65L, 65L, 60L, 40L), TriangleRed =
c(80L,
45L, 60L, 50L, 40L, 35L), TriangleGreen = c(75L, 45L, 55L, 50L, 45L,
50L)), .Names = c("Subject", "CircleBlue", "CircleRed", "CircleGreen",
"SquareBlue", "SquareRed", "SquareGreen", "TriangleBlue", "TriangleRed",
"TriangleGreen"), row.names = c(NA, 6L), class = "data.frame")

tmp1 <- melt( accuracy, id="Subject" )
colnames( tmp1 ) [ which( colnames( tmp1 ) == "value" ) ] <- "Accuracy"

keys <- data.frame( variable = levels( tmp1$variable )
 , Shape=rep( c( "Circle", "Square", "Triangle" ), each=3 )
 , Color=rep( c( "Blue", "Red", "Green" ), times=3 )
 )
tmp2 <- merge( tmp1, keys )

accuracym <- tmp2[ , c("Accuracy", "Subject", "Shape", "Color") ]

On Sat, 17 Jul 2010, John L. Woodard wrote:


Hi Tal,

Here is the output as you requested:

structure(list(Subject = c(101L, 102L, 103L, 104L, 105L, 106L
), CircleBlue = c(95L, 80L, 80L, 85L, 70L, 70L), CircleRed = c(100L,
90L, 70L, 80L, 75L, 75L), CircleGreen = c(100L, 100L, 95L, 100L,
95L, 75L), SquareBlue = c(95L, 85L, 90L, 90L, 70L, 40L), SquareRed =
c(100L,
90L, 100L, 90L, 75L, 60L), SquareGreen = c(100L, 100L, 100L, 90L,
85L, 85L), TriangleBlue = c(60L, 55L, 65L, 65L, 60L, 40L), TriangleRed =
c(80L,
45L, 60L, 50L, 40L, 35L), TriangleGreen = c(75L, 45L, 55L, 50L, 45L,
50L)), .Names = c("Subject", "CircleBlue", "CircleRed", "CircleGreen",
"SquareBlue", "SquareRed", "SquareGreen", "TriangleBlue", "TriangleRed",
"TriangleGreen"), row.names = c(NA, 6L), class = "data.frame")

Regarding the ANOVA, OK--I see it now (I was looking for the words
"Repeated Measures", which weren't there...).  I didn't notice the
example till I ran each one.  It looks like a great program, though I'll
have to figure out the reshape issue before I can use ezANOVA.  Many
thanks for your help!

John

John L. Woodard, Ph.D.

Associate Professor of Psychology

Wayne State University

5057 Woodward Ave., 7th Floor

Detroit, MI 48202


Voice: 313-577-5838

Fax: 313-577-7636

e-mail: john.wood...@wayne.edu


On 7/17/10 2:40 PM, Tal Galili wrote:

Hi John,

Try posting a sample of your data in reply to this e-mail by using:

dput(head(accuracy))

And me (or someone else) will be sure to fix your command.

Regarding the ANOVA, read more :)

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 Sat, Jul 17, 2010 at 8:03 PM, jlwoodard mailto:john.wood...@wayne.edu>> wrote:


Tal,
 Thanks for the information.

 I actually did read through the help for the reshape package,
though being
relatively new to R, I don't quite understand the ins and outs of the
command.

I tried using the melt command:
x<-melt(accuracy,id='Subject')

but, it didn't give me anything different than the stacked
command.  I'm
trying to get two columns to indicate the Shape and Color.

Thanks also for this information on ezANOVA.  It looks very promising,
though I didn't see an example of repeated measures ANOVA in the
help file.

Best regards,

John
--
View this message in context:

http://r.789695.n4.nabble.com/Help-with-Reshaping-from-Wide-to-Long-tp2292462p2292524.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org  mailing list
   

Re: [R] how to collapse categories or re-categorize variables?

2010-07-17 Thread Peter Dalgaard
Ista Zahn wrote:
> Hi,
> On Fri, Jul 16, 2010 at 5:18 PM, CC  wrote:
>> I am sure this is a very basic question:
>>
>> I have 600,000 categorical variables in a data.frame - each of which is
>> classified as "0", "1", or "2"
>>
>> What I would like to do is collapse "1" and "2" and leave "0" by itself,
>> such that after re-categorizing "0" = "0"; "1" = "1" and "2" = "1" --- in
>> the end I only want "0" and "1" as categories for each of the variables.
> 
> Something like this should work
> 
> for (i in names(dat)) {
> dat[, i]  <- factor(dat[, i], levels = c("0", "1", "2"), labels =
> c("0", "1", "1))
> }

Unfortunately, it won't:

> d <- 0:2
> factor(d, levels=c(0,1,1))
[1] 01
Levels: 0 1 1
Warning message:
In `levels<-`(`*tmp*`, value = c("0", "1", "1")) :
  duplicated levels will not be allowed in factors anymore


This effect, I have been told, goes way back to design choices in S
(that you can have repeated level names) plus compatibility ever since.

It would make more sense if it behaved like

d <- factor(d); levels(d) <- c(0,1,1)

and maybe, some time in the future, it will. Meanwhile, the above is the
workaround.

(BTW, if there are 60 variables, you probably don't want to iterate
over their names, more likely "for(i in seq_along(dat))...")

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] Help with a problem

2010-07-17 Thread Stephan Kolassa

Mike,

I am slightly unclear on what you want to do. Do you want to check rows 
1 and 7 or 1 *to* 7? Should c1 be at least 100 for *any one* or *all* 
rows you are looking at, and same for c2?


You can sort your data like this:
data <- data[order(data$ds),]

Type ?order for help. But also do this for added enlightenment...:

library(fortunes)
fortune("dog")

Next, your analysis on the sorted data frame. As I said, I am not 
entirely clear on what you are looking at, but the following may solve 
your problem with choices "1 to 7" and "any one" above.


foo <- 0
for ( ii in 1:(nrow(data)-8) ) {
  if (any(data$c1[ii+seq(0,6)]>=100) & any(data$c2[ii+seq(0,6)]>=8)) {
foo <- 1
break
  }
}

The variable "foo" should contain what you want it to. Look at ?any 
(and, if this does not do what you want it to, at ?all) for further info.


No doubt this could be vectorized, but I think the loop is clear enough.

Good luck!
Stephan



Michael Hess schrieb:

Hello R users,

I am a researcher at the University of Michigan looking for a solution to an R 
problem.  I have loaded my data in from a mysql database and it looks like this


data

   ds c1 c2
1  2010-04-03100   0
2  2010-04-30  11141  15
3  2010-05-01  3  16
4  2010-05-02   7615  14
5  2010-05-03   6910  17
6  2010-05-04   5035  3
7  2010-05-05   3007  15
8  2010-05-06   4  14
9  2010-05-07   8335  17
10 2010-05-08   2897  13
11 2010-05-09   6377  17
12 2010-05-10   3177  17
13 2010-05-11   7946  15
14 2010-05-12   8705  0
15 2010-05-13   9030  16
16 2010-05-14   8682  16
17 2010-05-15   8440  15


What I am trying to do is sort by ds, and take rows 1,7, see if c1 is at least 
100 AND c2 is at least 8. If it is not, start with check rows 2,8 and if not 
there 3,9until it loops over the entire file.   If it finds a set that 
matches, set a new variable equal to 1, if never finds a match, set it equal to 
0.

I have done this in stata but on this project we are trying to use R.  Is this 
something that can be done in R, if so, could someone point me in the correct 
direction.

Thanks,

Michael Hess
University of Michigan
Health System

**
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues 


__
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] sort file names in numerical order

2010-07-17 Thread Michael Hannon


> I get some file names by list.files().
> These names are in  alphabetical order.
> I want to change it to logical numeric  order.
> Example:
> > fileNames <- c("A10", "A1", "A2", "B1", "B2",  "B10")
> > sort(fileNames)
> [1] "A1"  "A10" "A2"  "B1"   "B10" "B2"
> I want to have:
> "A1"  "A2" "A10" "B1" "B2" "B10"
> 
> Is  this possible?

Greetings.  I see that you've gotten an elegant solution to your problem.
I've appended a poor-man's solution, which I generated more for my own
edification than for yours.

-- Mike


## modified file names, changed to exhibit sorting on letters
fileNames <- c("A10", "B10", "A1", "A2", "B1", "B2"); fileNames

## use regular expressions to pick off letters, numbers
fnLet <- gsub("(^[^0-9]+).*$", "\\1", fileNames); fnLet
fnNum <- gsub("^[^0-9]+(.*)$", "\\1", fileNames); fnNum

## need to force numeric sorting of the numbers
fnNum <- as.numeric(fnNum)

## find the order of the numbers, for later use in subsetting
fnNumOrd <- order(fnNum); fnNumOrd

## pack all the relevant information into a data frame, then select from that
fnPieces <- data.frame(fnLet, fnNum, fileNames, stringsAsFactors=FALSE);
fnPieces

## partial sort by numbers only (gives new df)
dfPartialSort <- fnPieces[fnNumOrd, ]; dfPartialSort

## find the order of the names, then select from new df with that
fnLetOrd <- order(dfPartialSort[, 1]); fnLetOrd
dfFullSort <- dfPartialSort[fnLetOrd, ]; dfFullSort

## the file names have "gone along for the ride", so pick them off now
sortedFileNames <- dfFullSort$fileNames; sortedFileNames

__
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] slplot issue

2010-07-17 Thread Shawn Way
In a prior life I was able to use slplot can change the xlim and ylim such 
that the ellipse was a perfect circle.  It seems that the xlim and ylim 
are no longer supported by the slplot function.  Any thoughts on how I can 
change this?

Thank you kindly,

--
Shawn Way, PE
MECO, Inc.
(p) 281-276-7612
(f)  281-313-0248

http://www.meco.com/img/meco.gif"; />
http://www.meco.com";>WWW.MECO.COM
 
This e-mail is for the use of the intended recipient(s) only. If you 
have
received this e-mail in error, please notify the sender immediately and 
then
delete it. If you are not the intended recipient, you must not use, 
disclose 
or distribute this e-mail without the author's prior permission. We 
have taken
precautions to minimize the risk of transmitting software viruses, but 
we 
advise you to carry out your own virus checks on any attachment to this 
message. We
cannot accept liability for any loss or damage caused by software 
viruses.


[[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 a problem

2010-07-17 Thread RICHARD M. HEIBERGER
Michael,

This will get you started.  What you are doing with the seven rows isn't
clear
from your description.  I made the dates into "Date" objects.  I called your
data
"mydata" as "data" is potentially ambiguous.

Rich



mydata <- read.table(header=TRUE, textConnection("
  ds c1 c2
1  2010-04-03100   0
2  2010-04-30  11141  15
3  2010-05-01  3  16
4  2010-05-02   7615  14
5  2010-05-03   6910  17
6  2010-05-04   5035  3
7  2010-05-05   3007  15
8  2010-05-06   4  14
9  2010-05-07   8335  17
10 2010-05-08   2897  13
11 2010-05-09   6377  17
12 2010-05-10   3177  17
13 2010-05-11   7946  15
14 2010-05-12   8705  0
15 2010-05-13   9030  16
16 2010-05-14   8682  16
17 2010-05-15   8440  15
"))

mydata$ds <- as.Date(mydata$ds)
result <- 0
for (i in seq(length=nrow(mydata)-6)) {
  ## do something with
  mydata[i:(i+6), 2:3]
  ## and
  c(100, 8)
  if (TRUE) {
result <- i  ## I am returning the start row, not the generic 1.
break
  }
}
result

[[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 Reshaping from Wide to Long

2010-07-17 Thread Jeff Newmiller

Try this:

library(reshape)

accuracy <- structure(list(Subject = c(101L, 102L, 103L, 104L, 105L, 106L
), CircleBlue = c(95L, 80L, 80L, 85L, 70L, 70L), CircleRed = c(100L,
90L, 70L, 80L, 75L, 75L), CircleGreen = c(100L, 100L, 95L, 100L,
95L, 75L), SquareBlue = c(95L, 85L, 90L, 90L, 70L, 40L), SquareRed =
c(100L,
90L, 100L, 90L, 75L, 60L), SquareGreen = c(100L, 100L, 100L, 90L,
85L, 85L), TriangleBlue = c(60L, 55L, 65L, 65L, 60L, 40L), TriangleRed =
c(80L,
45L, 60L, 50L, 40L, 35L), TriangleGreen = c(75L, 45L, 55L, 50L, 45L,
50L)), .Names = c("Subject", "CircleBlue", "CircleRed", "CircleGreen",
"SquareBlue", "SquareRed", "SquareGreen", "TriangleBlue", "TriangleRed",
"TriangleGreen"), row.names = c(NA, 6L), class = "data.frame")

tmp1 <- melt( accuracy, id="Subject" )
colnames( tmp1 ) [ which( colnames( tmp1 ) == "value" ) ] <- "Accuracy"

keys <- data.frame( variable = levels( tmp1$variable )
  , Shape=rep( c( "Circle", "Square", "Triangle" ), each=3 )
  , Color=rep( c( "Blue", "Red", "Green" ), times=3 )
  )
tmp2 <- merge( tmp1, keys )

accuracym <- tmp2[ , c("Accuracy", "Subject", "Shape", "Color") ]

On Sat, 17 Jul 2010, John L. Woodard wrote:


Hi Tal,

Here is the output as you requested:

structure(list(Subject = c(101L, 102L, 103L, 104L, 105L, 106L
), CircleBlue = c(95L, 80L, 80L, 85L, 70L, 70L), CircleRed = c(100L,
90L, 70L, 80L, 75L, 75L), CircleGreen = c(100L, 100L, 95L, 100L,
95L, 75L), SquareBlue = c(95L, 85L, 90L, 90L, 70L, 40L), SquareRed =
c(100L,
90L, 100L, 90L, 75L, 60L), SquareGreen = c(100L, 100L, 100L, 90L,
85L, 85L), TriangleBlue = c(60L, 55L, 65L, 65L, 60L, 40L), TriangleRed =
c(80L,
45L, 60L, 50L, 40L, 35L), TriangleGreen = c(75L, 45L, 55L, 50L, 45L,
50L)), .Names = c("Subject", "CircleBlue", "CircleRed", "CircleGreen",
"SquareBlue", "SquareRed", "SquareGreen", "TriangleBlue", "TriangleRed",
"TriangleGreen"), row.names = c(NA, 6L), class = "data.frame")

Regarding the ANOVA, OK--I see it now (I was looking for the words
"Repeated Measures", which weren't there...).  I didn't notice the
example till I ran each one.  It looks like a great program, though I'll
have to figure out the reshape issue before I can use ezANOVA.  Many
thanks for your help!

John

John L. Woodard, Ph.D.

Associate Professor of Psychology

Wayne State University

5057 Woodward Ave., 7th Floor

Detroit, MI 48202


Voice: 313-577-5838

Fax: 313-577-7636

e-mail: john.wood...@wayne.edu


On 7/17/10 2:40 PM, Tal Galili wrote:

Hi John,

Try posting a sample of your data in reply to this e-mail by using:

dput(head(accuracy))

And me (or someone else) will be sure to fix your command.

Regarding the ANOVA, read more :)

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 Sat, Jul 17, 2010 at 8:03 PM, jlwoodard mailto:john.wood...@wayne.edu>> wrote:


Tal,
 Thanks for the information.

 I actually did read through the help for the reshape package,
though being
relatively new to R, I don't quite understand the ins and outs of the
command.

I tried using the melt command:
x<-melt(accuracy,id='Subject')

but, it didn't give me anything different than the stacked
command.  I'm
trying to get two columns to indicate the Shape and Color.

Thanks also for this information on ezANOVA.  It looks very promising,
though I didn't see an example of repeated measures ANOVA in the
help file.

Best regards,

John
--
View this message in context:

http://r.789695.n4.nabble.com/Help-with-Reshaping-from-Wide-to-Long-tp2292462p2292524.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.



---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Re

[R] Error installing tkrplot

2010-07-17 Thread Jay-pea

Hi,

I've been trying to install tkrplot and have been coming across this error.



Loading required package: tcltk
Loading Tcl/Tk interface ... Error : .onLoad failed in loadNamespace() for
'tcltk', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared library
'/Library/Frameworks/R.framework/Resources/library/tcltk/libs/i386/tcltk.so':
 
dlopen(/Library/Frameworks/R.framework/Resources/library/tcltk/libs/i386/tcltk.so,
10): Library not loaded: /usr/local/lib/libtcl8.5.dylib
  Referenced from:
/Library/Frameworks/R.framework/Resources/library/tcltk/libs/i386/tcltk.so
  Reason: image not found
Error: package 'tcltk' could not be loaded

I have been clicking on 'tkrplot' in 'R Package manager', yet I get this
error saying that I'm trying to load the package above that in the list
'tcltk'.

Anybody know why this is happening. Is there another way to load it?

Thanks,

James

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Error-installing-tkrplot-tp2292646p2292646.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] Regarding accesing R- Repositories at servers

2010-07-17 Thread Uwe Ligges



On 13.07.2010 09:42, venkatesh bandaru wrote:

Dear R-help team ,
I am venkatesh, student of University of Hyderabad, India. I couldn't able to  access 
R-repositories at Your specified servers.It is giving error such as " Couldn't able 
to access media".



It would be helpful to see what you did (the function call you entered), 
what your R version is as well as your OS, how you are connected. And 
the actual error message, not one you made up


Best,
Uwe Ligges


Can you please help me Regarding this.

i am anticipating for your reply, thanking you.

wishes&  regards
B.venkatesh,
University of Hyderabad,
India
9440186746



[[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] Help with Reshaping from Wide to Long

2010-07-17 Thread John L. Woodard
Hi Tal,

Here is the output as you requested:

structure(list(Subject = c(101L, 102L, 103L, 104L, 105L, 106L
), CircleBlue = c(95L, 80L, 80L, 85L, 70L, 70L), CircleRed = c(100L,
90L, 70L, 80L, 75L, 75L), CircleGreen = c(100L, 100L, 95L, 100L,
95L, 75L), SquareBlue = c(95L, 85L, 90L, 90L, 70L, 40L), SquareRed = 
c(100L,
90L, 100L, 90L, 75L, 60L), SquareGreen = c(100L, 100L, 100L, 90L,
85L, 85L), TriangleBlue = c(60L, 55L, 65L, 65L, 60L, 40L), TriangleRed = 
c(80L,
45L, 60L, 50L, 40L, 35L), TriangleGreen = c(75L, 45L, 55L, 50L, 45L,
50L)), .Names = c("Subject", "CircleBlue", "CircleRed", "CircleGreen",
"SquareBlue", "SquareRed", "SquareGreen", "TriangleBlue", "TriangleRed",
"TriangleGreen"), row.names = c(NA, 6L), class = "data.frame")

Regarding the ANOVA, OK--I see it now (I was looking for the words 
"Repeated Measures", which weren't there...).  I didn't notice the 
example till I ran each one.  It looks like a great program, though I'll 
have to figure out the reshape issue before I can use ezANOVA.  Many 
thanks for your help!

John

John L. Woodard, Ph.D.

Associate Professor of Psychology

Wayne State University

5057 Woodward Ave., 7th Floor

Detroit, MI 48202


Voice: 313-577-5838

Fax: 313-577-7636

e-mail: john.wood...@wayne.edu


On 7/17/10 2:40 PM, Tal Galili wrote:
> Hi John,
>
> Try posting a sample of your data in reply to this e-mail by using:
>
> dput(head(accuracy))
>
> And me (or someone else) will be sure to fix your command.
>
> Regarding the ANOVA, read more :)
>
> 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 Sat, Jul 17, 2010 at 8:03 PM, jlwoodard  > wrote:
>
>
> Tal,
>  Thanks for the information.
>
>  I actually did read through the help for the reshape package,
> though being
> relatively new to R, I don't quite understand the ins and outs of the
> command.
>
> I tried using the melt command:
> x<-melt(accuracy,id='Subject')
>
> but, it didn't give me anything different than the stacked
> command.  I'm
> trying to get two columns to indicate the Shape and Color.
>
> Thanks also for this information on ezANOVA.  It looks very promising,
> though I didn't see an example of repeated measures ANOVA in the
> help file.
>
> Best regards,
>
> John
> --
> View this message in context:
> 
> http://r.789695.n4.nabble.com/Help-with-Reshaping-from-Wide-to-Long-tp2292462p2292524.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] save plot

2010-07-17 Thread Uwe Ligges



On 17.07.2010 20:52, linda.s wrote:

Open a new device before plotting, do your plotting, close the device.

For example, using a PDF device via pdf():

pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,
version = "1.4", onefile = TRUE)
for(i in 1:10) {
y<- rnorm(100)
x<- rnorm(100)
plot(y ~ x)
}
dev.off()

The last line (dev.off() is very important as the file will not be valid
pdf without closing the device.

HTH

G


I got the error:

pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,

+version = "1.4", onefile = TRUE)

for(i in 1:10) {

+y<- rnorm(100)
+x<- rnorm(100)
+plot(y ~ x)
+ }

dev.off()

null device
   1





Which error??? Everyting went fine, as far as I can see.

Uwe Ligges




__
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] save plot

2010-07-17 Thread linda.s
> Open a new device before plotting, do your plotting, close the device.
>
> For example, using a PDF device via pdf():
>
> pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,
>    version = "1.4", onefile = TRUE)
> for(i in 1:10) {
>    y <- rnorm(100)
>    x <- rnorm(100)
>    plot(y ~ x)
> }
> dev.off()
>
> The last line (dev.off() is very important as the file will not be valid
> pdf without closing the device.
>
> HTH
>
> G

I got the error:
> pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,
+version = "1.4", onefile = TRUE)
> for(i in 1:10) {
+y <- rnorm(100)
+x <- rnorm(100)
+plot(y ~ x)
+ }
> dev.off()
null device
  1

__
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] plot month and year

2010-07-17 Thread linda.s
i am a beginner and tried to provide a reproducible example. is the
following style a correct one?
Thanks.

> dput(unem)
> structure(list(a = c(10.2, 9.8, 9.5, 8.3, 7.9, 8.8, 8.9, 9.3,
+ 9.2, 9, 9.5, 12, 15.7, 16.1, 15.4, 14.7, 13.9, 15.3, 15.4, 15,
+ 13.8, 13.9, 14.1, 15.8), b = c(7, 6.7, 6.8, 6.1, 6.5, 7.4, 8.4,
+ 7.6, 7.5, 7.5, 7.8, 9.1, 11.2, 12.1, 12.2, 11.5, 11.5, 11.7,
+ 11.7, 11.2, 10.3, 10.7, 10.8, 11.6), c = c(6.5, 5.9, 5.9, 5.4,
+ 6.1, 6.6, 7.6, 7.2, 6.9, 7.1, 7.7, 8.4, 11.6, 11.3, 11, 10.9,
+ 12, 12.7, 12.8, 11, 10, 10.1, 10.3, 11.1), d = c(8.3, 7.6, 7.3,
+ 6.2, 6.2, 7.1, 8.5, 8.3, 7.7, 7.3, 8, 10.2, 13.9, 14.9, 14.8,
+ 13.1, 13.1, 13.3, 13.3, 12.1, 11.1, 11.3, 11.6, 12.7)), .Names = c("a",
+ "b", "c", "d"), class = "data.frame", row.names = c("JAN_08",
+ "FEB_08", "MAR_08", "APR_08", "MAY_08", "JUN_08", "JULY_08",
+ "AUG_08", "SEP_08", "OCT_08", "NOV_08", "DEC_08", "JAN_09", "FEB_09",
+ "MAR_09", "APR_09", "MAY_09", "JUN_09", "JUL_09", "AUG_09", "SEP_09",
+ "OCT_09", "NOV_09", "DEC_09"))
   abcd
JAN_08  10.2  7.0  6.5  8.3
FEB_08   9.8  6.7  5.9  7.6
MAR_08   9.5  6.8  5.9  7.3
APR_08   8.3  6.1  5.4  6.2
MAY_08   7.9  6.5  6.1  6.2
JUN_08   8.8  7.4  6.6  7.1
JULY_08  8.9  8.4  7.6  8.5
AUG_08   9.3  7.6  7.2  8.3
SEP_08   9.2  7.5  6.9  7.7
OCT_08   9.0  7.5  7.1  7.3
NOV_08   9.5  7.8  7.7  8.0
DEC_08  12.0  9.1  8.4 10.2
JAN_09  15.7 11.2 11.6 13.9
FEB_09  16.1 12.1 11.3 14.9
MAR_09  15.4 12.2 11.0 14.8
APR_09  14.7 11.5 10.9 13.1
MAY_09  13.9 11.5 12.0 13.1
JUN_09  15.3 11.7 12.7 13.3
JUL_09  15.4 11.7 12.8 13.3
AUG_09  15.0 11.2 11.0 12.1
SEP_09  13.8 10.3 10.0 11.1
OCT_09  13.9 10.7 10.1 11.3
NOV_09  14.1 10.8 10.3 11.6
DEC_09  15.8 11.6 11.1 12.7
> attach(unem)
The following object(s) are masked from 'unem (position 3)':

a, b, c, d
The following object(s) are masked from 'unem (position 4)':

a, b, c, d
> unem1 <- ts(unem$a, start = c(2008, 1), freq = 12)
> plot(unem1, type = "o")

Question:
The X axis on the plot now starts from 2008.0; Since the data starts
from January 2008, can I make it 2008.1, and also show 2009.12 on the
axis?
Thanks.

On Wed, Jul 14, 2010 at 9:49 AM, Achim Zeileis  wrote:
> You do not provide a reproducible example, as the posting guide asks you to.
> But I guess that your time series setup using ts() is insufficient, see ?ts.
> If the data starts in January 2008, why do you tell R that it starts in 1?
> Presumably you have monthly data and
>
>  unem1 <- ts(unem$a, start = c(2008, 1), freq = 12)
>  plot(unem1, type = "o")
>
> is what you want.
>
> hth,
> Z
>
> On Wed, 14 Jul 2010, linda.s wrote:
>
>> R Code begins
>> unem=read.csv("book5.csv",header=T,row.names=1)
>> attach(unem)
>> unem1=ts(unem$a, start=1)
>> ts.plot(unem1,main="a")
>> points(unem1,type="o")
>> R Code ends
>>
>> because the time starts at JAN_08 and ends on DEC_09, how to make the
>> y axis in the plot show month starting from JAN_08 instead of having
>> the current
>> ugly appearance (5, 10, 15, 20,?)?
>>
>> On Wed, Jul 14, 2010 at 9:20 AM, linda.s  wrote:
>>>
>>> R Code begins
>>> unem=read.csv("book5.csv",header=T,row.names=1)
>>> attach(unem)
>>> unem1=ts(unem$Allen, start=1)
>>> ts.plot(unem1,main="Allen")
>>> points(unem1,type="o")
>>> R Code ends
>>>
>>> because the time starts at JAN_08 and ends on DEC_09, how to make the
>>> y axis in the plot show month starting from JAN_08 instead of having
>>> the current
>>> ugly appearance (5, 10, 15, 20,?)?
>>>
>>
>

__
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 Reshaping from Wide to Long

2010-07-17 Thread Tal Galili
Hi John,

Try posting a sample of your data in reply to this e-mail by using:

dput(head(accuracy))

And me (or someone else) will be sure to fix your command.

Regarding the ANOVA, read more :)

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 Sat, Jul 17, 2010 at 8:03 PM, jlwoodard  wrote:

>
> Tal,
>  Thanks for the information.
>
>  I actually did read through the help for the reshape package, though being
> relatively new to R, I don't quite understand the ins and outs of the
> command.
>
> I tried using the melt command:
> x<-melt(accuracy,id='Subject')
>
> but, it didn't give me anything different than the stacked command.  I'm
> trying to get two columns to indicate the Shape and Color.
>
> Thanks also for this information on ezANOVA.  It looks very promising,
> though I didn't see an example of repeated measures ANOVA in the help file.
>
> Best regards,
>
> John
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Help-with-Reshaping-from-Wide-to-Long-tp2292462p2292524.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.


[R] Help with a problem

2010-07-17 Thread Michael Hess
Hello R users,

I am a researcher at the University of Michigan looking for a solution to an R 
problem.  I have loaded my data in from a mysql database and it looks like this

> data
   ds c1 c2
1  2010-04-03100   0
2  2010-04-30  11141  15
3  2010-05-01  3  16
4  2010-05-02   7615  14
5  2010-05-03   6910  17
6  2010-05-04   5035  3
7  2010-05-05   3007  15
8  2010-05-06   4  14
9  2010-05-07   8335  17
10 2010-05-08   2897  13
11 2010-05-09   6377  17
12 2010-05-10   3177  17
13 2010-05-11   7946  15
14 2010-05-12   8705  0
15 2010-05-13   9030  16
16 2010-05-14   8682  16
17 2010-05-15   8440  15


What I am trying to do is sort by ds, and take rows 1,7, see if c1 is at least 
100 AND c2 is at least 8. If it is not, start with check rows 2,8 and if not 
there 3,9until it loops over the entire file.   If it finds a set that 
matches, set a new variable equal to 1, if never finds a match, set it equal to 
0.

I have done this in stata but on this project we are trying to use R.  Is this 
something that can be done in R, if so, could someone point me in the correct 
direction.

Thanks,

Michael Hess
University of Michigan
Health System

**
Electronic Mail is not secure, may not be read every day, and should not be 
used for urgent or sensitive issues 

__
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] cca in ade4

2010-07-17 Thread Gavin Simpson
On Sat, 2010-07-17 at 13:31 +0800, elaine kuo wrote:
> Dear List,
> 
> I used spec and envi for cca in ade4. (both are data.frame)
> 
> However, there is a message telling that
> error in if (nf > rank) nf <- rank R
> missing value in  TRUE/FALSE
> 
> Please kindly help how to modify the code below.
> Thank you.

We can't possibly diagnose the problem as we don't have spec or envi.

If this is anything like the same data used in the vegan:::cca question
posted earlier, then you have samples with no species data recorded.
Drop those and fit the model again and see if you get any further.

HTH

G

> 
> Elaine
> 
> 
> code
> rm(list=ls())
> spec <-read.csv("c:/migration/M_R_20100718_winterM_spec_vegan.csv",header=T,
> row.names=1)
> dim(spec)
> spec[1,]
> 
> envi <-read.csv("c:/migration/M_R_20100718_winterM_envi_vegan.csv",header=T,
> row.names=1)
> dim(envi)
> envi[1,]
> 
> library(ade4)
> 
> w.cca  <-  cca(spec, envi, scan=TRUE)
> 
>   [[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.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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 required for cca in ade4

2010-07-17 Thread Gavin Simpson
On Sat, 2010-07-17 at 13:15 +0800, elaine kuo wrote:
> Dear List,
> 
> I tried to conduct cca using csv data but failed.
> The message said that data.frame is required.
> 
> Please kindly share how to convert a csv-imported file to a data.frame.
> Thank you.

It was a dataframe. You aren't giving ade4:::cca a dataframe because you
are extracting a single component of that data frame in your call.

Witness:

> dat <- data.frame(X = rnorm(10), Y = rnorm(10))
> class(dat$X)
[1] "numeric"
> is.data.frame(dat$X)
[1] FALSE

The reason ade4:::cca expects a dataframe is that CCA is generally used
for a *multivariate* response. Here you are supplying a univariate
response.

HTH

G

> 
> Elaine
> 
> code
> 
> rm(list=ls())
> spec <-read.csv("c:/migration/M_R_20100718_winterM_spec_vegan.csv",header=T,
> row.names=1)
> dim(spec)
> spec[1,]
> 
> envi <-read.csv("c:/migration/M_R_20100718_winterM_envi_vegan.csv",header=T,
> row.names=1)
> dim(envi)
> envi[1,]
> 
> library(ade4)
> 
> w.cca  <-  cca(spec$WinterM_ratio, envi, scan=TRUE)
> error in cca(spec$WinterM_ratio, envi, scan = FALSE) :
>   data.frame expected
> 
>   [[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.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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] cca in vegan (formula instead of community matrix data)

2010-07-17 Thread Gavin Simpson
On Sat, 2010-07-17 at 12:44 +0800, elaine kuo wrote:
> Dear List,
> 
> I tried to do cca based on species data and environmental variables (formula
> instead of community data).
> However, there was an error saying row sums must be >0.
> I searched the previous related messages but found few solutions.
> Please kindly help and thank you in advance.

You have samples that have no species observed at all. As such is it
impossible to anything with these samples. Remove them and then fit your
model

datam <- with(datam, datam[rowSums(WinterM_ratio) > 0, ])
m.cca <- cca(WinterM_ratio ~ topo_mean + coast + prec_max +
 temp_min + evi_min,  datam)

However, I have one question for you; is WinterM_ratio a univariate
response (single column)? If it is, why do you want to analyse it using
CCA? CCA is generally used for multivariate species responses.

Finally; you might want to do something about that warning message.
Either your R is out of date or your package library is. If you are
using R2.11-x then run this:

update.packages(checkBuilt = TRUE)

to update the packages to the newest version of R; there have been lots
of changes in the way help is processed / made available that might not
be available if using packages built under earlier versions of R.

HTH

G

> 
> 
> code
> This is vegan 1.17-3
> Warning message:
> package 'vegan' was built under R version 2.10.1
> 
> rm(list=ls())
> library(vegan)
> 
> datam <-read.csv("c:/migration/M_R_20100707_winterM.csv",header=T,
> row.names=1)
> dim(datam)
> datam[1,]
> 
> m.cca  <-
>  cca(datam$WinterM_ratio~datam$topo_mean+datam$coast+datam$prec_max
> +datam$temp_min+datam$evi_min,  datam)
> 
> error in  cca.default(d$X, d$Y, d$Z) :
>   All row sums must be >0 in the community data matrix
> 
>   [[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.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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] save plot

2010-07-17 Thread Gavin Simpson
On Fri, 2010-07-16 at 11:17 -0400, linda.s wrote:
> I made a plot, but after I made a second plot, the previous plot was
> gone. How can I save all the plots in a file (I do not manually copy
> and paste them one by one)?
> Thanks.
> Linda

[I presume you addressed this to Duncan Murdoch for a good reason???]

Open a new device before plotting, do your plotting, close the device.

For example, using a PDF device via pdf():

pdf("my_plots.pdf", height = 8, width = 8, pointsize = 10,
version = "1.4", onefile = TRUE)
for(i in 1:10) {
y <- rnorm(100)
x <- rnorm(100)
plot(y ~ x)
}
dev.off()

The last line (dev.off() is very important as the file will not be valid
pdf without closing the device.

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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] multivariate graphs, averaging on some vars

2010-07-17 Thread Uwe Ligges



On 17.07.2010 12:39, skan wrote:


Thank you very much, I'll try it.

About my question on graphics with colour...

Imagine I have a function y=y(x1, x2, x3), I'd need four dimensions to graph
x1, x2, x3, and y.
My idea is to use the typical 3D plot adding the information of the
additional fourth variable 'y to the colour of the point.
What package do you recommend to do it?
Any interactive plotting package?


As has been said before:

cloud() in lattice, scatterplot3d() in scatterpülo3d or plot3d() in rgl, 
the latter also for "interactive" rotation of the whole picture


Uwe Ligges




thx


__
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] Identify points (was Plot error)

2010-07-17 Thread Peter Ehlers

On 2010-07-17 9:50, James Platt wrote:

The other question I have:

Is there any way to link the data point on the graph to the name of a
row

i.e in my table:

name value_1 value_2
bill   14
ben  2   2
jane 3   1

I click on the data point at 2,2 and it would read out ben



Check out HWidentify or HTKidentify in pkg:TeachingDemos.

  -Peter Ehlers

__
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 Reshaping from Wide to Long

2010-07-17 Thread jlwoodard

Tal,
  Thanks for the information.

 I actually did read through the help for the reshape package, though being
relatively new to R, I don't quite understand the ins and outs of the
command.

I tried using the melt command:
x<-melt(accuracy,id='Subject')

but, it didn't give me anything different than the stacked command.  I'm
trying to get two columns to indicate the Shape and Color.

Thanks also for this information on ezANOVA.  It looks very promising,
though I didn't see an example of repeated measures ANOVA in the help file.

Best regards,

John
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-Reshaping-from-Wide-to-Long-tp2292462p2292524.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] Bug 14340 - Symbols() plots with wrongly scaled y-axis

2010-07-17 Thread baptiste auguie
Hi,

try adding asp=1 in symbols() to set the aspect ratio of the plotting
region to 1.

HTH,

baptiste


On 17 July 2010 18:21,   wrote:
> Hello, I submitted this bug report to r-core and got a rejection saying I
> should post to r-help.
> This is my first time ever submitting a bug report, so forgive me if I'm
> using some wrong format.
>
> So, here's my bug report:
>
> Component:  Graphics
> OS:  Mac OS 10.5.8, X11 XQuartz 2.5.0
> Summary:
> In the symbols function of the graphics package, scaling of the y-axis is
> wrong, causing symbols that should be separate to overlap in the y-direction
> (x-direction is okay).
>
> Description:
> Attached is a plot that should be of circles of radius 5 spaced exactly with
> their centers 10 apart in both x and y directions, so that they should be
> packed with the circles touching edge-to-edge.  In the y-direction, somehow
> the
> plotting scale is wrong such that the circles overlap.  I've plotted
> horizontal
> and vertical lines at x=45,50,55, and y=45,50,55, as well as two squares
> with
> side=10.  The squares are also overlapping in the vertical scale.
>
> Steps to reproduce:
> Here are the commands I used to generate this:
>
> maptrees = function(n=1,a=1,b=1,h=2,view="horz",fg=1,np=FALSE,add=TRUE) {
>    #n = tree density (#/m2)
>    #a = crown horizontal radius (m)
>    #b = crown vertical radius (m)
>    #h = tree height (m)
>    #view = "horz", "vert"
>    #np = TRUE if new plot desired
>
>    if (np) {
>        quartz(width=6, height=6)
>        add=!np
>        }
>
>    dx = sqrt(1/n)
>    x = rep(dx*(1:10),10)
>    y = as.vector(t(matrix(x,10,10)))
>
>    if (view=="horz") {
>        circles = rep(a,100)
>        symbols(x=x,y=y,circles=circles, fg=fg,inches=FALSE,add=add)
>        points(x,y,pch='.')
>        mtext(paste("n=",n,", d=",dx,", a=",a))
>    } else {
>        #mtext(paste("n=",n,", d=",dx,", a=",a,", b=",b,", h=",h))
>
>    }
>    return(cbind(x,y,circles))
>    }
>
> Commands:
>    junk =maptrees(n= 0.01, a=5,add=FALSE)
>    lines(c(0,100),c(45,45))
>    lines(c(0,100),c(55,55))
>    lines(c(0,100),c(50,50))
>
>    lines(c(50,50),c(0,100))
>    lines(c(55,55),c(0,100))
>    lines(c(45,45),c(0,100))
>    symbols(50,50,squares=10,fg=2, add=TRUE,inches=FALSE)
>    symbols(50,60,squares=10,fg=2, add=TRUE,inches=FALSE)
>
> Actual results:  See attached plot.
> Expected results:  The circles and squares in the plot should be
> edge-to-edge,
> not overlapping in the vertical direction.
> Build Date and Platform: Build 2010-7-16 on Mac 10.5.8
>
>
> I am using a MacBookPro:
> platform       x86_64-apple-darwin9.8.0
> arch           x86_64
> os             darwin9.8.0
> system         x86_64, darwin9.8.0
> status
> major          2
> minor          11.1
> year           2010
> month          05
> day            31
> svn rev        52157
> language       R
> version.string R version 2.11.1 (2010-05-31)
>
> I could not find another bug report of this problem.
>
> Thanks to anyone who can help.
>
> Nancy Kiang
>
> --
>
>
> __
> 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. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
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] RWinEdt and WinEdt 6.0

2010-07-17 Thread Uwe Ligges



On 15.07.2010 16:45, Christopher Desjardins wrote:

Hi,
I am curious if the status of RWinEdt and WinEdt 6.0 has changed since this
thread
http://r.789695.n4.nabble.com/RWinEdt-in-WinEdt-6-td2174285.html


Unfortunately not due to lack of time. But planned for the summer.

Uwe




Thanks for the help (especially Uwe Ligges for writing RWinEdt).
Chris

[[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] Send code to R from WinEdt55

2010-07-17 Thread Uwe Ligges



On 15.07.2010 16:42, YANG, Richard ChunHSi wrote:

R Gurus:

This sounds not a FAQ. I upgraded WinEdt from 5.4 to 5.5 ,
following load RWinEdt, R-WinEdt editor appears. There are more menu
items and task icons in this version, but I failed to find a pull down
menu or task icon to send code to R.

What did I miss?


You need to reinstall RWinEdt in that case.

Uwe Ligges






sessionInfo()

R version 2.11.0 (2010-04-22)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252
LC_MONETARY=English_Canada.1252
[4] LC_NUMERIC=CLC_TIME=English_Canada.1252

attached base packages:
[1] grDevices datasets  splines   graphics  stats tcltk utils
methods   base

other attached packages:
[1] RWinEdt_1.8-2   svSocket_0.9-48 R2HTML_2.1  Hmisc_3.8-1
survival_2.35-8

loaded via a namespace (and not attached):
[1] cluster_1.12.3 grid_2.11.0lattice_0.18-5 svMisc_0.9-57
TinnR_1.0.3tools_2.11.0

Richard








[[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] Bug 14340 - Symbols() plots with wrongly scaled y-axis

2010-07-17 Thread nancynyk
Hello, I submitted this bug report to r-core and got a rejection 
saying I should post to r-help.
This is my first time ever submitting a bug report, so forgive me if 
I'm using some wrong format.


So, here's my bug report:

Component:  Graphics
OS:  Mac OS 10.5.8, X11 XQuartz 2.5.0
Summary:
In the symbols function of the graphics package, scaling of the y-axis is
wrong, causing symbols that should be separate to overlap in the y-direction
(x-direction is okay).

Description:
Attached is a plot that should be of circles of radius 5 spaced exactly with
their centers 10 apart in both x and y directions, so that they should be
packed with the circles touching edge-to-edge.  In the y-direction, somehow the
plotting scale is wrong such that the circles overlap.  I've plotted horizontal
and vertical lines at x=45,50,55, and y=45,50,55, as well as two squares with
side=10.  The squares are also overlapping in the vertical scale.

Steps to reproduce:
Here are the commands I used to generate this:

maptrees = function(n=1,a=1,b=1,h=2,view="horz",fg=1,np=FALSE,add=TRUE) {
#n = tree density (#/m2)
#a = crown horizontal radius (m)
#b = crown vertical radius (m)
#h = tree height (m)
#view = "horz", "vert"
#np = TRUE if new plot desired

if (np) {
quartz(width=6, height=6)
add=!np
}

dx = sqrt(1/n)
x = rep(dx*(1:10),10)
y = as.vector(t(matrix(x,10,10)))

if (view=="horz") {
circles = rep(a,100)
symbols(x=x,y=y,circles=circles, fg=fg,inches=FALSE,add=add)
points(x,y,pch='.')
mtext(paste("n=",n,", d=",dx,", a=",a))
} else {
#mtext(paste("n=",n,", d=",dx,", a=",a,", b=",b,", h=",h))

}
return(cbind(x,y,circles))
}

Commands:
junk =maptrees(n= 0.01, a=5,add=FALSE)
lines(c(0,100),c(45,45))
lines(c(0,100),c(55,55))
lines(c(0,100),c(50,50))

lines(c(50,50),c(0,100))
lines(c(55,55),c(0,100))
lines(c(45,45),c(0,100))
symbols(50,50,squares=10,fg=2, add=TRUE,inches=FALSE)
symbols(50,60,squares=10,fg=2, add=TRUE,inches=FALSE)

Actual results:  See attached plot.
Expected results:  The circles and squares in the plot should be edge-to-edge,
not overlapping in the vertical direction.
Build Date and Platform: Build 2010-7-16 on Mac 10.5.8


I am using a MacBookPro:
platform   x86_64-apple-darwin9.8.0
arch   x86_64
os darwin9.8.0
system x86_64, darwin9.8.0
status
major  2
minor  11.1
year   2010
month  05
day31
svn rev52157
language   R
version.string R version 2.11.1 (2010-05-31)

I could not find another bug report of this problem.

Thanks to anyone who can help.

Nancy Kiang

--

__
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] Computing the power of a matrix efficiently and accurately

2010-07-17 Thread Miguel Lacerda
Good day,

I would like to know if there is an efficient and accurate method for
computing the power of a tridiagonal matrix in R? The "obvious" method would
be eigen-decomposition, but I find that this is not very accurate, probably
because the dimensions of the matrix I am considering are large and the
eigenvectors are not well approximated. Here is an example of what I am
trying to do:

set.seed(1234)

m=500 # dimension of my matrix

X=diag(rnorm(500,20,2)) # set up tridiagonal matrix
for(i in 1:(m-1))
{
  X[i,i+1]=rnorm(1,5,1)
  X[i+1,i]=rnorm(1,5,1)
}

n=100 # the power of the matrix X i.e. X^n = X%*%X%*%X ... n times (n = 1000
in my application)

X_eigen=eigen(X)
P=X_eigen$vectors
P_inv=solve(P)
d=X_eigen$values

M=diag(m)

res_mult=c()
res_eigen=c()
for(i in 1:n)
{
# straightforward multiplication...
M = M%*%X
res_mult = rbind(res_mult, M[m,])

# eigen-decomposition...
res_eigen = rbind(res_eigen, (P%*%diag(d^i)%*%P_inv)[m,])
}

# Look how the diagonal element X[m,m] changes with successive powers:
> res_mult[1,m]
[1] 23.45616
> res_eigen[1,m]
[1] 23.45616
> res_mult[n,m]
[1] 3.844556e+148
> res_eigen[n,m]
[1] 3.844556e+148

# Look how the off-diagonal element X[m,1] changes with successive powers:
> res_mult[1,1]
[1] 0
> res_eigen[1,1]
[1] 1.942362e-16
> res_mult[n,1]
[1] 0
> res_eigen[n,1]
[1] 1.469650e+132


Notice how poorly the off-diagonal element is approximated by the
eigen-decomposition!! I am aware of the mtx.exp() function in the Malmig
package, although repeatedly calling this function is not efficient as I
need to extract the m-th row of the matrix raised to each power from 1:n.

Any suggestions? Could I possibly exploit the fact that X is tridiagonal in
my application?

Thanks!
Miguel

-- 
Miguel Lacerda
Department of Statistical Sciences
University of Cape Town

[[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] Multinomial logistic regression in complex surveys

2010-07-17 Thread Joshua Wiley
I would take a look at mlogit() in package mlogit or vglm() with
family = multinomial in package VGAM.

HTH,

Josh

2010/7/16 Rosario Austral :
> Dear R-list members,
> I´m using the package "survey" and I need to find a function for
> multinomial logistic regression in a complex design. The functions that
> I see are only for dicotomic and ordinal variables.
> Thank you!
> Rosario Austral
>
>
>
>
> 
> De: "r-help-requ...@r-project.org" 
> Para: rosarioaust...@yahoo.com.ar
> Enviado: viernes, 16 de julio, 2010 16:06:35
> Asunto: Welcome to the "R-help" mailing list (Digest mode)
>
> Bienvenido a la lista de distribución R-help@r-project.org
>
>
> Para mandar un mensaje a esta lista, envíelo a:
>
>  r-h...@r-project.org
>
> Puede obtener información general sobre la lista en:
>
>  https://stat.ethz.ch/mailman/listinfo/r-help
>
> Si alguna vez desea anular  su  subscripción o cambiar las  opciones
> de la misma (p.ej.: cambiarse a modo resumido o no, cambiar su clave,
> etc.), consulte la página de su subscripción en:
>
>  https://stat.ethz.ch/mailman/options/r-help/rosarioaustral%40yahoo.com.ar
>
>
>
> También puede realizar estos cambios por medio de correo electrónico,
> enviando un mensaje a:
>
>  r-help-requ...@r-project.org
>
> indicando la palabra "help" en el asunto (no ponga las comillas) o en
> el cuerpo del mensaje. Se le devolverá un mensaje con instrucciones.
>
> Tiene que saber su clave para poder cambiar sus opciones (incluido el
> cambio de la propia clave) o para anular su subscripción. Su clave es:
>
>  fiona
>
> Normalmente, Mailman le recordará  mensualmente las claves  que tenga
> en las listas de distribución de r-project.org, aunque si lo prefiere,
> puede inhabilitar este comportamiento.  El recordatorio también
> incluirá instrucciones sobre como anular su subscripción o cómo
> cambiar los parámetros de subscripción. En la página de opciones hay
> un botón que le enviará un mensaje de correo electrónico con su clave.
>
>
>
>
>        [[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.
>
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] Help with Reshaping from Wide to Long

2010-07-17 Thread Tal Galili
Hi John,

1) Read the help for the "reshape" package.  What you want is to use the
"melt" function.
2) There are various ways of doing Repeated measures Anova in R, you might
want to have a look at this:
http://www.r-statistics.com/2010/04/repeated-measures-anova-with-r-tutorials/
(I especially like the "ezANOVA" function)

Cheers,
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 Sat, Jul 17, 2010 at 6:42 PM, jlwoodard  wrote:

>
> I am trying to reshape data that are in the wide format into the long
> format.
> The design is a repeated-measures design, which combined 3 levels of shape
> (circle, square, triangle) with 3 levels of color (Blue, Red, Green), for a
> total of 9 variables.  The wide data look like this (sorry I couldn't get
> the columns to line up quite right:
>
>   Subject CircleBlue CircleRed CircleGreen SquareBlue SquareRed SquareGreen
> TriangleBlue TriangleRed TriangleGreen
> 1  101 95100   100 95100   100
> 60 8075
> 2  102 80 90   100 85 90   100
> 55 4545
>
> I would like to convert the data to the following format so that I could do
> a repeated measures ANOVA:
>
> Accuracy  Subject   Shape   Color
> 95   subj101Circle  Blue
> 80   subj102Circle  Blue
> 100  subj101Circle  Red
> 90   subj102Circle  Red
> 100  subj101Circle  Green
> 100  subj102Circle  Green
> 95   subj101Square   Blue
> 85   subj102Square   Blue
> 100  subj101Square   Red
> 90   subj102Square   Red
> 100  subj101Square   Green
> 100  subj102Square   Green
> 60   subj101Triangle  Blue
> 55   subj102Triangle  Blue
> 80   subj101Triangle  Red
> 45   subj102Triangle  Red
> 75   subj101Triangle  Green
> 45   subj102Triangle  Green
>
> I've been able to accomplish the task using the stack command, together
> with
> some fairly lengthy code to reorganize the stacked data frame.  Is it
> possible to use the reshape command to accomplish this task in a more
> straightforward manner?   Many thanks in advance!
>
> John
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Help-with-Reshaping-from-Wide-to-Long-tp2292462p2292462.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] Plot error

2010-07-17 Thread James Platt
The other question I have:

Is there any way to link the data point on the graph to the name of a  
row

i.e in my table:

name value_1 value_2
bill   14
ben  2   2
jane 3   1

I click on the data point at 2,2 and it would read out ben

thanks again.

James

On 17 Jul 2010, at 16:43, James Platt wrote:

> Hi both,
>
> Sorry my mistake I was trying to make a graph from another file I  
> called seq, I decided to use test as an example, but mixed up the two.
>
> I have got this to work now thanks.
>
> after doing this:
>
>> #Assign columns to variables 'x' and 'y'
>> x <- test[ , "value_1"]
>> y <- test[ , "value_2"]
>>
>> #plot
>> plot(x, y)
>
> cheers,
>
> James
>
> On 17 Jul 2010, at 16:07, Joshua Wiley wrote:
>
>> Hi James,
>>
>> I believe the issue has to do with the values you assigned to 'x' and
>> 'y'.  You call the function c() on seq["value_1"], but you assigned
>> your data not to 'seq' but to 'test'.  You need to use the variable
>> name that you assigned your data to (as a side note seq() is a
>> function, so you should probably avoid using that as name to store
>> data anyways).  Also you have data in a variable 'test' that has both
>> rows and columns, so the preferred way to access it is
>> variablename[rowname/number , columnname/number].  In your case that
>> would be test[ , "value_1"].  I left the space before the comma blank
>> to indicate include all rows.  It does technically work in this case
>> to simply write test["value_1"] but this is prone to error in other
>> situations.  This is my best guess as to what you want to do:
>>
>> #Read in Data
>> #(just to make sure were on the same page)
>> test <- structure(list(name = structure(c(2L, 1L, 3L),
>> .Label = c("ben", "bill", "jane"), class = "factor"),
>> value_1 = 1:3, value_2 = c(4L, 2L, 1L)),
>> .Names = c("name", "value_1", "value_2"),
>> class = "data.frame", row.names = c(NA, -3L))
>>
>> test # print so we can look at it
>>
>> #Assign columns to variables 'x' and 'y'
>> x <- test[ , "value_1"]
>> y <- test[ , "value_2"]
>>
>> #plot
>> plot(x, y)
>>
>> #Or using data directly
>> plot(test[ , "value_1"], test[ , "value_2"])
>>
>> Cheers,
>>
>> Josh
>>
>> On Sat, Jul 17, 2010 at 7:50 AM, James Platt > > wrote:
>>> Hi guys,
>>>
>>> I am a newbie to R, so apologies in advance.
>>>
>>> I created this simple table in excel, saved in tab delimited .txt:
>>>
>>> name value_1 value_2
>>> 1 bill   14
>>> 2 ben  2   2
>>> 3 jane 3   1
>>>
>>>
 test <-read.table("\path\to\file", sep="\t", header=TRUE)
>>>
 x <-c(seq["value_1"])
 y <-c(seq["value_2"])
>>>
 plot(x,y)
>>>
>>> and i get this error
>>>
>>> Error in xy.coords(x, y, xlabel, ylabel, log) :
>>> (list) object cannot be coerced to type 'double'
>>>
>>> What does this mean and how do i fix it?
>>>
>>> Thanks for the help, James
>>>
>>> __
>>> 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.
>>>
>>
>>
>>
>> -- 
>> Joshua Wiley
>> Ph.D. Student, Health Psychology
>> University of California, Los Angeles
>> http://www.joshuawiley.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] Plot error

2010-07-17 Thread James Platt

Hi both,

Sorry my mistake I was trying to make a graph from another file I  
called seq, I decided to use test as an example, but mixed up the two.


I have got this to work now thanks.

after doing this:


#Assign columns to variables 'x' and 'y'
x <- test[ , "value_1"]
y <- test[ , "value_2"]

#plot
plot(x, y)


cheers,

James

On 17 Jul 2010, at 16:07, Joshua Wiley wrote:


Hi James,

I believe the issue has to do with the values you assigned to 'x' and
'y'.  You call the function c() on seq["value_1"], but you assigned
your data not to 'seq' but to 'test'.  You need to use the variable
name that you assigned your data to (as a side note seq() is a
function, so you should probably avoid using that as name to store
data anyways).  Also you have data in a variable 'test' that has both
rows and columns, so the preferred way to access it is
variablename[rowname/number , columnname/number].  In your case that
would be test[ , "value_1"].  I left the space before the comma blank
to indicate include all rows.  It does technically work in this case
to simply write test["value_1"] but this is prone to error in other
situations.  This is my best guess as to what you want to do:

#Read in Data
#(just to make sure were on the same page)
test <- structure(list(name = structure(c(2L, 1L, 3L),
.Label = c("ben", "bill", "jane"), class = "factor"),
value_1 = 1:3, value_2 = c(4L, 2L, 1L)),
.Names = c("name", "value_1", "value_2"),
class = "data.frame", row.names = c(NA, -3L))

test # print so we can look at it

#Assign columns to variables 'x' and 'y'
x <- test[ , "value_1"]
y <- test[ , "value_2"]

#plot
plot(x, y)

#Or using data directly
plot(test[ , "value_1"], test[ , "value_2"])

Cheers,

Josh

On Sat, Jul 17, 2010 at 7:50 AM, James Platt > wrote:

Hi guys,

I am a newbie to R, so apologies in advance.

I created this simple table in excel, saved in tab delimited .txt:

name value_1 value_2
1 bill   14
2 ben  2   2
3 jane 3   1



test <-read.table("\path\to\file", sep="\t", header=TRUE)



x <-c(seq["value_1"])
y <-c(seq["value_2"])



plot(x,y)


and i get this error

Error in xy.coords(x, y, xlabel, ylabel, log) :
 (list) object cannot be coerced to type 'double'

What does this mean and how do i fix it?

Thanks for the help, James

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





--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] Help with Reshaping from Wide to Long

2010-07-17 Thread jlwoodard

I am trying to reshape data that are in the wide format into the long format. 
The design is a repeated-measures design, which combined 3 levels of shape
(circle, square, triangle) with 3 levels of color (Blue, Red, Green), for a
total of 9 variables.  The wide data look like this (sorry I couldn't get
the columns to line up quite right:

   Subject CircleBlue CircleRed CircleGreen SquareBlue SquareRed SquareGreen
TriangleBlue TriangleRed TriangleGreen 
1  101 95100   100 95100   100  
  
60 8075   
2  102 80 90   100 85 90   100  
  
55 4545   

I would like to convert the data to the following format so that I could do
a repeated measures ANOVA:

Accuracy  Subject   Shape   Color
95   subj101Circle  Blue
80   subj102Circle  Blue
100  subj101Circle  Red
90   subj102Circle  Red
100  subj101Circle  Green
100  subj102Circle  Green
95   subj101Square   Blue
85   subj102Square   Blue
100  subj101Square   Red
90   subj102Square   Red
100  subj101Square   Green
100  subj102Square   Green
60   subj101Triangle  Blue
55   subj102Triangle  Blue
80   subj101Triangle  Red
45   subj102Triangle  Red
75   subj101Triangle  Green
45   subj102Triangle  Green

I've been able to accomplish the task using the stack command, together with
some fairly lengthy code to reorganize the stacked data frame.  Is it
possible to use the reshape command to accomplish this task in a more
straightforward manner?   Many thanks in advance!

John


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-Reshaping-from-Wide-to-Long-tp2292462p2292462.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 comment off sections

2010-07-17 Thread Erik Iverson

On 07/17/2010 01:05 AM, Joshua Wiley wrote:

I use XEmacs + ESS, and looking for ways to add text to a region of
code, I see it is quite easy
with C-x r t.  Thanks for your great advice.



I use GNU Emacs.  With a region of code actve, M-; will add the comment line (or 
remove it if it's already there) to each line in the region.  Perhaps XEmacs has 
a similar keybinding?


It's nice because it's the same thing to comment or uncomment a block of 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] Plot error

2010-07-17 Thread Joshua Wiley
Hi James,

I believe the issue has to do with the values you assigned to 'x' and
'y'.  You call the function c() on seq["value_1"], but you assigned
your data not to 'seq' but to 'test'.  You need to use the variable
name that you assigned your data to (as a side note seq() is a
function, so you should probably avoid using that as name to store
data anyways).  Also you have data in a variable 'test' that has both
rows and columns, so the preferred way to access it is
variablename[rowname/number , columnname/number].  In your case that
would be test[ , "value_1"].  I left the space before the comma blank
to indicate include all rows.  It does technically work in this case
to simply write test["value_1"] but this is prone to error in other
situations.  This is my best guess as to what you want to do:

#Read in Data
#(just to make sure were on the same page)
test <- structure(list(name = structure(c(2L, 1L, 3L),
.Label = c("ben", "bill", "jane"), class = "factor"),
value_1 = 1:3, value_2 = c(4L, 2L, 1L)),
.Names = c("name", "value_1", "value_2"),
class = "data.frame", row.names = c(NA, -3L))

test # print so we can look at it

#Assign columns to variables 'x' and 'y'
x <- test[ , "value_1"]
y <- test[ , "value_2"]

#plot
plot(x, y)

#Or using data directly
plot(test[ , "value_1"], test[ , "value_2"])

Cheers,

Josh

On Sat, Jul 17, 2010 at 7:50 AM, James Platt  wrote:
> Hi guys,
>
> I am a newbie to R, so apologies in advance.
>
> I created this simple table in excel, saved in tab delimited .txt:
>
> name value_1 value_2
> 1 bill       1            4
> 2 ben      2           2
> 3 jane     3           1
>
>
>>test <-read.table("\path\to\file", sep="\t", header=TRUE)
>
>>x <-c(seq["value_1"])
>>y <-c(seq["value_2"])
>
>>plot(x,y)
>
> and i get this error
>
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>  (list) object cannot be coerced to type 'double'
>
> What does this mean and how do i fix it?
>
> Thanks for the help, James
>
> __
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] Plot error

2010-07-17 Thread Ista Zahn
Hi James,

On Sat, Jul 17, 2010 at 2:50 PM, James Platt  wrote:
> Hi guys,
>
> I am a newbie to R, so apologies in advance.
>
> I created this simple table in excel, saved in tab delimited .txt:
>
> name value_1 value_2
> 1 bill       1            4
> 2 ben      2           2
> 3 jane     3           1
>
>
>>test <-read.table("\path\to\file", sep="\t", header=TRUE)
>
>>x <-c(seq["value_1"])
>>y <-c(seq["value_2"])

You lost me here. What is seq["value_1"] supposed to do? Please fix
your example.

>
>>plot(x,y)
>
> and i get this error
>
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>  (list) object cannot be coerced to type 'double'
>
> What does this mean and how do i fix it?
>
> Thanks for the help, James
>
> __
> 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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.


[R] Plot error

2010-07-17 Thread James Platt

Hi guys,

I am a newbie to R, so apologies in advance.

I created this simple table in excel, saved in tab delimited .txt:

name value_1 value_2
1 bill   14
2 ben  2   2
3 jane 3   1


>test <-read.table("\path\to\file", sep="\t", header=TRUE)

>x <-c(seq["value_1"])
>y <-c(seq["value_2"])

>plot(x,y)

and i get this error

Error in xy.coords(x, y, xlabel, ylabel, log) :
  (list) object cannot be coerced to type 'double'

What does this mean and how do i fix it?

Thanks for the help, James

__
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] sort file names in numerical order

2010-07-17 Thread Sebastian Gibb
thanks a lot, it works.

you wrote:
> library(gtools)
> ?mixedorder
> 
> --- On Sat, 7/17/10, Sebastian Gibb  wrote:
> > From: Sebastian Gibb 
> > Subject: [R] sort file names in numerical order
> > To: r-help@r-project.org
> > Received: Saturday, July 17, 2010, 4:31 AM
> > Hello,
> > 
> > I get some file names by list.files().
> > These names are in alphabetical order.
> > I want to change it to logical numeric order.
> > 
> > Example:
> > > fileNames <- c("A10", "A1", "A2", "B1", "B2",
> > 
> > "B10")
> > 
> > > sort(fileNames)
> > 
> > [1] "A1"  "A10" "A2"  "B1"  "B10" "B2"
> > I want to have:
> > "A1"  "A2" "A10" "B1" "B2" "B10"
> > 
> > Is this possible?
> > 
> > Kind regards,
> > 
> > Sebastian
> > 
> > __
> > 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] installing and loading packages

2010-07-17 Thread Roman Luštrik

What are your user permission on the PC where you're working?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/installing-and-loading-packages-tp887190p2292385.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] installing and loading packages

2010-07-17 Thread Jeff Newmiller
I don't think there"most". It is normal to have to call the "library" function 
for each package you need devices to during an R session.

"chakri_amateur"  wrote:

>
>In my Windows XP, I just have to load package every time I open R, but not
>Install !! 
>
>There must be some problem during installation !
>
>Chakri
>-- 
>View this message in context: 
>http://r.789695.n4.nabble.com/installing-and-loading-packages-tp887190p2292339.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.

---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

__
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] installing and loading packages

2010-07-17 Thread chakri_amateur

In my Windows XP, I just have to load package every time I open R, but not
Install !! 

There must be some problem during installation !

Chakri
-- 
View this message in context: 
http://r.789695.n4.nabble.com/installing-and-loading-packages-tp887190p2292339.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] ed50

2010-07-17 Thread Dipa Hari

Dr. Ruben Rao
Thanks for your reply .But I don't know that how should I reparameterise the 
model.can you reply me in detail for reparameterization and taylor series for 
delta method .
Thanks
 

--- On Tue, 7/13/10, Rubén Roa  wrote:


From: Rubén Roa 
Subject: RE: [R] ed50
To: "Dipa Hari" , r-help@r-project.org
Date: Tuesday, July 13, 2010, 6:27 AM




> -Mensaje original-
> De: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] En nombre de Dipa Hari
> Enviado el: lunes, 12 de julio de 2010 22:19
> Para: r-help@r-project.org
> Asunto: [R] ed50
> 
> I am using semiparametric Model
>  library(mgcv)
> sm1=gam(y~x1+s(x2),family=binomial, f)
> 
> How should I  find out standard error for ed50 for the above 
> model ED50 =( -sm1$coef[1]-f(x2)) / sm1$coef [2]
>  
> f(x2) is estimated value for non parametric term.
>  
> Thanks

Two ways, 

1) Re-parameterise the model so that ed50 is an explicit parameter in the 
model, or
2) Taylor series (aka Delta method) using the standard errors of coef[1], 
coef[2] and their correlation.

HTH

 

Dr. Rubén Roa-Ureta
AZTI - Tecnalia / Marine Research Unit
Txatxarramendi Ugartea z/g
48395 Sukarrieta (Bizkaia)
SPAIN



  
[[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] sort file names in numerical order

2010-07-17 Thread Gabor Grothendieck
On Sat, Jul 17, 2010 at 4:31 AM, Sebastian Gibb  wrote:
> Hello,
>
> I get some file names by list.files().
> These names are in alphabetical order.
> I want to change it to logical numeric order.
> Example:
>> fileNames <- c("A10", "A1", "A2", "B1", "B2", "B10")
>> sort(fileNames)
> [1] "A1"  "A10" "A2"  "B1"  "B10" "B2"
> I want to have:
> "A1"  "A2" "A10" "B1" "B2" "B10"
>
> Is this possible?
>

The code for mixsort which does that type of sorting can be found on this page:

  http://gsubfn.googlecode.com

and gtools has a mixedsort function.

__
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] sort file names in numerical order

2010-07-17 Thread John Kane

library(gtools)
?mixedorder 


--- On Sat, 7/17/10, Sebastian Gibb  wrote:

> From: Sebastian Gibb 
> Subject: [R] sort file names in numerical order
> To: r-help@r-project.org
> Received: Saturday, July 17, 2010, 4:31 AM
> Hello,
> 
> I get some file names by list.files().
> These names are in alphabetical order.
> I want to change it to logical numeric order.
> Example:
> > fileNames <- c("A10", "A1", "A2", "B1", "B2",
> "B10")
> > sort(fileNames)
> [1] "A1"  "A10" "A2"  "B1"  "B10" "B2"
> I want to have:
> "A1"  "A2" "A10" "B1" "B2" "B10"
> 
> Is this possible?
> 
> Kind regards,
> 
> Sebastian
> 
> __
> 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] Adjustment for multiple-comparison for log-rank test

2010-07-17 Thread Marco Barbàra

DeaR experts,

I was asked for a log-rank pairwise survival comparison. I've a straightforward 
way
 to do this using the SAS system:

http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#/documentation/cdl/en/statug/63033/HTML/default/statug_lifetest_sect019.htm

What I've found in R is shown below, but it's not a logrank test, 
I suppose. (The documentation talks about "Tukey pairwise-comparisons").

Is it possible to carry out a "pairwise" logrank test? 
Am I totally misguided?

Thank you very much for help.
 

### R code 
#
> data(pbc)
> pbc$stage <- factor(pbc$stage)
> (fit <- coxph(Surv(time,status==2)~stage,data=pbc))
Call:
coxph(formula = Surv(time, status == 2) ~ stage, data = pbc)


   coef exp(coef) se(coef)z   p
stage2 1.10  3.010.737 1.50 0.13000
stage3 1.53  4.630.722 2.12 0.03400
stage4 2.53 12.570.717 3.53 0.00041

Likelihood ratio test=65.1  on 3 df, p=4.84e-14  n=412 (6 observations deleted 
due to missingness)

> summary(glht(fit,linfct=mcp(stage="Tukey"),alternative="g"))

 Simultaneous Tests for General Linear Hypotheses

Multiple Comparisons of Means: Tukey Contrasts


Fit: coxph(formula = Surv(time, status == 2) ~ stage, data = pbc)

Linear Hypotheses:
   Estimate Std. Error z value Pr(>z)
2 - 1 <= 0   1.1027 0.7374   1.495  0.237
3 - 1 <= 0   1.5318 0.7224   2.120  0.068 .  
4 - 1 <= 0   2.5311 0.7168   3.531 <0.001 ***
3 - 2 <= 0   0.4291 0.2544   1.686  0.169
4 - 2 <= 0   1.4284 0.2375   6.013 <0.001 ***
4 - 3 <= 0   0.9994 0.1816   5.502 <0.001 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
(Adjusted p values reported -- single-step method)

__
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] re. Mathematica and R

2010-07-17 Thread Alan Kelly
David - information on calling R from within Mathematica can be found at the
following link:
http://www.mofeel.net/1164-comp-soft-sys-math-mathematica/13022.aspx
HTH,
Alan Kelly

__
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] multivariate graphs, averaging on some vars

2010-07-17 Thread skan

Thank you very much, I'll try it.

About my question on graphics with colour...

Imagine I have a function y=y(x1, x2, x3), I'd need four dimensions to graph
x1, x2, x3, and y.
My idea is to use the typical 3D plot adding the information of the
additional fourth variable 'y to the colour of the point.
What package do you recommend to do it?
Any interactive plotting package?

thx
-- 
View this message in context: 
http://r.789695.n4.nabble.com/multivariate-graphs-averaging-on-some-vars-tp2292039p2292270.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 comment off sections

2010-07-17 Thread Peter Dalgaard
Joshua Wiley wrote:
> I use XEmacs + ESS, and looking for ways to add text to a region of
> code, I see it is quite easy
> with C-x r t.  Thanks for your great advice.

or even

M-x comment-region
M-x uncomment-region

These are commonly bound to C-c ; (because of LISP heritage), but not in
(my version of) ESS.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.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] SOLVED - export tables to excel files on multiple sheets with titles for each table

2010-07-17 Thread eugen pircalabelu
Hello R-users,
I was able using RExcel and the VBA script offered by Eric Neuwirth (modifying 
it a little bit) to import dataframes on separate Excel sheets, each with its 
own particular title. As such the problem is solved.

Thank you all for your suggestions.
Have a nice day ahead!   


 Eugen Pircalabelu







From: Erich Neuwirth 
To: Whit Armstrong 


Sent: Fri, July 16, 2010 6:00:55 AM
Subject: Re: [R] export tables to excel files on multiple sheets with titles 
for 
each table


If you are exporting your dataframes to Excel on Windows and
if you have Excel installed and 
if you are willing to make your hands dirty by programming VBA 
(the programming language built into Excel) and
if you are willing to install RExcel
(by way of the CRAN package RExcelInstaller or by visiting rcom.univie.ac.at)
then here is some code which transfers all dataframes in the
global environment in R into separate worksheets in the active workbook in 
Excel.
This version adds the name of the dataframe as a header on the sheet and also
uses it as the name of the worksheet.
It should be easy to adapt this to add headers and worksheet names of your 
choice.
If you want to use this code, you have to set a reference to RExcelVBALib in the
workbook with the VBA code below.
I you have never used RExcel before: There are many examples
demonstrating different techniques to connect R and Excel for
data transfer and computation.

-=-=-=-=-=-==

Option Explicit

Sub TransferToExcel(dfName As String, header As String)
Dim myWs As Worksheet
Set myWs = ActiveWorkbook.Worksheets.Add
myWs.Name = dfName
myWs.Cells(1, 1).Value = header
rinterface.GetDataframe dfName, myWs.Cells(2, 1)
End Sub

Sub DoIt()
Dim i As Integer
Dim dfNames As Variant
Dim myDfName As String
rinterface.StartRServer
dfNames = RDataFrameNames()
For i = LBound(dfNames) To UBound(dfNames)
myDfName = CStr(dfNames(i, LBound(dfNames, 2)))
TransferToExcel myDfName, myDfName
Next i
rinterface.StopRServer
End Sub

Function RDataFrameNames() As Variant
Dim cmdString As String
Dim myDfNames As Variant
rinterface.StartRServer
cmdString = "dfpos<-sapply(ls(),function(x)is.data.frame(eval(as.name(x"
rinterface.RRun cmdString
cmdString = "dfnames<-ls()[dfpos]"
rinterface.RRun cmdString
myDfNames = rinterface.GetRExpressionValueToVBA("dfnames")
RInterface.RRun "rm(dfnames,dfpos)"
RDataFrameNames = myDfNames
End Function

On Jul 15, 2010, at 3:29 AM, Whit Armstrong wrote:

It isn't beautiful, but I use this package to write excel files from linux.
>
>http://github.com/armstrtw/Rexcelpoi
>

--
Erich Neuwirth
Didactic Center for Computer Science and Institute for Scientific Computing
University of Vienna


  
[[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] sort file names in numerical order

2010-07-17 Thread Sebastian Gibb
Hello,

I get some file names by list.files().
These names are in alphabetical order.
I want to change it to logical numeric order.
Example:
> fileNames <- c("A10", "A1", "A2", "B1", "B2", "B10")
> sort(fileNames)
[1] "A1"  "A10" "A2"  "B1"  "B10" "B2"
I want to have:
"A1"  "A2" "A10" "B1" "B2" "B10"

Is this possible?

Kind regards,

Sebastian

__
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] multivariate graphs, averaging on some vars

2010-07-17 Thread Dennis Murphy
Hi:

On Fri, Jul 16, 2010 at 3:44 PM, skan  wrote:

>
> Hello
>
> I have a table of this kind:
>
> functionx1  x2  x3
> 2.232   1   1   1.00
> 2.242   1   1   1.01
> 2.732   1   1   1.02
> 2.770   1   2   1.00
> 1.932   1   2   1.01
> 2.132   1   2   1.02
> 3.222   1.2 1   1
> .   ... ..  ..
>
>
> The table represents the values of a function(x1, x2, x3) for each
> combination x1, x2, x3.
>
> I'd like to generate a plot where each point has the coordinates x=x1,
> y=x2,
> z=(mean of function(x1, x2) for all different x3).  How can I do it?
>

Here are three ways to get the function means over the x1 * x2 combinations
-
there are others, too. I changed the variable function to y since function
is a basic object in R and therefore not a good choice of variable name.

library(doBy)
library(plyr)

# (1) aggregate
(s1 <- aggregate(y ~ x1 + x2, data = d, FUN = mean))

# (2) function summaryBy() in package doBy:
(s2 <- summaryBy(y ~ x1 + x2, data = d, FUN = mean))

# (3)  function ddply() in package plyr:
(s3 <- ddply(d, .(x1, x2), summarise, y = mean(y)))

All three give the same answer (apart from the name of the y mean):

   x1 x2 y
1 1.0  1 2.402
2 1.0  2 2.278
3 1.2  1 3.222

fox example, with the data from above the first point would be:
> x=x1=1, y=x2=1, z=(2.232+2.242+2.732)/3
>
>
> In truth, my table has many columns and I want to take the mean over all
> the
> variables except the ones I represent at the axes, for example represent
> function(x1, x2) taking the mean over x3, x4, x5.
>

Same as above. The response is averaged over all x1 * x2 combinations.

>
> Or using the maximum value of function(x1, x2) over all x1, x2, x3
>

Substitute FUN = max for FUN = mean in aggregate() and summaryBy(),
and use y = max(y) in place of y = mean(y) in the ddply() call. I presume
you meant max f(x1, x2) over all x3 with the same (x1, x2) combination.


> How can I do it?
>
>
For the 3D plot, one choice is persp() in base graphics; another is
cloud() in the lattice package. persp() requires setting up a rectangular
grid of (x1, x2) pairs, with y = f(x1, x2) supplied as a n1 x n2 matrix.
cloud() in lattice only requires a formula of the form y ~ x1 + x2. See
their respective help pages for more details. The scatterplot3d package
could also be used in this context.


> Another question.
> How can I plot function(x1, x2, x3) with x=x1, y=x2, z=x3, different
> colours=function
>

One can create a vector of colors, but the question is too vaguely worded
to give any specific advice.

HTH,
Dennis

>
>
>
> thanks
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/multivariate-graphs-averaging-on-some-vars-tp2292039p2292039.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] Access web content from within R

2010-07-17 Thread Bart Joosen

Thanks Henrique, that does the trick!!!

Bart
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Access-web-content-from-within-R-tp2289953p2292181.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.