I need to create a function that takes two integer numbers `x` and `N`, where `N > x` and returns a vector of dimension `N` with all zeros with the exception of component `x`, in which it has a `1`.

I managed to do it in the following way,

```
Function=function(x,N){
  vec=rep(0,N)
  r=as.integer(x)
  vec[r]=1
  return(vec)
}

```

but it is incredibly slow when I need to iterate the process and apply it to a large number of realizations. On the other hand, a friend of mine is able to do the same thing with a single function of python (I think "OneHotEncoder") and it's super fast.

I was wondering if there are functions in R that are suited for this purpose.