I have a data.frame that includes factor and numeric variables, as may be seen below.

testFrame = data.frame(First=sample (1:10), Second=sample (1:20), Third=sample (1:10), Replace=T);
Fifth=rep(c("Edward","Frank","Georgia","Hank","Isaac"),4) I want to construct a matrix that assigns dummy variables to the factor and leaves the numeric variables alone. Fourth=rep(c("Alice","Bob","Charlie","David"), 5), and Fifth=rep(c("Edward","Frank","Georgia

First + Second + Third + Fourth + Fifth, data=testFrame, model.matrix
This eliminates the reference level for one level of each factor, as expected when executing lm. But I want to create a matrix that includes a dummy or indicator variable for each level of every factor. I am not concerned about multicollinearity because I am developing this matrix for glmnet.

Is there a way to have model.matrix create the dummy for every level of the factor? Jul 9 21 views

## How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

## Show a list of all variables in R

Hi Swathi, You can use ls() to list ...READ MORE

## How to replace all occurrences of a character in a character column in a data frame in R

If you used sub() to replace the ...READ MORE

## How do I make a matrix from a list of vectors in R?

Suppose l1 and l2 are my vectors, li = ...READ MORE

## What is the difference between [] and [[]] notations to access the elements of a list or dataframe in R?

R provides 3 basic indexing operators. Refer ...READ MORE

## How to create dummy variables based on a categorical variable of lists in R?

You can use mtabulate in the following way: library(qdapTools) cbind(data, ...READ MORE

## Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE