Repita el vector para llenar la columna en el marco de datos

Parece que esta maniobra muy simple solía funcionar para mí, y ahora simplemente no. Una versión ficticia del problema:

df <- data.frame(x = 1:5) # create simple dataframe
df
  x
1 1
2 2
3 3
4 4
5 5

df$y <- c(1:5) # adding a new column with a vector of the exact same length. Works out like it should
df
 x y
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5

df$z <- c(1:4) # trying to add a new colum, this time with a vector with less elements than there are rows in the dataframe.

Error in `
df <- data.frame(x = 1:5) # create simple dataframe
df
  x
1 1
2 2
3 3
4 4
5 5

df$y <- c(1:5) # adding a new column with a vector of the exact same length. Works out like it should
df
 x y
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5

df$z <- c(1:4) # trying to add a new colum, this time with a vector with less elements than there are rows in the dataframe.

Error in `$<-.data.frame`(`*tmp*`, "z", value = 1:4) : 
  replacement has 4 rows, data has 5
lt;-.data.frame`(`*tmp*`, "z", value = 1:4) : replacement has 4 rows, data has 5

Esperaba que esto funcionara con el siguiente resultado:

 x y z
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 1

Es decir. el vector más corto debería comenzar a repetirse automáticamente. Estoy bastante seguro de que esto solía funcionar para mí (está en un script que he estado ejecutando cientos de veces sin problemas). Ahora ni siquiera puedo hacer que el ejemplo ficticio anterior funcione como quiero. ¿Qué me estoy perdiendo?

Respuestas a la pregunta(2)

Su respuesta a la pregunta