1

I have samples A:Z and I want to make a matrix that have sample column and another value column with all 1's.

result should look like this.

samples values
A        1
B        1
C        1
D        1
.        .
.        .
Z        1
1
  • 1
    @akrun Sorry mate, totally forgot! Thank you for your help. Commented Aug 17, 2015 at 5:40

1 Answer 1

1

Use cbind to create a matrix

 cbind(samples, values=1)

but matrix can hold only a single class so the output columns will be 'character'

I would suggest to use data.frame to hold columns of different class.

 data.frame(samples, values=1)

If we want the 'samples' column to be character class, use option stringsAsFactors=FALSE. The default is TRUE.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.