Error in `$<-.data.frame`(`*tmp*`, residuals, value = c(`1` = 85.2823496546331, : replacement has 64 rows, data has 999
3.
stop(sprintf(ngettext(N, "replacement has %d row, data has %d", "replacement has %d rows, data has %d"), N, nrows), domain = NA)
2.
`$<-.data.frame`(`*tmp*`, residuals, value = c(`1` = 85.2823496546331, `2` = 75.6452252037355, `3` = -26.6646054332669, `4` = 53.1072802045741, `5` = 45.2947706852716, `6` = 0.109746902327331, `7` = -90.2459997479568, `8` = -56.514561514735, `9` = -9.18563164550705, `10` = -58.4067912439267, ...
1.
`$<-`(`*tmp*`, residuals, value = c(`1` = 85.2823496546331, `2` = 75.6452252037355, `3` = -26.6646054332669, `4` = 53.1072802045741, `5` = 45.2947706852716, `6` = 0.109746902327331, `7` = -90.2459997479568, `8` = -56.514561514735, `9` = -9.18563164550705, `10` = -58.4067912439267, `11` = -14.1825622165646, ...
Asked
Active
Viewed 138 times
-1

Caconde
- 4,177
- 7
- 35
- 32
-
It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Do you have missing values in your data? – MrFlick Nov 17 '20 at 18:24
1 Answers
0
The error is very clear - replacement has 64 rows, data has 999
.
This means that at some place in your code (I can't tell you where as you have not posted it) you are attempting to replace only parts of an object.
Here is an example of what you are attempting to do, based on some example data:
# Make a dataframe with 10 rows in it
df = data.frame(A = 1:10, B = 1:10+1)
df
#> A B
#> 1 1 2
#> 2 2 3
#> 3 3 4
#> 4 4 5
#> 5 5 6
#> 6 6 7
#> 7 7 8
#> 8 8 9
#> 9 9 10
#> 10 10 11
If you try to assign one of the rows with a different length vector or set of values, you will get the error.
df$A = c(1,2,3)
#> Error in `$<-.data.frame`(`*tmp*`, A, value = c(1, 2, 3)): replacement has 3 rows, data has 10
If you instead try to change the column to a vector of equal length, it will work.
df$A <- c(1,1,1,1,1,1,1,1,1,1)
df
#> A B
#> 1 1 2
#> 2 1 3
#> 3 1 4
#> 4 1 5
#> 5 1 6
#> 6 1 7
#> 7 1 8
#> 8 1 9
#> 9 1 10
#> 10 1 11
To summarise, make sure that you are using the correct objects.
Created on 2020-11-17 by the reprex package (v0.3.0)

mhovd
- 3,724
- 2
- 21
- 47