There may be a better way, but here I take it upon myself.
#
Examples: In your first data frame -
df1 <- read.table(text = "V1 V2 V3 V4 PC1 0.5863431 0.5863431 3.952237e-01 3.952237e-01 PC2 -0.3952237 -0.3952237 5.863431e-01 5.863431e-01 PC3 -0.7071068 0.7071068 1.665335e-16 3.885781e-16", header = TRUE) m1 <- as.matrix(df1) d1 <- duplicated(m1, MARGIN = 0) | duplicated(m1, MARGIN = 0, fromLast = TRUE) colnames(m1)[unique(col(d1)[d1])] # [1] "V1" "V2" "V3" "V4"
And on the second -
df2 <- read.table(text = "V1 V2 V3 V4 PC1 -0.5987139 -0.5987139 -0.03790446 0.5307039 PC2 -0.0189601 -0.0189601 -0.99315168 -0.1137136 PC3 0.3986891 0.3523926 -0.11045319 0.8394442", header = TRUE) m2 <- as.matrix(df2) d2 <- duplicated(m2, MARGIN = 0) | duplicated(m2, MARGIN = 0, fromLast = TRUE) colnames(m2)[unique(col(d2)[d2])] # [1] "V1" "V2"
Note: Since your data contains all numerical values, I would recommend starting with a matrix instead of a data frame.
source share