0
$\begingroup$

QUESTIONS:

  1. Can you tell me how I can convert int and factor variables to numeric variables in R?

  2. Can you tell me why as.numeric(as.character(df$Account_Global_Region_Cascading_Band)) doesn't work?

CONTEXT: I've converted all of my CSV columns to numbers. I want to run a correlation matrix via this STHDA tutorial. The Error Message below is preventing this. All variables are literally numbers even though their types aren't necessarily.

ERROR:

> res <- cor(sql_inputs_formatted)
Error in cor(sql_inputs_formatted) : 'x' must be numeric
 $ Account_Global_Region_Cascading_Band: int  3 3 2 2 2 2
 $ Account_Annual_Revenue_Cascading    : num  5.6e+08 0.0 0.0 0.0 6.1e+06 5.7e+06
 $ Account_Annual_Revenue              : int  1000 50 50 50 50 50
 $ Account_NAICS_Code_Cascading        : int  813000 334000 517919 0 0 0
 $ Account_Employee_Count_Cascading    : Factor w/ 256 levels "10","100","1000",..: 80 23 66 6 88 47
 $ Account_Employee_Count_Band         : int  5000 10001 10001 10001 100 100
 $ Account_Buyer_Industry_Cascading.1  : int  0 4 1 6 6 0
 $ Active_Nodes                        : int  0 10 0 0 0 0
 $ Active_Node_Bands                   : int  1 1 1 1 1 1
 $ Account_Fit_Score                   : int  14 10 10 10 16 16
 $ Account_Fit_Score_Bands             : int  3 2 2 2 4 4
 $ Predictive_Engagement_Score_Bands   : int  2 2 2 1 2 4
 $ Engaged_People                      : int  3 6 11 1 4 0
 $ Engagement_Minutes_3_mo             : int  4 747 121 10 312 0
 $ Engagement_Minutes_7.days           : int  0 86 0 0 19 0
 $ Engagio_Status_Bands                : int  1 3 3 3 3 4
 $ DF_Total_Funding                    : num  0 0 0 0 0 0
 $ Number_of_People                    : int  8 6 14 1 3 1
 $ Fortune_Rank                        : int  0 0 0 0 0 0
 $ Expected_Node_Count_Band            : int  0 0 0 0 0 0
 $ Contact_Job_Level_Band              : int  2 2 1 2 1 2
 $ Contact_Job_Department_Band         : int  6 6 3 6 6 6
 $ Contact_Sphere_Band                 : int  4 2 1 1 1 4
 $ Bizible_Touchpoint_Count            : int  1 6 1 1 1 0
 $ Bizible_Touchpont_Band              : int  2 6 2 2 2 2
 $ Lead_Source_Type_Band               : int  0 0 1 1 1 0
 $ Person.Score                        : int  90 260 35 35 30 20
 $ Person_Score_Band                   : int  4 6 2 2 2 1
 $ Behavior.Score                      : int  40 15 0 0 0 0
 $ Behavior.Score.Band                 : int  2 1 1 1 1 1
 $ Demographic.Score                   : int  25 225 20 20 20 10
 $ Demographic_Score_Band              : int  1 6 1 1 1 1
 $ SQL                                 : int  1 1 1 1 1 1
as.numeric(as.character(sql_inputs_formatted$Account_Global_Region_Cascading_Band))
as.numeric(as.character(sql_inputs_formatted$Account_Annual_Revenue_Cascading))
as.numeric(as.character(sql_inputs_formatted$Account_Annual_Revenue))
as.numeric(as.character(sql_inputs_formatted$Account_NAICS_Code_Cascading))
as.numeric(as.character(sql_inputs_formatted$Account_Employee_Count_Cascading))
as.numeric(as.character(sql_inputs_formatted$Account_Employee_Count_Band))
as.numeric(as.character(sql_inputs_formatted$Account_Buyer_Industry_Cascading.1))
as.numeric(as.character(sql_inputs_formatted$Active_Nodes))
as.numeric(as.character(sql_inputs_formatted$Active_Node_Bands))
as.numeric(as.character(sql_inputs_formatted$Account_Fit_Score))
as.numeric(as.character(sql_inputs_formatted$Account_Fit_Score_Bands))
as.numeric(as.character(sql_inputs_formatted$Predictive_Engagement_Score_Bands))
as.numeric(as.character(sql_inputs_formatted$Engaged_People))
as.numeric(as.character(sql_inputs_formatted$Engagement_Minutes_3_mo))
as.numeric(as.character(sql_inputs_formatted$Engagement_Minutes_7.days))
as.numeric(as.character(sql_inputs_formatted$Engagio_Status_Bands))
as.numeric(as.character(sql_inputs_formatted$DF_Total_Funding))
as.numeric(as.character(sql_inputs_formatted$Number_of_People))
as.numeric(as.character(sql_inputs_formatted$Fortune_Rank))
as.numeric(as.character(sql_inputs_formatted$Expected_Node_Count_Band))
as.numeric(as.character(sql_inputs_formatted$Contact_Job_Level_Band))
as.numeric(as.character(sql_inputs_formatted$Contact_Job_Department_Band))
as.numeric(as.character(sql_inputs_formatted$Contact_Sphere_Band))
as.numeric(as.character(sql_inputs_formatted$Bizible_Touchpoint_Count))
as.numeric(as.character(sql_inputs_formatted$Lead_Source_Type_Band))
as.numeric(as.character(sql_inputs_formatted$Person.Score))
as.numeric(as.character(sql_inputs_formatted$Behavior.Score))
as.numeric(as.character(sql_inputs_formatted$Behavior.Score.Band))
as.numeric(as.character(sql_inputs_formatted$Demographic.Score))
as.numeric(as.character(sql_inputs_formatted$Demographic_Score_Band))
as.numeric(as.character(sql_inputs_formatted$SQL))

ATTACHMENT: enter image description here

All the best, Andrew

$\endgroup$
0
$\begingroup$

as.matrix(sql_inputs_formatted) should work.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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