Dear Jesse,
You can use a "list" to do what you want:

# Data
mylist1=list(x=1:5,y=rnorm(10),z=letters[1:15])
mylist2=list(x=1:15,y=rnorm(5),z=letters[1:5])

# Length of each object in mylist1
l1=sapply(mylist1,length)

# The same for mylist2
l2=sapply(mylist2,length)

# Ratio
l1/l2
x         y         z
0.3333333 2.0000000 3.0000000


Now, if you have different matrices, something like this should do the job:


# Data
m1=matrix(rnorm(200),ncol=20)
m2=matrix(rnorm(100),ncol=20)

# Length of each column
lm1=apply(m1,2,length)
lm2=apply(m2,2,length)

# Ratio
lm1/lm2


HTH,

Jorge


On Tue, Sep 16, 2008 at 3:48 PM, j daniel <[EMAIL PROTECTED]> wrote:

>
> Greetings,
>
> I need to compare the ratios of vector sizes like this:
>
> length(object1) / length(object2)
>
> I have many vector objects to compare, so I would like to do it in a loop.
> I created a loop like this:
>
>
> mat1 <- matrix()
>
> for (i in 1:6)
> {
>   for (j in 1:6)
>     {
>
>       mat1[i,j] <- length( paste("object",i,sep="")) /
> (paste("object",j,sep="") )
>
>     }
> }
>
>
> The loop does not work, however, because   paste("object",i,sep="")
>  creates
> a character vector of length 1.  Is there a way to cast this as an object
> so
> that it can be evaluated in the loop?
>
> Thanks in advance
>
> Jesse
> --
> View this message in context:
> http://www.nabble.com/casting-a-character-vector-as-an-object-tp19519216p19519216.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.

Reply via email to