My issue is that I have a dataset with over 200 variables, some are numerical and some are categorical (encoded as 0 or 1). My goal is to use ggplot2
to make a bar graph to show two bars of categorical vs numerical data.
Another problem I'm facing is that I also don't know how to identify which columns are continuous and which are categorical since using str
only gives me the first ~90 columns' breakdown and not the rest. Sorry if this is an extremely beginner question but I'm trying to build my R skills and this problem has stumped me.
The plan in my head was to somehow make 2 columns (potentially using summarise
), one column being categorical data and the other being numerical and then using geom_col
to make the chart, but it isn't panning out as I planned.
I've put a dput of the data and this only includes the first 6 rows of the data (of which there are a million).
EDIT:
I just remembered that summary
is a function and I can use it to get the summary of all the columns. So that's one way of identifying which columns are numerical/categorical.
structure(list(id = 0:5, f0 = c(0.205979, 0.181004, 0.182583,
0.18024, 0.177172, 0.255237), f1 = c(0.410993, 0.473119, 0.307431,
0.494592, 0.495513, 0.345842), f2 = c(0.176775, 0.0117337, 0.32595,
0.0083673, 0.0142631, 0.0215491), f3 = c(0.223581, 0.213657,
0.207116, 0.22358, 0.548819, 0.220755), f4 = c(0.423543, 0.619678,
0.605699, 0.760618, 0.625396, 0.524854), f5 = c(0.47614, 0.441593,
0.309695, 0.439211, 0.562493, 0.423693), f6 = c(0.41359, 0.230407,
0.493337, 0.432055, 0.117158, 0.53315), f7 = c(0.612021, 0.686013,
0.751107, 0.776147, 0.561255, 0.628484), f8 = c(0.534873, 0.281971,
0.536272, 0.483958, 0.0771147, 0.340781), f9 = c(0.147295, 0.238509,
0.286813, 0.260886, 0.158321, 0.146893), f10 = c(0.0261771, 0.493411,
0.139532, 0.147122, 0.260239, 0.15273), f11 = c(0.106613, 0.107277,
0.107222, 0.105433, 0.102561, 0.105788), f12 = c(0.200924, 0.231828,
0.247791, 0.287755, 0.265285, 0.187001), f13 = c(0.713191, 0.45715,
0.631949, 0.455777, 0.503776, 0.529869), f14 = c(0.15575, 0.3952,
0.347463, 0.247971, 0.269776, 0.177117), f15 = c(0.557335, 0.617088,
0.642173, 0.616628, 0.545945, 0.602677), f16 = c(0.341702, 0.459358,
0.257763, 0.335907, 0.319548, 0.345858), f17 = c(0.28572, 0.209225,
0.162548, 0.337025, 0.278538, 0.324575), f18 = c(0.230396, 0.201098,
0.327377, 0.239127, 0.214922, 0.244007), f19 = c(0.203957, 0.199383,
0.193583, 0.176163, 0.200239, 0.22411), f20 = c(0.509588, 0.366578,
0.49544, 0.538269, 0.534551, 0.477728), f21 = c(0.706972, 0.585788,
0.636742, 0.706468, 0.728652, 0.777664), f22 = c(1L, 1L, 0L,
1L, 0L, 1L), f23 = c(0.00779271, 0.285311, 0.00713318, 0.00882891,
0.00483992, 0.00277594), f24 = c(0.247765, 0.400367, 0.309747,
0.353799, 0.323546, 0.257023), f25 = c(0.26375, 0.162493, 0.221081,
0.219977, 0.166292, 0.346681), f26 = c(0.259555, 0.249365, 0.28481,
0.266858, 0.285516, 0.23055), f27 = c(0.23173, 0.14116, 0.230828,
0.145617, 0.208651, 0.14439), f28 = c(0.138379, 0.133688, 0.138271,
0.13859, 0.200394, 0.140246), f29 = c(0.197824, 0.247906, 0.199742,
0.234925, 0.198155, 0.372983), f30 = c(0.0543923, 0.139251, 0.0604075,
0.0598173, 0.414729, 0.210188), f31 = c(0.194153, 0.216444, 0.146746,
0.140886, 0.251997, 0.154155), f32 = c(0.2815, 0.109674, 0.208131,
0.205023, 0.193405, 0.262118), f33 = c(0.0348178, 0.0330182,
0.0359773, 0.319312, 0.0344898, 0.0424123), f34 = c(0.0253337,
0.0174584, 0.0226313, 0.00997192, 0.0164647, 0.00876692), f35 = c(0.114432,
0.189336, 0.113542, 0.112291, 0.197312, 0.212664), f36 = c(0.139203,
0.168785, 0.274871, 0.288915, 0.207429, 0.142091), f37 = c(0.246157,
0.184251, 0.18277, 0.332632, 0.255857, 0.189681), f38 = c(0.251371,
0.202753, 0.151502, 0.140831, 0.139875, 0.191045), f39 = c(0.701423,
0.218451, 0.570035, 0.473845, 0.321039, 0.512447), f40 = c(0.301182,
0.324364, 0.271744, 0.423955, 0.182084, 0.282717), f41 = c(0.193924,
0.255499, 0.206439, 0.243941, 0.250127, 0.180514), f42 = c(0.267497,
0.287433, 0.20769, 0.259576, 0.210941, 0.318404), f43 = c(0L,
0L, 0L, 0L, 0L, 1L), f44 = c(0.19343, 0.821982, 0.162094, 0.834834,
0.844187, 0.833346), f45 = c(0.23863, 0.284351, 0.176569, 0.176857,
0.180589, 0.249247), f46 = c(0.15477, 0.177537, 0.198756, 0.158319,
0.162991, 0.168063), f47 = c(0.249857, 0.207924, 0.203, 0.387808,
0.240422, 0.258782), f48 = c(0.210685, 0.209812, 0.20962, 0.334391,
0.242435, 0.211146), f49 = c(0.406662, 0.186463, 0.189327, 0.187999,
0.186832, 0.20528), f50 = c(0.21481, 0.177476, 0.175949, 0.49832,
0.178233, 0.173018), f51 = c(0.258668, 0.321973, 0.179615, 0.177429,
0.179031, 0.180383), f52 = c(0.377518, 0.244173, 0.215551, 0.235699,
0.216712, 0.217522), f53 = c(0.192042, 0.224053, 0.239486, 0.17525,
0.249345, 0.237658), f54 = c(0.340855, 0.186513, 0.211676, 0.187267,
0.204219, 0.189119), f55 = c(0.19966, 0.305412, 0.175939, 0.231274,
0.172806, 0.179439), f56 = c(0.264074, 0.130774, 0.410515, 0.130341,
0.286873, 0.266468), f57 = c(0.20555, 0.170331, 0.169127, 0.180271,
0.183107, 0.197002), f58 = c(0.0751093, 0.241071, 0.0780515,
0.177084, 0.0856055, 0.0777128), f59 = c(0.205688, 0.246026,
0.254501, 0.277188, 0.334205, 0.210231), f60 = c(0.178962, 0.146584,
0.246476, 0.149774, 0.142723, 0.425218), f61 = c(0.245008, 0.225636,
0.271976, 0.240298, 0.204273, 0.311011), f62 = c(0.519336, 0.447242,
0.749593, 0.605277, 0.415167, 0.672393), f63 = c(0.306419, 0.176352,
0.175384, 0.172028, 0.173777, 0.212197), f64 = c(0.127139, 0.201398,
0.124792, 0.130512, 0.131868, 0.24262), f65 = c(0.367479, 0.269459,
0.171549, 0.258989, 0.31257, 0.245935), f66 = c(0.23638, 0.292691,
0.262281, 0.191919, 0.191401, 0.338846), f67 = c(0.195694, 0.180824,
0.300476, 0.228763, 0.183941, 0.288842), f68 = c(0.0131946, 0.0134969,
0.21631, 0.209845, 0.213248, 0.203026), f69 = c(0.199588, 0.228739,
0.164643, 0.179141, 0.149717, 0.184661), f70 = c(0.283367, 0.472396,
0.280466, 0.481151, 0.479134, 0.644471), f71 = c(0.168824, 0.168721,
0.203379, 0.167182, 0.172482, 0.183972), f72 = c(0.00485497,
0.00431214, 0.00450731, 0.00280641, 0.00421919, 0.00277695),
f73 = c(0.117723, 0.300805, 0.216858, 0.296244, 0.201649,
0.293068), f74 = c(0.257688, 0.415982, 0.274105, 0.260443,
0.215576, 0.201891), f75 = c(0.197262, 0.196219, 0.19622,
0.287999, 0.195598, 0.194176), f76 = c(0.211452, 0.17279,
0.162854, 0.211924, 0.154246, 0.18795), f77 = c(0.372637,
0.352968, 0.318504, 0.465532, 0.345664, 0.371596), f78 = c(0.198157,
0.23261, 0.261242, 0.17846, 0.189286, 0.186211), f79 = c(0.68997,
0.606188, 0.564383, 0.545248, 0.572118, 0.516633), f80 = c(0.449955,
0.460567, 0.441597, 0.477845, 0.413406, 0.438683), f81 = c(0.71311,
0.703051, 0.664491, 0.6828, 0.684964, 0.723415), f82 = c(0.212041,
0.213396, 0.218721, 0.228464, 0.216381, 0.21688), f83 = c(0.183619,
0.233853, 0.154807, 0.160022, 0.212603, 0.152865), f84 = c(0.288667,
0.0225595, 0.0174673, 0.451457, 0.00784774, 0.0146216), f85 = c(0.648678,
0.529151, 0.645717, 0.621233, 0.536482, 0.547742), f86 = c(0.600398,
0.496101, 0.364822, 0.618612, 0.557684, 0.566896), f87 = c(0.223267,
0.188039, 0.185882, 0.165683, 0.198738, 0.165412), f88 = c(0.590163,
0.31264, 0.211491, 0.204384, 0.178637, 0.303006), f89 = c(0.248847,
0.210123, 0.29336, 0.15953, 0.245034, 0.271566), f90 = c(0.795641,
0.835844, 0.477802, 0.49647, 0.514771, 0.406773), f91 = c(0.139932,
0.169867, 0.495697, 0.26611, 0.427435, 0.270663), f92 = c(0.618696,
0.688726, 0.512464, 0.459905, 0.511809, 0.677383), f93 = c(0.639142,
0.678031, 0.702827, 0.127136, 0.521353, 0.774171), f94 = c(0.00854853,
0.00474478, 0.0146961, 0.00834716, 0.00711112, 0.00765453
), f95 = c(0.559151, 0.145737, 0.144596, 0.146811, 0.148517,
0.143779), f96 = c(0.57364, 0.162314, 0.163786, 0.162876,
0.162357, 0.42667), f97 = c(0.138808, 0.232351, 0.228586,
0.28379, 0.226104, 0.230674), f98 = c(0.499156, 0.0172355,
0.171948, 0.0160375, 0.00816107, 0.00654037), f99 = c(0.112203,
0.111834, 0.110486, 0.361132, 0.113454, 0.110359), f100 = c(0.181498,
0.210767, 0.284144, 0.184569, 0.25576, 0.189231), f101 = c(0.165887,
0.322257, 0.340463, 0.332192, 0.265153, 0.363179), f102 = c(0.0931709,
0.0946931, 0.0906748, 0.0937519, 0.0938302, 0.0930987), f103 = c(0.106952,
0.107586, 0.374007, 0.168246, 0.107421, 0.109402), f104 = c(0.127861,
0.0151669, 0.00978475, 0.310551, 0.126748, 0.126214), f105 = c(0.250924,
0.366396, 0.383777, 0.255281, 0.030215, 0.246414), f106 = c(0.501673,
0.161434, 0.214091, 0.134932, 0.207409, 0.297587), f107 = c(0.0367395,
0.0377841, 0.0384423, 0.0362577, 0.132724, 0.0378212), f108 = c(0.111361,
0.187185, 0.108502, 0.112279, 0.109432, 0.113226), f109 = c(0.0759184,
0.118134, 0.156583, 0.122642, 0.0766613, 0.0718116), f110 = c(0.0194442,
0.0131518, 0.0200242, 0.0231604, 0.0265451, 0.0267337), f111 = c(0.25076,
0.232125, 0.214525, 0.246768, 0.158171, 0.151966), f112 = c(0.465093,
0.146513, 0.247209, 0.28035, 0.307366, 0.152632), f113 = c(0.087502,
0.0843095, 0.0859332, 0.0855842, 0.0836992, 0.0869702), f114 = c(0.00418475,
0.138346, 0.00903916, 0.0816367, 0.0145687, 0.0170051), f115 = c(0.195936,
0.281625, 0.182059, 0.167441, 0.185126, 0.166497), f116 = c(0.166389,
0.166673, 0.165421, 0.295566, 0.1667, 0.167), f117 = c(0.171328,
0.172128, 0.250517, 0.171693, 0.233375, 0.171187), f118 = c(0.146014,
0.0870872, 0.0888492, 0.14849, 0.0891672, 0.084485), f119 = c(0.199232,
0.17797, 0.166452, 0.164541, 0.180105, 0.166683), f120 = c(0.133999,
0.233744, 0.022483, 0.0266703, 0.0188624, 0.227958), f121 = c(0.168191,
0.217005, 0.189192, 0.168976, 0.169766, 0.194631), f122 = c(0.010242,
0.00879878, 0.180499, 0.0902695, 0.254478, 0.0102328), f123 = c(0.29449,
0.0286304, 0.266176, 0.0215818, 0.315526, 0.11173), f124 = c(0.0129772,
0.00734746, 0.00966264, 0.0108653, 0.00377826, 0.180101),
f125 = c(0.00396898, 0.00478429, 0.00350172, 0.00891461,
0.00591282, 0.00574104), f126 = c(0.0137389, 0.0122833, 0.01613,
0.0106881, 0.0127259, 0.0164608), f127 = c(0.0400764, 0.0814183,
0.042034, 0.040018, 0.0479119, 0.0486109), f128 = c(0.170711,
0.172358, 0.167598, 0.168854, 0.274214, 0.172247), f129 = c(0.250246,
0.254012, 0.274962, 0.249082, 0.252435, 0.253467), f130 = c(0.195538,
0.130545, 0.129131, 0.137523, 0.437068, 0.201123), f131 = c(0.708556,
0.708918, 0.705977, 0.708682, 0.706935, 0.703609), f132 = c(0.448925,
0.42795, 0.429651, 0.416802, 0.416283, 0.426115), f133 = c(0.550352,
0.551945, 0.57525, 0.571273, 0.550451, 0.643521), f134 = c(0.217984,
0.222525, 0.224012, 0.248067, 0.21975, 0.217423), f135 = c(0.751629,
0.747199, 0.715692, 0.723089, 0.723113, 0.715747), f136 = c(0.822459,
0.820548, 0.819017, 0.819892, 0.82181, 0.822545), f137 = c(0.186298,
0.186604, 0.186921, 0.184337, 0.186963, 0.184453), f138 = c(0.0241969,
0.861636, 0.029521, 0.731664, 0.0196157, 0.81938), f139 = c(0.0440971,
0.53655, 0.573076, 0.651212, 0.541864, 0.53461), f140 = c(0.0789431,
0.0807445, 0.0806273, 0.0791886, 0.076189, 0.0822097), f141 = c(0.181147,
0.0198446, 0.0261064, 0.17709, 0.0123222, 0.30891), f142 = c(0.022591,
0.0328465, 0.408483, 0.0305256, 0.0194522, 0.406271), f143 = c(0.576712,
0.623617, 0.0706079, 0.549967, 0.786651, 0.0878426), f144 = c(0.406843,
0.0349813, 0.738622, 0.692899, 0.0273897, 0.0305774), f145 = c(0.510578,
0.714859, 0.511274, 0.731004, 0.632851, 0.742482), f146 = c(0.799434,
0.772612, 0.749761, 0.132668, 0.798959, 0.449932), f147 = c(0.651125,
0.238379, 0.653871, 0.654234, 0.657175, 0.657582), f148 = c(0.460708,
0.134555, 0.495641, 0.49854, 0.490563, 0.528362), f149 = c(0.636714,
0.458582, 0.377781, 0.577893, 0.763264, 0.586127), f150 = c(0.350704,
0.349, 0.343877, 0.346137, 0.350492, 0.349394), f151 = c(0.872989,
0.874695, 0.785149, 0.876881, 0.739302, 0.874989), f152 = c(0.00775086,
0.0266352, 0.0192592, 0.0239041, 0.0108278, 0.0168011), f153 = c(0.0171031,
0.617291, 0.00328705, 0.0231351, 0.0104208, 0.0175228), f154 = c(0.0198748,
0.0112022, 0.42505, 0.428267, 0.0106496, 0.0191382), f155 = c(0.203042,
0.201488, 0.205863, 0.206447, 0.200671, 0.200632), f156 = c(0.864594,
0.866689, 0.401814, 0.874224, 0.863533, 0.868254), f157 = c(0.595877,
0.0417948, 0.68611, 0.602061, 0.56418, 0.566479), f158 = c(0.542969,
0.63295, 0.497687, 0.0235163, 0.0239648, 0.0174306), f159 = c(0.99025,
0.994544, 0.992871, 0.992893, 0.996923, 0.990412), f160 = c(0.0203726,
0.0132554, 0.0283399, 0.699298, 0.0103345, 0.0255842), f161 = c(0.00623812,
0.00690825, 0.390101, 0.0110718, 0.00932452, 0.00512325),
f162 = c(0.0110403, 0.00373931, 0.014232, 0.00472005, 0.0103996,
0.00714041), f163 = c(0.00601871, 0.00647825, 0.0107123,
0.0131132, 0.00967258, 0.00686035), f164 = c(0.407014, 0.0904678,
0.0900319, 0.0915269, 0.0924836, 0.0904473), f165 = c(0.0801402,
0.0817649, 0.0774046, 0.0808828, 0.0817591, 0.0793126), f166 = c(0.0135023,
0.0150858, 0.0135566, 0.00890857, 0.323262, 0.00697369),
f167 = c(0.144265, 0.144639, 0.142851, 0.208734, 0.143824,
0.143776), f168 = c(0.00722897, 0.00880811, 0.280431, 0.00875111,
0.0103486, 0.00770517), f169 = c(0.00325605, 0.00570845,
0.00616985, 0.00610196, 0.00322787, 0.127835), f170 = c(0.0145555,
0.0113171, 0.0181722, 0.00803094, 0.00890864, 0.00914715),
f171 = c(0.123806, 0.00799705, 0.0170709, 0.0153184, 0.0120795,
0.0102979), f172 = c(0.133871, 0.133067, 0.135464, 0.133295,
0.132252, 0.132211), f173 = c(0.0115314, 0.00800969, 0.00830626,
0.0103102, 0.0113799, 0.0106431), f174 = c(0.01025, 0.00576756,
0.012026, 0.0110344, 0.00883222, 0.00445361), f175 = c(0.25375,
0.0220156, 0.00946835, 0.0185532, 0.118965, 0.135863), f176 = c(0.0901617,
0.0915084, 0.0945196, 0.395968, 0.0926637, 0.0889005), f177 = c(0.147857,
0.108732, 0.105624, 0.105859, 0.186997, 0.109143), f178 = c(0.303087,
0.180742, 0.205675, 0.267114, 0.150604, 0.148729), f179 = c(0.112764,
0.00811474, 0.0113062, 0.0129122, 0.188779, 0.0151103), f180 = c(0.104344,
0.147373, 0.106958, 0.234323, 0.187091, 0.148508), f181 = c(0.168583,
0.196966, 0.25571, 0.169078, 0.170887, 0.169115), f182 = c(0.0113421,
0.0129, 0.0111406, 0.402167, 0.00932068, 0.00537193), f183 = c(0.239028,
0.402807, 0.213636, 0.145057, 0.137853, 0.147523), f184 = c(0.0080181,
0.366473, 0.0100735, 0.00787029, 0.386982, 0.00493245), f185 = c(0.167653,
0.137001, 0.194227, 0.209357, 0.146626, 0.160962), f186 = c(0.217342,
0.254902, 0.333723, 0.22098, 0.296619, 0.259621), f187 = c(0.184178,
0.139658, 0.182061, 0.139231, 0.0969613, 0.136193), f188 = c(0.17906,
0.173887, 0.0163325, 0.00593593, 0.0996525, 0.096063), f189 = c(0.0780094,
0.0779325, 0.0751663, 0.078739, 0.0774108, 0.0816943), f190 = c(0.135768,
0.133428, 0.13505, 0.137634, 0.177526, 0.136796), f191 = c(0.00653366,
0.132297, 0.252896, 0.00746181, 0.279102, 0.00604987), f192 = c(0.00983182,
0.00878965, 0.00964862, 0.00565325, 0.0102574, 0.00208378
), f193 = c(0.0133175, 0.623407, 0.0158064, 0.00424982, 0.00523053,
0.0101397), f194 = c(0.390079, 0.40735, 0.0131159, 0.0141088,
0.015248, 0.0161143), f195 = c(0.0048006, 0.0128724, 0.122997,
0.0113782, 0.013281, 0.00467389), f196 = c(0.0565999, 0.05968,
0.143064, 0.144935, 0.148521, 0.229058), f197 = c(0.114139,
0.0515508, 0.0528888, 0.324393, 0.0563958, 0.0510632), f198 = c(0.012599,
0.00785992, 0.0117101, 0.00629401, 0.330496, 0.00973795),
f199 = c(0.0148175, 0.0148815, 0.012503, 0.0115951, 0.129898,
0.0104436), f200 = c(0.446073, 0.161739, 0.289838, 0.395579,
0.404324, 0.531233), f201 = c(0.216079, 0.240681, 0.163251,
0.163644, 0.23377, 0.16724), f202 = c(0.152113, 0.202786,
0.152532, 0.152773, 0.153135, 0.283164), f203 = c(0.111237,
0.0572263, 0.0589189, 0.0532894, 0.0540616, 0.0581285), f204 = c(0.170896,
0.171921, 0.234702, 0.173113, 0.170713, 0.169657), f205 = c(0.190477,
0.093504, 0.0992864, 0.142118, 0.0942917, 0.0979218), f206 = c(0.0119361,
0.0112854, 0.00922959, 0.00741204, 0.0137314, 0.00838844),
f207 = c(0.0052268, 0.00830068, 0.00702313, 0.00815466, 0.00319317,
0.00742868), f208 = c(0.42974, 0.438884, 0.0156424, 0.0128732,
0.0260431, 0.012408), f209 = c(0.0130596, 0.00853464, 0.00900314,
0.00818217, 0.0107202, 0.163032), f210 = c(0.199369, 0.19743,
0.198217, 0.199155, 0.197807, 0.198642), f211 = c(0.25841,
0.269382, 0.188984, 0.189123, 0.227081, 0.191721), f212 = c(0.208863,
0.476575, 0.277815, 0.117435, 0.116094, 0.195567), f213 = c(0.129545,
0.193125, 0.155073, 0.292135, 0.258921, 0.229067), f214 = c(0.00697845,
0.164553, 0.0109542, 0.0103391, 0.00389366, 0.00502581),
f215 = c(0.0129482, 0.193796, 0.00675169, 0.00767631, 0.00937485,
0.00901705), f216 = c(0.0494655, 0.0519386, 0.0498809, 0.053168,
0.051085, 0.0524635), f217 = c(0.00880425, 0.112805, 0.00885345,
0.0051708, 0.00881312, 0.00735628), f218 = c(0.114205, 0.117136,
0.116385, 0.113209, 0.111952, 0.114077), f219 = c(0.119683,
0.00749656, 0.127872, 0.130026, 0.0109755, 0.253709), f220 = c(0.19121,
0.188227, 0.154898, 0.190459, 0.156167, 0.154024), f221 = c(0.169976,
0.170947, 0.15249, 0.173361, 0.176744, 0.14858), f222 = c(0.188199,
0.0170151, 0.0194859, 0.0183313, 0.0242529, 0.189866), f223 = c(0.355674,
0.0149358, 0.346187, 0.0136594, 0.00680298, 0.340906), f224 = c(0.0131642,
0.00935609, 0.0116285, 0.0087308, 0.0121423, 0.0070031),
f225 = c(0.304878, 0.00809456, 0.00419791, 0.00439017, 0.00735293,
0.0108651), f226 = c(0.00721283, 0.21546, 0.00689942, 0.00743819,
0.00729541, 0.00514002), f227 = c(0.0112769, 0.0110305, 0.0095461,
0.00625075, 0.00652742, 0.0141166), f228 = c(0.0831857, 0.3395,
0.0847955, 0.0830153, 0.0797272, 0.0775788), f229 = c(0.0106239,
0.0096396, 0.00971543, 0.00972325, 0.00867306, 0.0097693),
f230 = c(0.0311985, 0.028568, 0.026858, 0.0296188, 0.0275322,
0.0277257), f231 = c(0.200306, 0.233639, 0.221741, 0.191215,
0.206406, 0.126783), f232 = c(0.195791, 0.195675, 0.195907,
0.196332, 0.194853, 0.196891), f233 = c(0.20347, 0.203766,
0.204326, 0.20426, 0.20572, 0.201783), f234 = c(0.036314,
0.0840147, 0.14259, 0.0311318, 0.174073, 0.078024), f235 = c(0.157711,
0.206317, 0.291537, 0.198538, 0.189884, 0.123239), f236 = c(0.199117,
0.249256, 0.205421, 0.280397, 0.165742, 0.169384), f237 = c(0.0074436,
0.003758, 0.00880719, 0.0023423, 0.00195727, 0.00328608),
f238 = c(0.189048, 0.269871, 0.125082, 0.125658, 0.169822,
0.247377), f239 = c(0.20254, 0.200669, 0.199523, 0.198827,
0.199123, 0.194986), f240 = c(0.273267, 0.166494, 0.196465,
0.171466, 0.141719, 0.138999), f241 = c(0.167211, 0.211146,
0.238307, 0.216006, 0.217416, 0.137174), f242 = c(1L, 1L,
0L, 1L, 0L, 0L), f243 = c(0L, 0L, 0L, 0L, 0L, 0L), f244 = c(1L,
0L, 1L, 1L, 1L, 1L), f245 = c(1L, 0L, 1L, 1L, 1L, 1L), f246 = c(1L,
1L, 1L, 1L, 0L, 0L), f247 = c(0L, 0L, 1L, 1L, 0L, 0L), f248 = c(0L,
0L, 0L, 0L, 0L, 1L), f249 = c(0L, 1L, 0L, 1L, 1L, 0L), f250 = c(0L,
0L, 1L, 1L, 1L, 1L), f251 = c(0L, 1L, 0L, 0L, 1L, 1L), f252 = c(0L,
0L, 0L, 1L, 0L, 0L), f253 = c(1L, 1L, 0L, 1L, 1L, 1L), f254 = c(0L,
1L, 0L, 0L, 0L, 0L), f255 = c(1L, 0L, 0L, 1L, 1L, 1L), f256 = c(1L,
0L, 0L, 0L, 0L, 1L), f257 = c(0L, 0L, 0L, 0L, 0L, 0L), f258 = c(0L,
1L, 1L, 0L, 1L, 0L), f259 = c(0L, 0L, 1L, 0L, 1L, 1L), f260 = c(1L,
0L, 0L, 0L, 0L, 0L), f261 = c(0L, 0L, 1L, 0L, 1L, 0L), f262 = c(0L,
0L, 0L, 0L, 0L, 0L), f263 = c(1L, 1L, 0L, 0L, 0L, 0L), f264 = c(1L,
1L, 0L, 1L, 0L, 0L), f265 = c(0L, 0L, 0L, 0L, 1L, 0L), f266 = c(0L,
1L, 0L, 1L, 0L, 0L), f267 = c(0L, 1L, 0L, 1L, 0L, 0L), f268 = c(1L,
0L, 0L, 0L, 0L, 1L), f269 = c(1L, 0L, 0L, 0L, 0L, 0L), f270 = c(0L,
0L, 1L, 1L, 1L, 1L), f271 = c(1L, 1L, 1L, 0L, 1L, 0L), f272 = c(0L,
0L, 0L, 0L, 0L, 1L), f273 = c(1L, 0L, 0L, 0L, 0L, 0L), f274 = c(1L,
1L, 1L, 0L, 1L, 0L), f275 = c(0L, 1L, 0L, 1L, 0L, 0L), f276 = c(0L,
0L, 0L, 0L, 0L, 0L), f277 = c(1L, 1L, 0L, 0L, 1L, 0L), f278 = c(0L,
0L, 0L, 0L, 1L, 1L), f279 = c(0L, 0L, 1L, 0L, 0L, 0L), f280 = c(0L,
0L, 1L, 1L, 1L, 1L), f281 = c(0L, 0L, 0L, 0L, 0L, 0L), f282 = c(0L,
0L, 0L, 0L, 0L, 0L), f283 = c(0L, 0L, 0L, 0L, 1L, 0L), f284 = c(0L,
0L, 0L, 0L, 0L, 0L), target = c(1L, 1L, 1L, 1L, 1L, 0L)), row.names = c(NA,
-6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000013debbe1ef0>)
CodePudding user response:
All the columns are numeric
df1[, which(sapply(.SD, is.numeric))]
If we are looking for specific values i.e. 0 and 1
binary <- df1[, which(sapply(.SD, function(x) all(c(0, 1) %in% x)))]
conti <- setdiff(seq_along(df1), binary)
It can be tested with
>df1[, sum(sapply(.SD, is.numeric))]
[1] 287
> ncol(df1)
[1] 287
CodePudding user response:
You can use the class
function along with a sapply
to get all the columns types.
Here I made a little example:
df = data.frame(matrix(as.numeric(runif(10*10)),ncol = 10),
matrix(sample(c(0L, 1L), size = 100, replace = TRUE), ncol = 10))
sapply(df, class)
Your binary columns will appear as 'integer'.