Sparse.model.matrix error message


Sparse.model.matrix error message



I'm trying to create a sparse-matrix and get this error message:



Error: fnames == names(mf) are not all TRUE



I think it has something to do with the column names of my data, maybe you can help.



Here are the column names:



Error: fnames == names(mf) are not all TRUE


colnames(trainDataShrinkage) <-"Bildungsgrad2_Lower_secondary_education"
,"Bildungsgrad3_Upper_secondary_education"
,"Bildungsgrad4_Post-secondary_non-tertiary_education"
,"Bildungsgrad5_Short-cycle_tertiary_education"
,"Bildungsgrad6_Bachelors_or_equivalent_level"
,"Bildungsgrad7_Masters_or_equivalent_level"
,"Bildungsgrad8_Doctoral_or_equivalent_level"
,"Familienstand2_Verheiratet,_getrenntlebend"
,"Familienstand3_Ledig"
,"Familienstand4_Geschieden,_eing._gleichg._Partn._aufgehoben"
,"Familienstand5_Verwitwet,_Lebenspartner/in_verstorben"
,"Familienstand6_Eing._gleichg._Partn.,_zusammenlebend"
,"Geschlecht2_Weiblich"
,"Migrationshintergrund2_direkter_Migrationshintergrund"
,"Migrationshintergrund3_indirekter_Migrationshintergrund"
,"Bundesland2_Hamburg"
,"Bundesland3_Niedersachsen"
,"Bundesland4_Bremen"
,"Bundesland5_Nordrhein-Westfalen"
,"Bundesland6_Hessen"
,"Bundesland7_Rheinland-Pfalz"
,"Bundesland8_Baden-Wuerttemberg"
,"Bundesland9_Bayern"
,"Bundesland10_Saarland"
,"Bundesland11_Berlin_(West_und_Ost)"
,"Bundesland12_Brandenburg"
,"Bundesland13_Mecklenburg-Vorpommern"
,"Bundesland14_Sachsen"
,"Bundesland15_Sachsen-Anhalt"
,"Bundesland16_Thueringen"
,"Unternehmengroesse2_5 bis_10"
,"Unternehmengroesse3_11_bis_unter_20"
,"Unternehmengroesse6_20_bis_unter_100"
,"Unternehmengroesse7_100_bis_unter_200"
,"Unternehmengroesse9_200_bis_unter_2000"
,"Unternehmengroesse10_2000_und_mehr"
,"Erwerbsstatus2_Teilzeitbeschaeftigung"
,"Erwerbsstatus4_Geringfuegig_beschaeftigt"
,"Stundenlohn"
,"AlterEins"
,"AlterZwei"
,"AlterDrei"
,"AlterFuenF"
,"AlterSechs"
,"BildungsjahreEins"
,"BildungsjahreZwei"
,"BildungsjahreDrei"
,"BildungsjahreVier"
,"BildungsjahreFuenf"
,"ArbeitsmarkterfahrungVollzeitEins"
,"ArbeitsmarkterfahrungVollzeitZwei"
,"ArbeitsmarkterfahrungVollzeitDrei"
,"ArbeitsmarkterfahrungVollzeitVier"
,"ArbeitsmarkterfahrungVollzeitFuenf"
,"ArbeitsmarkterfahrungTeilzeitEins"
,"ArbeitsmarkterfahrungTeilzeitZwei"
,"ArbeitsmarkterfahrungTeilzeitDrei"
,"ArbeitsmarkterfahrungTeilzeitVier"
,"ArbeitsmarkterfahrungTeilzeitFuenf"
,"BruttoverdienstLetztenMonatEins"
,"BruttoverdienstLetztenMonatZwei"
,"BruttoverdienstLetztenMonatDrei"
,"BruttoverdienstLetztenMonatVier"
,"BruttoverdienstLetztenMonatFuenf")




1 Answer
1



It does not like some special characters in the column names. I faced issues with column names starting with #, 1, . and /. Can you try to replace these occurrences with '_'.



Simplest way would be to trim your column names off any special characters. Let me know if you cannot rename them due to any limitation.





i replaced all , . / - with _ and still have they same error
– Kurakov
2 days ago





Did you also replace '()' ?
– Kdulam
2 days ago





yes i also replaced()
– Kurakov
2 days ago






okay i found the reason why it didnt worked. I also have to replace spaces with _
– Kurakov
2 days ago





Yes, sorry i forgot to mention Spaces. Its that and any special characters. Glad it worked out. Happy Coding!
– Kdulam
2 days ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift