How to use excel file to identify column as name column of PCA?


Jean Megner

I am new to R and I want to do a PCA.

Here is my dataset:

structure(list(Varietes.rep = c("EPS45_2", "EPS47_1", "EPS45_1", "OPM_2", "EPS41_2", "EPS46_1", "Belet_1", "EPS42_2", "BDA_2", "Osoro_1"), ASI = c(4, 6, 2, 0, 3, 5, 3, 2, 6, 2), DTSnum = c(19, 16, 18, 16, 20, 25, 22, 16, 23, 22), DTAnum = c(15, 10, 16, 16, 17, 20, 19, 14, 17, 20), Amplitude = c(9, 14, 9, 4, 7, 8, 11, 6, 10, 6), AUC = c(416.6667, 512.1622, 353.4483, 20.98765, 327.907, 288.6364, 400, 108.8608, 601.6393, 260.6557), Pourcentage.pieds.steriles.femelle = c(4, 2.27272727272727, 1.5625, 0, 5.8252427184466,7.69230769230769, 1.20481927710843, 1.0752688172043, 1.2987012987013, 2.66666666666667), Hauteur.moyenne = c(270.3676, 256.6753, 281.0508, 288.0988, 272.4674, 293.8163, 303.4189, 264.7375, 258.371, 294.4444), Hauteur.moyenne.soies =c(101.8154, 100.6533, 101.8947, 100.2716, 101.8372, 130.7391, 126.2361, 97.1125, 102.7705, 122.7097), Pourcentage.double.epis = c(29.4117647058824, 33.3333333333333, 41.1764705882353, 74.5098039215686, 15.6862745098039, 29.4117647058824, 47.0588235294118, 58.8235294117647, 27.4509803921569, 31.3725490196078)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))

My column name is "Varietes.rep" and I want to be precise that this variable is my personal, for my PCA.

What can I do?

User 438383

Named columns need to be row names, so you need to convert the columns to row names first:

library(magrittr)
pca = dat %>%
    tibble::column_to_rownames("Varietes.rep") %>%
    prcomp()
Standard deviations (1, .., p=9):
[1] 1.740407e+02 1.940922e+01 1.244057e+01 4.747485e+00 2.481467e+00 1.197997e+00 3.621528e-01 1.236234e-01 9.236234e-16

Rotation (n x k) = (9 x 9):
                                            PC1          PC2          PC3         PC4          PC5          PC6         PC7         PC8           PC9
ASI                                -0.009441536 -0.004237640  0.023921657 -0.19086237 -0.052048523 -0.315610214  0.20076598  0.69780588  5.773503e-01
DTSnum                             -0.006867303  0.125533815  0.062339752 -0.13742720  0.558004323 -0.308139050 -0.23453973  0.40836369 -5.773503e-01
DTAnum                              0.002574233  0.129771455  0.038418095  0.05343516  0.610052846  0.007471164 -0.43530572 -0.28944219  5.773503e-01
Amplitude                          -0.013888223 -0.004206378 -0.058284888 -0.08600605 -0.513714294 -0.075437642 -0.83548049  0.14619983 -1.541798e-15
AUC                                -0.996727987  0.013670006 -0.075289266  0.01591253  0.008442632 -0.005448888  0.01329253 -0.01212881  1.000562e-16
Pourcentage.pieds.steriles.femelle -0.001913776  0.047541419  0.149077548 -0.08786674 -0.152057897 -0.855253847  0.08990259 -0.45291086  8.907345e-16
Hauteur.moyenne                     0.037010923  0.739041840 -0.244336259  0.59755584 -0.107680234 -0.097974355  0.04572905  0.11130594 -4.653036e-16
Hauteur.moyenne.soies              -0.002450546  0.624853368  0.002744968 -0.73347830 -0.078457457  0.203460007  0.07873022 -0.13343280  7.895899e-16
Pourcentage.double.epis             0.069412039 -0.168206275 -0.950298953 -0.17718858  0.094402269 -0.131187195  0.02483250 -0.07540691  1.981639e-16

