16

Though question seems to be duplicate, i'm posting this as non of them gave a solution and relevant to my problem.

dtrain<-xgb.DMatrix(data=data.matrix(train),label=data[t,c(31)])

Error in xgb.DMatrix(data = data.matrix(train), label = data[t, c(31)]) : REAL() can only be applied to a 'numeric', not a 'integer'

> class(data[t,c(31)])
[1] "integer"

> str(train)

'

data.frame':    1965 obs. of  30 variables:
 $ having_IP_Address          : int  2 2 2 2 2 2 2 2 2 2 ...
 $ URL_Length                 : int  3 3 3 3 3 3 3 3 3 3 ...
 $ Shortining_Service         : int  1 1 1 1 1 1 1 1 1 1 ...
 $ having_At_Symbol           : int  1 1 1 1 1 1 1 1 1 1 ...
 $ double_slash_redirecting   : int  2 2 2 2 2 2 2 2 2 2 ...
 $ Prefix_Suffix              : int  2 2 1 2 3 2 1 1 3 1 ...
 $ having_Sub_Domain          : int  1 2 1 1 1 3 1 2 1 1 ...
 $ SSLfinal_State             : int  2 2 2 1 2 2 1 2 2 2 ...
 $ Domain_registeration_length: int  3 1 3 2 2 1 2 3 2 1 ...
 $ Favicon                    : int  1 2 1 1 1 1 1 1 2 1 ...
 $ port                       : int  1 2 1 1 1 1 1 1 2 1 ...
 $ HTTPS_token                : int  2 2 2 2 2 2 2 2 2 2 ...
 $ Request_URL                : int  1 1 1 2 2 1 2 1 2 1 ...
 $ URL_of_Anchor              : int  2 2 2 2 2 3 1 2 3 1 ...
 $ Links_in_tags              : int  3 2 3 3 1 3 2 1 3 2 ...
 $ SFH                        : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Submitting_to_email        : int  2 1 2 2 2 2 2 1 1 2 ...
 $ Abnormal_URL               : int  2 2 2 2 2 2 2 2 2 2 ...
 $ Redirect                   : int  1 1 1 1 1 1 1 1 1 1 ...
 $ on_mouseover               : int  1 2 1 1 1 1 1 1 1 1 ...
 $ RightClick                 : int  1 1 1 1 1 1 1 1 1 1 ...
 $ popUpWidnow                : int  1 2 1 1 1 1 1 1 2 1 ...
 $ Iframe                     : int  1 2 1 1 1 1 1 1 2 1 ...
 $ age_of_domain              : int  3 1 1 1 3 3 1 1 1 1 ...
 $ DNSRecord                  : int  2 1 1 2 1 2 1 2 2 1 ...
 $ web_traffic                : int  3 3 2 3 3 3 1 3 2 2 ...
 $ Page_Rank                  : int  2 3 1 1 1 1 1 1 1 1 ...
 $ Google_Index               : int  1 1 1 1 1 1 1 1 1 1 ...
 $ Links_pointing_to_page     : int  2 1 3 2 1 2 1 3 2 2 ...
 $ Statistical_report         : int  2 1 2 2 2 2 2 2 2 2 ...

What all I understood by searching this error is REAL() cannot be applied to lists. I am clueless what is this REAL(). Thanks in advance!!

Shankar Pandala
  • 969
  • 2
  • 8
  • 28
  • 1
    did you try converting your data to numeric as the error suggests `train[] <- lapply(train, as.numeric)`, and then use `xgb.DMatrix(data=data.matrix(train))` – user20650 Nov 24 '15 at 11:12

4 Answers4

17

The error states that xgb.DMatrix takes numeric values, where the data were integers.

To convert the data to numeric use

train[] <- lapply(train, as.numeric)

and then use

xgb.DMatrix(data=data.matrix(train))
user20650
  • 24,654
  • 5
  • 56
  • 91
Shankar Pandala
  • 969
  • 2
  • 8
  • 28
3

Roughly speaking REAL is a C-function for accessing the content of an R-numeric-vector in C.

bonnaix
  • 149
  • 1
  • 5
3

X: dataframe of predictors Y: vector of labels

dtrain <- xgb.DMatrix(as.matrix(as.numeric(X)),Y)

Or: xgb<- xgboost(data = as.matrix(X), label = Y,...)

silly
  • 887
  • 9
  • 9
0

I know this is an question, but sapply gave me a more straight solution.

train <- sapply(train, as.numeric)
xgb.DMatrix(data=train)
Augusto
  • 241
  • 3
  • 5