Reputation: 71
I have a DataFrame Df => dim(Df) = 3243 679
I would like to change a part of my dataframe for exemple:
Df[50:100,1] = c(...)
with c(...)
corresponding to a vector of 50 elements.
Is there a better way to do it because it doesn't work
Error in `[<-.data.frame`(`*tmp*`, 50:100, 1, value = c("27.4349976", :
replacement has 50 rows, data has 3243
Upvotes: 0
Views: 69
Reputation: 1599
Note that your vector to be inserted has fewer elements than necessary. 50: 100 are 51 elements.
set.seed(1)
df <- data.frame(a = rnorm(n = 1000),
b = rnorm(n = 1000),
c = rnorm(n = 1000))
insert <- c(runif(n = 51))
df[50:100,1] <- insert
Upvotes: 1