Dummy or indicator variables are used to include categorical or qualitative variables in a regression model.
Questions tagged [dummy-variable]
868 questions
0
votes
1 answer
Functions within R for dummy variables
I'm wanting to create dummy variables for a few different columns in R. I can do this for the variable Disability with the code:
Disability <- model.matrix(~ Disability - 1,
transform(Dev_Mod, Disability =…

MLPNPC
- 454
- 5
- 18
0
votes
1 answer
Loop over each factor in lm in r
I have a database that has several factors. I want to iterate a regression over each factor for each variable, but for the whole database. Something like this:
for (i in unique(db$Product)) {
for (j in unique(db$Super)) {
for (c in…

Leandro Zipitria
- 55
- 9
0
votes
1 answer
Need to create a dummy variable in R that is equal to 1 if the variable name contains specific phrases
I want to create a new variable, created_idx_var, that is equal to 1 if the variable name contains any of the phrases "idx", "Idx", "indx", "Indx", "index", "Index", "etf", "ETF", or if the variable index equals "Yes".
I just started to learn R. My…

Hayley Han
- 1
- 1
0
votes
2 answers
Create dummy values for a list of dates in pandas
I have a dataframe with a double index (day, time) and would like to create a new column 'Holiday' equal to one if the index day belongs to a list of holidays.
My list of holidays of type DatetimeIndex:
holidays = ['2017-09-11', '2017-12-24']
My…

Batmax
- 253
- 8
- 17
0
votes
0 answers
dummies package in R
After creating dummy variables for all the categorical variables in the dataset, I'm able to view only the dummy variables and not the original factor varaibles in the new dataset .How do i get to view the original factor and dummy variables created…

flyinlizard
- 1
- 2
0
votes
1 answer
Creating Dummy Variables by Date Range in R
I would like to create dummy variables that indicate which product version was in effect based on the date range, i.e. between the release date and the following version release date without doing it manually. I have a few hundred versions with…

Mike Guay
- 25
- 3
0
votes
1 answer
Converting a string to dummy encoded variables
Here's the data
PlayerID, Characters, Win or Lose
I can make it look like this
8PYPY0LLQ,valkyrie5 , chr_witch4 , hog_rider5 , zapMachine1 , mega_minion3 , baby_dragon2 , bomber7 , skeleton_horde1, 0
Or like this
2GRG822L9,"barbarians8,…

Tyler L
- 835
- 2
- 16
- 28
0
votes
1 answer
Fixing 'TypeError' in Poisson Regression (using Python)
I'm running a Poisson Regression in Python, and it's throwing the following error:
TypeError: from_formula() takes at least 4 arguments (3 given)
How can I fix it? My code is as follows:
from statsmodels.genmod.generalized_estimating_equations…

Hassan Baig
- 15,055
- 27
- 102
- 205
0
votes
2 answers
R: How can I convert an ordered factor to dummy variables?
For example. A factor that with ordered levels
[1] 0 0 6 6 3 4
Levels: 0 < 1 < 2 < 3 < 4 < 5 < 6
should be converted to
ti0 ti1 ti2 ti3 ti4 ti5 ti6
1 0 0 0 0 0 0
1 0 0 0 0 0 0
1 1 1 1 1 1 1
1 1 1 1 1 …

user3285362
- 31
- 1
- 2
0
votes
1 answer
How do I identify rows with duplicates when all columns are dummy variables?
Here is a sample dataframe:
Col1 Col2 Col3
1 0 0
0 1 0
1 0 0
1 0 1
0 1 1
I want to return the following data frame:
Col1 Col2 Col3
1 0 1
0 1 1
That is, I want each…

JRP
- 125
- 2
- 10
0
votes
0 answers
Histogram to decide whether two distributions have the same shape in R
I would like to create a diagram in R as shown below (right) where i can show the distribution of my dummy variable, reservation (1) or walk-in (0), as separate.
This in order to do a correct analysis of the Mann-Whitney U test.
I want to make the…

Emily
- 1
- 2
0
votes
2 answers
Classification dummy R
In a large dataset of US stocks I have a integer variable containing SIC codes. https://www.sec.gov/info/edgar/siccodes.htm
I would like to create a dummy variable indicating the major group of 50, i.e. a variable that takes on 1 for durable goods…

J. Alexander Sanden
- 41
- 5
0
votes
4 answers
Creating a dummy variable for certain hours of the day
i need some help. I'm currently trying to fit a linear model to hourly electricity prices. So, I was thinking of creating a dummy, which takes the value 1, if the hour of the day is between 06:00 and 20:00. Unfortunately, I have struggled so far.…

hoppe_pr
- 11
- 1
- 3
0
votes
2 answers
Convert feature to dummies
I have a dataset that looks like the following:
name ingredient allergic
prod1 ing1 yes
prod1 ing2 yes
prod2 ing1 no
prod2 ing3 no
prod3 ing3 yes
I want to convert the ingredient variable to…

Joey B
- 125
- 3
- 14
0
votes
1 answer
R - Replace observations with dummy if in top x% of var
I have some data in a large data frame (about 80x300) that looks something like this:
dum <- data.frame(id=c("a", "b", "c", "d", "e"),
v1=c(2, 7, 8, 5, 0),
v2=c(9, 2, 4, 6, 1),
v3=c(2, 2, 6, 1,…

cparmstrong
- 799
- 6
- 23