0

Below is my code. I get the following error:

replacement has 2287 rows, data has 2490~

Why is that? shouldn't it be coming from the same data frame?

> df.Part3 <- df %>%  
> filter(NEIGHBORHOOD_NAME=="BRONXDALE",YEAR>2008,SALE_PRICE>0)%>%  
> mutate(TOTAL_UNITS=RESIDENTIAL_UNITS+COMMERCIAL_UNITS)%>%  
> mutate(SALE_YEAR=year(SALE_DATE))%>%   ungroup()%>%  
> select(SALE_PRICE,SALE_YEAR,YEAR_BUILT,GROSS_SQUARE_FEET,TOTAL_UNITS,TYPE)
> 
> z <- lm(formula=SALE_PRICE~.,data=df.Part3) summary(z)
> 
> df.Part3["residuals"]<-z$residuals
zx8754
  • 52,746
  • 12
  • 114
  • 209
  • See this answer in the linked post: https://stackoverflow.com/a/64122317/680068 – zx8754 Nov 08 '22 at 21:26
  • 4
    At a guess, the line `z <- lm(formula=SALE_PRICE~.,data=df.Part3) summary(z)` is not valid (two statements in the one line) and `z` is not being replaced, leading to an old version being used on the next line. – thelatemail Nov 08 '22 at 21:31
  • 1
    @zx8754, re the linked "dupe," that show the same error, but I don't think it's caused by the same issue or resolvable the same way here. – Jon Spring Nov 08 '22 at 21:33
  • @JonSpring I see, then let's close as typo. – zx8754 Nov 08 '22 at 21:37
  • Try with double square brackets, `df.Part3[["residuals"]]`, see [Difference between `[` and `[[`](https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-el) . Also, `resid(z)` is the recommended way of accessing the residuals of *any* object with a component `residuals`. – Rui Barradas Nov 08 '22 at 21:37
  • For the record the only typo was in this question. I copied and pasted the code but for some reason the summary and lm() function pasted on the same row and I didn't see it. In the console, it is correct. – Thanos of Siberia Nov 08 '22 at 21:55

0 Answers0