Mohan
Mohan

Reputation: 8843

In R, is there a difference between the types which would elsewhere be Int and Vector[Int]?

I'm trying to understand the type system in R.

Most modern programming languages have a type system in which there is a difference between the numeric type int and the container type Vector[int] (a.k.a. int vector, Vector int, vector<int>, etc.). In R, if I run

x <- 1L
typeof(x)
is.vector(x)

y <- c(1L,2L)
typeof(y)
is.vector(y)

I get out

[1] "integer"
[1] TRUE
[1] "integer"
[1] TRUE

This suggests that there is no distinct 'int' type and every integer is a vector (of ints). Is that right?

Upvotes: 1

Views: 43

Answers (1)

Clemsang
Clemsang

Reputation: 5481

There is no difference between a value and a vector of length 1 in general in R (integer or not):

identical(1L, c(1L))
[1] TRUE

Upvotes: 2

Related Questions