0

I am trying to create a label to the combn command so that I know exactly which pairs where compared. Here's an example: Let a be my vector of interest,

a<-seq(1,10,1)
c<-combn(a,2)

So I want to create a vector label with the numbers that are paired:

label<-rep("abc",times=ncol(c)) #This is just a vector to initialized "label"
head(label)

for(i in ncol(c)){
label[i]<-c(paste("Exon",c[1,i],"with",c[2,i]))
}
head(label)

The problem is when I run the for loop it doesn't work. Alternatively, it only outputs the last comparison.

1
  • Your loop runs only once because ncol(c) is only a single value. You have to use something like 1:ncol(c) or seq(along=label). Commented Apr 20, 2013 at 21:18

1 Answer 1

3

Remove the loop and use a vectorized approach:

label <- paste("Exon", c[1,] "with", c[2,])

BTW: c is a very bad variable name (see ?c).

Sign up to request clarification or add additional context in comments.

1 Comment

@sgibb why is very bad to use c as a name? you should (some situations) use base::c , that's about it. maybe not elegant but I don't think it is so bad.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.