[R] plotting vectors of different lengths

arun smartpink111 at yahoo.com
Sat Mar 22 15:10:40 CET 2014


Hi Eliza,
You could also do:
res <- outer(y,x, FUN=function(u,v) paste0("(",u,",",v,")"))
 dimnames(res) <- list(y,x)
#or
 names(x) <- x
 names(y) <- y
 outer(y,x, FUN=function(u,v) paste0("(",u,",",v,")"))
A.K.




On Saturday, March 22, 2014 7:46 AM, Jorge I Velez <jorgeivanvelez at gmail.com> wrote:
You are welcome, Eliza.

If I understand correctly, the following will do:

x <- 1:8
y <- 1:5
matrix(apply(expand.grid(x = y, y = x), 1, function(r) paste0("(", r[1],
",", r[2], ")")), ncol = length(x))

Best,
Jorge.-



On Sat, Mar 22, 2014 at 10:37 PM, eliza botto <eliza_botto at hotmail.com>wrote:

> Thankyou very much jorge. It would a great favor if i may know how to go
> from x=1,2,3,4,5,6,7,8 and y=1,2,3,4,5
>
> TO
>
>        1     2     3     4     5     6     7     8
>
> 1  (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8)
>
> 2   (2,1) (2,2) (2,3) (2,4) (2,5) (2,6) (2,7) (2,8)
>
> 3   (3,1) (3,2) (3,3) (3,4) (3,5) (3,6) (3,7) (3,8)
>
> 4   (4,1) (4,2) (4,3) (4,4) (4,5) (4,6) (4,7) (4,8)
>
> 5   (5,1) (5,2) (5,3) (5,4) (5,5) (5,6) (5,7) (5,8)
>
> Thnakyou very in advance
>
> Eliza
>
>
> From: jorgeivanvelez at gmail.com
> Date: Sat, 22 Mar 2014 22:26:01 +1100
> Subject: Re: [R] plotting vectors of different lengths
> To: eliza_botto at hotmail.com
> CC: r-help at r-project.org
>
>
> Hi Eliza,
>
> Perhaps the following?
>
> matpoints(t(dat), type = 'l')
>
> HTH,
> Jorge.-
>
>
> On Sat, Mar 22, 2014 at 10:18 PM, eliza botto <eliza_botto at hotmail.com>wrote:
>
>
> Dear useRs,
> I have two column vectors of different lengths say x=1,2,3,4,5,6,7,8 and
> y=1,2,3,4,5. I wanted to plot them by using "points()" command over an
> already existed image but got an error, "Error in xy.coords(x, y) : 'x' and
> 'y' lengths differ".What i actually wanted to do was to plot the points in
> the following format.
>
> dat <- read.table(text="
>     1     2     3     4     5     6     7     8
> 1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8)
> 2 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8)
> 3 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8)
> 4 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8)
> 5 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) (1,7) (1,8)
> ",sep="",header=TRUE,stringsAsFactors=FALSE)
> How can i do it?
> Thankyou very much indeed in advance.
> Eliza
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>

    [[alternative HTML version deleted]]

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





More information about the R-help mailing list