0

image of the "locked" row

How do I format my dataframe to match the "wine" database with the first row with names being separated from the rest of the data?

I’m moving this data from excel to r.

I'm trying to run k-means clustering and need only the numerical data in the dataframe but would also like to label my data points on the visuals.

Current Structure:

structure(list(...1 = c("MC", "MPK", "MT", "HG1", "DSL1", "TC1", 
"WeC1", "MS1", "PS1", "MOG1", "ZC1", "HG2", "TC2", "WeC2", "MS2", 
"PS2", "MOG2", "ZC2", "BW1", "SB1", "BD1", "PH1", "OGK1", "JH1", 
"CD1", "SD_US1", "BG1", "AB1", "BW2", "SB2", "BD2", "PH2", "OGK2", 
"JH2", "CD2", "SD_US2", "BG2", "AB2", "WC1", "WC2", "WC3", "WC4", 
"WC5", "HC2", "HC3", "HC4", "HC5", "AH1", "AH2", "AH3", "AH4", 
"AH5", "MTA1", "MTA2", "MTA3", "MTA4", "MTA5", "MTB1", "MTB2", 
"MTB3", "MTB4", "MTB5", "SD1", "SD2", "SD3", "SD4", "SD5"), CB_0002 = c(6.67, 
-1.373333333, 1.103333333, -1.956666667, 9.726666667, 9.873333333, 
8.916666667, 7.283333333, 7.453333333, 9.9, 8.203333333, -2.125, 
8.81, 8.88, 7.41, 7.51, 9.706666667, 6.973333333, 6.086666667, 
6.153333333, 1.946666667, 2.526666667, 4.173333333, 2.251666667, 
1.618333333, 2.89, 4.56, 0.01, 4.843333333, 6.776666667, 3.131666667, 
2.318333333, 4.096666667, 6.496666667, 3.313333333, 2.466666667, 
4.776666667, 0.223333333, 5.475999025, 0.511470012, 1.760665355, 
1.912034038, 0.75340849, 0.645777573, 2.172985911, 2.093470652, 
2.85538945, 4.11152797, 2.789046309, 2.018148314, 0.388894462, 
3.515294438, 6.412224719, 5.070346481, 4.61662617, 7.319566218, 
8.8358611, 8.010337235, 5.346183362, 7.157022806, 6.834977143, 
7.42088206, -0.534183425, 1.745965849, -0.063663897, 0.578528646, 
0.338901166), CB_0005 = c(0.19, 0.866666667, 0.62, 0.18, 4.143333333, 
3.19, 5.173333333, 1.716666667, 4.973333333, 2.45, 3.07, -0.123333333, 
5.951666667, 5.776666667, 5.86, 4.516666667, 2.58, 1.023333333, 
1.433333333, 0.546666667, -0.683333333, -0.213333333, -0.13, 
-1.31, -1.136666667, 0.656666667, 0.373333333, -0.586666667, 
-0.12, 1.326666667, -0.543333333, -1.683333333, 1.43, -0.266666667, 
3.396666667, -0.67, 0.446666667, -0.68, -1.791271957, -2.579171935, 
-2.249617087, -1.962741363, -0.911842701, -1.652768304, -2.037488906, 
-2.018637069, -1.202487074, -1.567699217, -1.268697423, -1.849395262, 
-2.63754002, -1.381764512, 0.829044901, 0.502147423, 0.010238402, 
0.758163087, 1.356070939, 1.728804128, 0.670436352, 1.320512424, 
0.953284467, 1.231950146, -0.458545229, -0.979187373, -0.979429108, 
-0.684593791, -0.97072078), CB_0006 = c(0.043333333, 0.45, 2.38, 
0.04, 4.31, 3.306666667, 5.913333333, 1.053333333, 4.573333333, 
1.643333333, 0.77, -0.523333333, 6.645, 5.776666667, 4.505, 3.813333333, 
2.003333333, -0.173333333, 2.126666667, 1.126666667, 0.553333333, 
-0.913333333, 2.39, -1.69, -0.446666667, 0.62, 0.59, -0.366666667, 
0.113333333, 2.086666667, 0.96, -2.253333333, 3.21, 0.25, 3.353333333, 
0.9, 0.996666667, -1.056666667, 0.96842814, 1.238997001, 2.111247339, 
2.632417968, 2.957791614, 2.352488099, 2.436937743, 1.416478401, 
2.301093649, 0.851761023, 1.714207673, 2.690772076, 1.335837241, 
0.947463687, 3.474979307, 2.715172096, 0.128972586, 3.059253929, 
3.618361826, 4.561311502, 2.887050645, 4.01342017, 4.061905047, 
3.084527636, 4.077874125, 1.720339787, 2.680703907, 3.429155953, 
1.076718526), CB_0011 = c(-2.496666667, -1.371666667, 0.863333333, 
-1.49, 2.343333333, 2.223333333, 3.27, 2.223333333, 2.766666667, 
0.466666667, 1.523333333, -0.023333333, 4.271666667, 2.59, 4.471666667, 
2, 0.336666667, 1.081666667, 0.236666667, -0.226666667, -1.193333333, 
-0.186666667, 1.273333333, -0.78, -0.1, 3.133333333, 1.2, -2.493333333, 
-1.613333333, 0.776666667, -0.89, -1.05, 0.79, -3.075, 4.393333333, 
-1.076666667, 0.436666667, -2.023333333, -4.085208233, -3.516059809, 
-2.822973721, -3.058210659, -2.488740565, -2.654138537, -1.563323017, 
-2.423356944, -2.347858193, 0.4773698, 0.763984257, 0.558693056, 
0.119281479, 0.782317133, 1.359085337, 0.124865797, -1.119268185, 
1.425699915, 1.866727668, 1.990434938, 0.609483251, 1.320638093, 
0.535468513, 1.456177932, -0.222050546, -0.826761721, -0.677009411, 
-0.463469908, -1.059253514), CB_0012 = c(2.815, 5.813333333, 
7.778333333, 0.745, 12.57833333, 12.27166667, 13.67833333, 9.041666667, 
13.12833333, 10.265, 10.87833333, 0.666666667, 14.67, 13.155, 
14.36666667, 12.73833333, 9.965, 7.761666667, 6.851666667, 6.155, 
4.758333333, 4.393333333, 7.111666667, 3.075, 3.881666667, 7.675, 
6.065, 3.571666667, 4.415, 6.14, 4.198333333, 3.696666667, 7.55, 
7.285, 8.931666667, 5.818333333, 6.615, 3.041666667, -1.115139532, 
-3.302496284, -4.133342071, -2.073313621, 2.857786894, -3.644243188, 
-1.666068974, -6.1066393, -4.2550487, -2.183899444, -4.667808484, 
-0.74783539, -3.803084978, -5.014973351, 4.67574087, 3.473028007, 
1.389581165, 4.702920785, 6.200598726, 6.297462828, 4.40762205, 
5.883113082, 5.66909587, 5.592972185, 1.702481686, 0.243357179, 
1.86042902, 3.084594805, -0.497330213), CB_0013 = c(0.43, 1.056666667, 
0.92, -0.416666667, 5.046666667, 5.583333333, 4.863333333, 3.366666667, 
4.096666667, 5.183333333, 3.843333333, 0.125, 5.33, 3.863333333, 
3.923333333, 4.241666667, 4.99, 3.66, 1.076666667, 2.026666667, 
0.496666667, 1.313333333, 1.18, 1.136666667, 0.78, 1.86, 1.273333333, 
1.046666667, 0.206666667, 2.47, 1.446666667, -0.403333333, 2.693333333, 
2.496666667, 1.23, 1.576666667, 1.996666667, 0.47, 1.394159215, 
0.678030016, 1.076488597, 0.363249037, 0.853131993, -1.606079079, 
-0.875570483, -1.013395238, -0.503759268, -0.929761503, -0.887922953, 
-0.998513792, -2.218530791, -0.721132205, 0.65791434, -0.657476339, 
0.323624771, 1.253684939, 2.513147936, 1.885789992, 0.572927408, 
2.35810823, 1.171786382, 2.324243736, -1.914968442, -2.266804605, 
-2.122018154, -2.263614658, -2.29255884), CB_0014 = c(-1.228333333, 
0.195, -1.835, -0.448333333, 3.558333333, 3.601666667, 3.681666667, 
1.985, 4.168333333, 2.495, 2.548333333, -0.975, 4.408333333, 
2.656666667, 3.055, 3.403333333, 1.558333333, 1.711666667, -1.91, 
-1.095, -1.011666667, -1.078333333, -1.035, -2.325, -1.876666667, 
-1.975, -0.601666667, -1.868333333, -0.928333333, -0.725, 3.01, 
4.358333333, 3.748333333, 2.231666667, 0.488333333, -1.956666667, 
-1.058333333, -1.188333333, -3.067946182, -3.753318788, -2.288407455, 
-2.358770647, -1.99460004, -2.797157118, -2.821238884, -1.814501746, 
-3.200828288, -0.388460565, -0.638998692, 0.215762874, -1.767152421, 
-1.457941204, 3.207467021, 2.032498158, 0.863455516, 3.424249596, 
4.240406008, 4.500498651, 2.406278475, 3.518719942, 3.232867203, 
3.780179725, -0.57672801, -0.872209074, -0.484175745, -1.575812116, 
-1.223198781), CB_0016 = c(-1.44, -0.363333333, 2.156666667, 
0.366666667, -1.443333333, -1.996666667, -0.45, 0.43, 1.51, -1.483333333, 
-0.67, -0.233333333, -1.421666667, -1.433333333, 1.59, 1.761666667, 
-1.853333333, -1.22, -0.656666667, 0.236666667, -0.226666667, 
-2.176666667, 0.38, -1.96, -0.15, -2.99, -0.583333333, 0.153333333, 
-1.223333333, 0.476666667, -0.33, -1.903333333, -0.42, -3.003333333, 
-0.47, -0.236666667, -0.256666667, -0.16, -5.776581841, -5.948045769, 
-5.819955957, -5.496178528, -6.25601099, -4.308211827, -4.126672141, 
-4.638024231, -6.514482634, -5.325306941, -6.868178191, -6.152633564, 
-4.080647242, -5.641202826, 0.350957704, -0.942649432, -2.735005377, 
1.147980322, 1.713637047, 2.009893435, -0.254436787, 1.258797206, 
0.368814144, 1.498039472, -1.957490471, -1.315617266, -1.504684065, 
-1.406568031, -2.669272019), CB_0017 = c(0.733333333, 2.84, 7.245, 
-0.01, 14.13666667, 13.36, 14.2, 8.833333333, 8.92, 11.96, 8.036666667, 
0.453333333, 14.12666667, 14.52333333, 11.54, 9.491666667, 12.82666667, 
9.403333333, 8.386666667, 6.17, 5.03, 3.73, 6.416666667, 4.118333333, 
7.753333333, 7.4, 7.881666667, 2.776666667, 4.493333333, 7.476666667, 
5.826666667, 3.99, 9.846666667, 7.816666667, 7.753333333, 6.246666667, 
9.16, 2.69, 0.58211635, 2.417689675, 0.2370146, 3.775366292, 
5.819523197, -2.727133421, 1.706586444, -1.223528063, -1.234500436, 
-1.246753709, -1.110495731, 0.656007927, 0.355281429, -1.51548638, 
4.797442718, 1.556284042, -0.095696, 3.750244252, 6.601848425, 
5.923289895, 2.890314035, 5.047521499, 5.275380369, 3.621663816, 
2.354253345, -0.176419606, 1.992240681, 2.47740302, -0.163856595
), CB_0019 = c(4.233333333, 0.493333333, 1.053333333, 0.036666667, 
1.43, 0.673333333, 1.023333333, 0.493333333, 1.983333333, 1.046666667, 
1.4, -0.506666667, -0.133333333, -0.446666667, 1.23, 2.113333333, 
0.193333333, -0.01, -5.216666667, 2.326666667, 0.393333333, -1.5, 
2.816666667, -0.176666667, 2.323333333, 0.443333333, 1.04, 1.646666667, 
0.78, 2.063333333, 1.408333333, 2.6, 2.116666667, 0.516666667, 
2.796666667, 1.803333333, 0.805, 1.216666667, -3.404207014, -3.586034263, 
-4.699109227, -1.901905606, -1.022254193, -0.746868627, 0.617487085, 
-0.608811858, -0.545044612, -3.128223632, -4.641628296, -4.805187761, 
-4.639284985, -5.188622386, 0.462203524, -0.441937022, -0.228882327, 
0.845034146, 0.70951323, 1.761774127, 0.559250465, 1.212296208, 
0.498456132, 1.66177922, 1.237705872, -1.694433988, -4.108768425, 
-2.442898387, 1.082830393)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -67L))
Ashley D
  • 1
  • 2
  • Please read about [how to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and update your question accordingly. Include a sample of your data by pasting the output of `dput()` into your post or `dput(head())` if you have a large data frame. Also include code you have tried, any relevant errors, and expected output. If you cannot post your data, then please post code for creating representative data. Please do not post pictures of your data. – LMc Jul 26 '23 at 19:12

1 Answers1

1

Those are row names, not a column. Tibbles don't like row names, so if you want row names you'll probably want to avoid dplyr and other tidyverse functions and convert your data back to a regular data frame. Something like this:

your_data = as.data.frame(your_data)
row.names(your_data) = your_data[["...1"]]

Note that you can have a tibble with row names, but if you ever use the [ operator they will disappear. Really, I'd take the advice in the link above and not pursue this course:

Generally, it is best to avoid row names, because they are basically a character column with different semantics than every other column.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294