Re: [R] Problem with unlist

2010-09-28 Thread Susan Gruber
I suspect the problem is that table() is not displaying the correct
length.  Try
  table(n, useNA="ifany")

--Susan


>Message: 75
>Date: Mon, 27 Sep 2010 11:41:24 -0700
>From: Henrik Bengtsson 
>To: Ben Bolker 
>Cc: r-help 
>Subject: Re: [R] Problem with unlist
>Message-ID:
>
>Content-Type: text/plain; charset=ISO-8859-1

>On Mon, Sep 27, 2010 at 5:27 AM, Ben Bolker  wrote:
>> Luis Felipe Parra  quantil.com.co> writes:
>>
>>>
>>> ?Hello, I am trying to unlist a list, which is attached, and I am
having the
>>> problem that when I unlist it the number of elements changes from 5065 to
>>> 5084
>>>
>>> ?> x <- lapply(SumaPluvi, FUN="[", 1);
>>> > n <- sapply(x, FUN=length);
>>> > print(table(n));
>>> n
>>> ? ?1
>>> 5065
>>> > print(which(n != 1));
>>> integer(0)
>>> > length(unlist(lapply(SumaPluvi, FUN="[", 1)))
>>> [1] 5081
>>> >
>>>
>>> I dont now why, but when I unlist it the number of elements changes from
>>> 5065 to 5084 even if there is no list element with length greater than
one.
>>> Do you know what can be happening?
>>>
>>
>> ?We probably won't be able to get farther without a reproducible
>> example. ?One brute-force way of finding the problem is by bisection:
>> i.e., try the first and last halves of your list separately, and see
>> if either one individually shows a similar problem. ?Proceed recursively
>> until you localize the problem ...

>...and as alternative, my most recent post did contain an updated code
>snippet that is likely to find list elements generating more than one
>value.

/Henrik

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


Re: [R] [R-SIG-Mac] plot 2 graphs on the same x-y plane

2012-04-11 Thread Susan Gruber
Hi,
A line can be added to an existing plot using the abline function.  For 
example, if a is the intercept and b is the slope, the command would be
   abline(a=a, b=b)

To overlay a new plot on an existing one, use the command: par(new=TRUE).  
For example:

plot(1:10, 1:10)
par(new=TRUE)
plot(log(1:10), 1:10)

This approach often leads to issues with the scale of the axes, tick marks, and 
labels.  Fortunately, R provides the flexibility to deal with all of them. I 
recommend you carefully read the help pages for plot, par, and axis, and have 
some fun playing around with all the options.

--Susan


On Apr 10, 2012, at 11:55 PM, Tawee Laoitichote wrote:

> 
> Dear Michael (and Davis), Your answer is not what I want to know. My question 
> is to find any command to plot the data I got from the field; such as a set 
> of (x,y) data ( I actually have these data) and together withe the derived 
> ones . I brought these data to plot on x-y plane,  getting a graph showing 
> some relation. Then, I wanted to find some linear relation, I would use least 
> square method to solve having a simple function such as; y = ax + b, solving 
> the a and b. So, I could plot a straight line using this function, or perhaps 
> forecast some data of y which I know the value x. My problem is when I did a 
> scatter plot by command "plot(x,y)", I got a graph. Whilst I plotted another 
> graph using the above function the existing graph disappeared replaced be the 
> latter function. Unfortunately, after searching a while to find the solution 
> command, I can not find the command. I asked the question as to request some 
> help not the example you shown. Any way, thanks for you effort. !
 Ta!
> 
> wee Mac OS10.7.3
>> From: michael.weyla...@gmail.com
>> Date: Tue, 10 Apr 2012 23:31:08 -0400
>> Subject: Re: [R] plot 2 graphs on the same x-y plane
>> To: ohowow2...@hotmail.com
>> CC: r-help@r-project.org
>> 
>> This is the same malformatted message you posted on R-SIG-Mac even
>> after David specifically asked for clarification not to reward bad
>> behavior, but perhaps this will enlighten:
>> 
>> # Minimal reproducible data!
>> x <- runif(15, 0, 5)
>> y <- 3*x - 2 + runif(15)
>> 
>> dat <- data.frame(x = x, y = y)
>> rm(list = c("x", "y"))
>> 
>> # Base graphics plot using the formula interface
>> plot(y ~ x, data = dat)
>> abline(lm(y~x, data = dat), col = "red3", lwd = 2)
>> 
>> Alternatively
>> 
>> library(ggplot2)
>> ggplot(dat, aes(x = x, y = y)) + geom_point() + stat_smooth(method =
>> "lm", color = I("red3"))
>> 
>> which is perhaps overkill in this situation.
>> 
>> 
>> Michael
>> 
>> On Tue, Apr 10, 2012 at 11:03 PM, Tawee Laoitichote
>>  wrote:
>>> 
>>> 
>>> 
>>> 
>>> hi,  I'm doing some data on least square curve fitting. What I like to have 
>>> is to compare the scatter plot whilst having the fitting curve on the same 
>>> coordinates. Any suggestting command besides plot(x,y).  TaweeMac OSX 10.7.3
>>>   [[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-SIG-Mac mailing list
> r-sig-...@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac

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