1
$\begingroup$

We know whenever we arrange dataset in R. We arrange independent and dependent variable column-wise for each ID.

But if I see numerical and category data in single column of independent variable, how can I use that for predicting?

Example, for 10 ID's. Past number of calls: 1,3,4,2,0,no past,5,1,no past, 6(note:no past have different behaviour than 0)

And some other independent variables And one target column.

So from the example, I don't want all levels as factor levels. I want to solve as by looking if 'no past' or as numeric(0-6).

How can I do so, I tried to make different column for 'no past'. But what would I place in 'past number of calls'.

$\endgroup$
1
  • $\begingroup$ I am voting to leave this open. Although it's asked with regard to R, these issues would exist no matter what software you use. $\endgroup$
    – Peter Flom
    Commented Apr 30, 2020 at 12:22

1 Answer 1

2
$\begingroup$

I would just code no past as 0 in the 'past number of calls; column, and add another factor column for 'no past', which takes one of two values. This gives you all the same information, but allows the columns to have either numeric or factor types.

$\endgroup$
4
  • $\begingroup$ As 0 has different behaviour than 'no past'. Would not this create bias? $\endgroup$ Commented Apr 11, 2017 at 6:00
  • $\begingroup$ Not when used in conjunction with the "no past" binary column. The "no past" column accounts for the different behavior. $\endgroup$
    – Sycorax
    Commented Apr 11, 2017 at 13:06
  • $\begingroup$ So, can I write 0-6 any number for 'no past' in 'past number of calls'? as conjunction will account for. $\endgroup$ Commented Apr 11, 2017 at 13:58
  • $\begingroup$ Yep. For example, if you were to use this in a regression, increasing the numeric value for 'no past' would be reflected by a linear change in the coefficient for the binary 'no past' column. $\endgroup$
    – Sycorax
    Commented Apr 11, 2017 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.