5

This seems to be simple but I can't find the answer. I combine two vectors using cbind().

> first = c(1:5)
> second = c(6:10)
> values = cbind(first,second)

When I want to retrieve a single element using values[1,2] I always get the column name in addition to the actual element.

> values[1,2]

second
6

How can I get the value without the column name?

I know I can remove the column names in the matrix like in this post: How to remove column names from a matrix in R? But how can I leave the matrix as is and only get the value I want?

Community
  • 1
  • 1
swbandit
  • 1,986
  • 1
  • 26
  • 37

1 Answers1

11

We can use unname

unname(values[1,2])
#[1] 6

Or as.vector

as.vector(values[1,2])

You can use the [[ operator to extact a single element,

values[[1,2]]
# [1] 6
Rorschach
  • 31,301
  • 5
  • 78
  • 129
akrun
  • 874,273
  • 37
  • 540
  • 662