0

Hi i am passing arguments in R.when i passing the string value i am getting the following error.

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
contrasts can be applied only to factors with 2 or more levels
In addition: Warning message:
In read.table(file = file, header = header, sep = sep, quote = quote,  :
incomplete final line found by readTableHeader on 'addresstest.txt'

this is my code

input <- function(CITY,ADDRESS)     
{
delhi <- read.delim("addresstest.txt", na.strings = "")
delhi$lnprice <- log(delhi$PRIMARY_PRICE) # creating log price variable
uidel = lm (lnprice ~ CITY+AREA_SQFT+BEDS+BATHS+ADDRESS,data = delhi) 
model <- predict (uidel,data.frame(CITY=CITY,ADDRESS=ADDRESS), na.rm = TRUE)
model
}

passing the values by

input(CITY=NCR,ADDRESS=Sector78)

any help will be appreciated.

sharon paul
  • 93
  • 2
  • 9
  • The error message seems to be telling you that one of your variables has only one level ... you can check this with `table` or `nlevels`. (compare to the output of `lm(1 ~ factor(1))`) – user20650 Sep 20 '15 at 15:44
  • can u explain deeply.i am new to r language – sharon paul Sep 20 '15 at 15:45
  • 1
    PS.. id try doing this correctly outside a function first – user20650 Sep 20 '15 at 15:46
  • When you read in your data, some variables (the categorical) will be converted to factors. If they have only one unique level then coefficients cannot be estimated. So check the number of unique values for each of your predictors. – user20650 Sep 20 '15 at 15:50
  • Might be worth having a read of the r intro https://cran.r-project.org/manuals.html – user20650 Sep 20 '15 at 15:50

0 Answers0