'newdata' had 1 row but variables found have 33 rows - Help with error code

Hello

I am creating a confidence interval using the following:

a <- (Properties$SQFT)
b <- (Properties$BEDROOMS)
c <- (Properties$BATHS)
d <- (Properties$DAYS)

predict(Model, data.frame(a = 3200, b = 4, c = 3, d = 60), interval = "confidence", level = 0.95)
predict

It is showing me the following error code:
'newdata' had 1 row but variables found have 33 rows

I have been trying for what feels like a million years with no luck. Any help would be appreciated!

Edit:

Properties <- read.table(file = "Properties.txt", header = TRUE)
str(Properties)


Model=lm(Properties$SALe_PRICE~Properties$SQFT+Properties$BEDROOMS+Properties$BATHS+Properties$DAYS)
summary(Model)

a <- (Properties$SQFT)
b <- (Properties$BEDROOMS)
c <- (Properties$BATHS)
d <- (Properties$DAYS)

predict(Model, data.frame(a = 3200, b = 4, c = 3, d = 60), interval = "confidence", level = 0.95)
predict

-> 'newdata' had 1 row but variables found have 33 rows        fit      lwr      upr
1  656.9205 597.3529 716.4881
2  544.9092 490.0353 599.7831
3  461.4711 423.8341 499.1082
4  392.9870 347.9219 438.0522
5  396.0466 351.7443 440.3489
6  439.0816 389.5483 488.6150
7  305.3748 285.2675 325.4821
8  374.3041 339.0357 409.5726
9  464.1598 434.2539 494.0657
10 368.7902 331.8679 405.7125
11 324.4370 305.1009 343.7732
12 332.9489 314.1399 351.7578
13 322.5467 305.5254 339.5679
14 319.4154 303.0877 335.7431
15 363.1554 316.8853 409.4254
16 286.7435 258.2170 315.2700
17 299.3378 281.5482 317.1274
18 309.0561 289.2991 328.8130
19 305.6776 288.2160 323.1392
20 345.6935 321.3828 370.0042
21 202.0958 167.1284 237.0631
22 308.3043 286.3011 330.3075
23 297.9260 279.3613 316.4907
24 268.6685 237.6889 299.6482
25 343.7089 321.2000 366.2179
26 300.2452 253.0570 347.4334
27 289.8085 264.0771 315.5399
28 289.3099 263.3379 315.2819
29 273.6605 245.5202 301.8008
30 275.7949 237.0198 314.5701
31 269.3483 219.1184 319.5783
32 189.2632 154.4770 224.0494
33 249.8091 203.2728 296.3455
function (object, ...) 
UseMethod("predict")
<bytecode: 0x563d0551d550>
<environment: namespace:stats>

Hi stefaniadram, sorry you're having so much trouble!
Firstly, this question doesn't really belong in #rstudio-cloud, since the error message isnt really related to anything to do with cloud. So I moved it to #general, where it's more likely to attract some help.


Also, be sure to pose questions like this with formatted code and a reprex. It makes it easier for folks who want to help to quickly replicate your error, and use your data & code to offer a solution to that problem.

For example with this question, we don't have Properties or Model, which will be helpful just to replicate your error, and inspect things a few things likely to result in this error. It's also not clear at what point in this code is producing the error message.

Here's a nice guide to help you get started, FAQ: Tips for writing R-related questions


Just to build an example (with meaningly data and model) of how this could work with a toy example in a reprex


library(dplyr)
a <- rnorm(20)
b <- rnorm(20)
c <- rnorm(20)
d <- rnorm(20)

Model = lm(
  a ~ b + c + d
)
  
predict(Model, data.frame(a = 3200, b = 4, c = 3, d = 60), interval = "confidence", level = 0.95)
#>        fit       lwr      upr
#> 1 17.26983 -11.57436 46.11402
predict
#> function (object, ...) 
#> UseMethod("predict")
#> <bytecode: 0x7fefd818a140>
#> <environment: namespace:stats>

Created on 2020-03-25 by the reprex package (v0.3.0)

Thanks for the help. I have edited the post to include the rest

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.