Related


How to identify the name of a column with duplicate values in R

User 11368874 The data frame has columns consisting of repeated values. How can we identify column names with duplicate values and their counts. data set: A B C 1 2 a 2 3 b 3 4 a 1 5 c I need output like this Columns with duplicate values are A(2) a

How to identify the name of a column with duplicate values in R

User 11368874 The data frame has columns consisting of repeated values. How can we identify column names with duplicate values and their counts. data set: A B C 1 2 a 2 3 b 3 4 a 1 5 c I need output like this Columns with duplicate values are A(2) a

How to use column value as column name?

Vladimir Korenev I have a dataframe with some columns containing data and one column with column names: mydf <- data.frame( "aa" = 11:15, "ab" = 21:25, "ac" = 31:35, "nn" = c("aa", "aa", "ac", "ab", "aa")) I want to get a vector from column "aa", "ab"

How to use column value as column name?

Vladimir Korenev I have a dataframe with some columns containing data and one column with column names: mydf <- data.frame( "aa" = 11:15, "ab" = 21:25, "ac" = 31:35, "nn" = c("aa", "aa", "ac", "ab", "aa")) I want to get a vector from column "aa", "ab"

Excel: Identify column with specific value

Akash I have an excel file with a table in the following format, with about 50 columns A B C D E id 1 0 0 0 0 1 0 1 0 0 0 2 0 0 0 0 1 3 It is guaranteed that the value of one row is exactly 1, i.e. "1", and the other rows are 0. How to convert the above to

Excel: Name the name of the column

Avi I use named Excel columns to simplify formulas. I would like to have the top cell of each such column be used as the header of the column by displaying the name of the column. How do I get strings? Edit: @Andreas asked how named columns can simplify formul

How to rearrange Excel columns by column header name

Highest How to rearrange columns by column header name. I need to process weekly reports and the original worksheet has 23 columns. I've abstracted part of it as an example. Original column order: QTY Payment Terms Contract No. etc Desired column order:Contrac

How to filter Excel column by month name?

Alexander Podak Given the following list in excel: How can I filter the rows (based on the date of birth column) when the user selects the month name? Here's what I've done so far, but I don't know how to manipulate the DOBcolumn: Private Sub ComboBox2_Change(

How to rearrange Excel columns by column header name

Highest How to rearrange columns by column header name. I need to process weekly reports and the original worksheet has 23 columns. I've abstracted part of it as an example. Original column order: QTY Payment Terms Contract No. etc Desired column order:Contrac

How to rearrange Excel columns by column header name

Highest How to rearrange columns by column header name. I need to process weekly reports and the original worksheet has 23 columns. I've abstracted part of it as an example. Original column order: QTY Payment Terms Contract No. etc Desired column order:Contrac

How to filter Excel column by month name?

Alexander Podak Given the following list in excel: How can I filter the rows (based on the date of birth column) when the user selects the month name? Here's what I've done so far, but I don't know how to manipulate the DOBcolumn: Private Sub ComboBox2_Change(

Excel formulas: how to reference cells by column name

Ramses How can I change my excel formula if I need to replace the direct reference to a cell with that cell's column name? For example, instead of SUM(A1:B1) I want to use something like SUM({Column1}:{Column2}) I know about structured references, but I can'

How to filter Excel column by month name?

Alexander Podak Given the following list in excel: How can I filter the rows (based on the date of birth column) when the user selects the month name? Here's what I've done so far, but I don't know how to manipulate the DOBcolumn: Private Sub ComboBox2_Change(

How to rearrange Excel columns by column header name

Highest How to rearrange columns by column header name. I need to process weekly reports and the original worksheet has 23 columns. I've abstracted part of it as an example. Original column order: QTY Payment Terms Contract No. etc Desired column order:Contrac