Stop R from appending .1 etc. Like suffix in header character vectors when called using colnames

I am trying to return a dataframe containing all the values ​​in each column that are less than -1.5, which have both the column heading and the name rowname. Basically, everything worked out for me, except for the last step, in which I replace the column with column numbers with the corresponding column names from the original data frame, when there are several values ​​from the same column that are less than -1.5, the name of the new column of the value is listed as " column name1 ". I searched around and found out that make.unique seems to do a similar thing, but I never called this function.

A <- c(0.6, -0.5, 0.1, 1.6, -1.6, 0.4, -1.6)
B <- c(0.7, -2.1, -0.3, 1.1, 2.1, -1.7, 1.1)
DF <- as.data.frame(cbind(A, B))
colnames(DF) <- c("010302A620300302000", "010803A110100069000")
rownames(DF) <- c("1996", "1997", "1998", "1999", "2000", "2001", "2002")

So, my original framework looks something like this:

010302A620300302000 010803A110100069000
1996                 0.6                 0.7
1997                -0.5                -2.1
1998                 0.1                -0.3
1999                 1.6                 1.1
2000                -1.6                 2.1
2001                 0.4                -1.7
2002                -1.6                 1.1

To get the corresponding values ​​for each row:

DF.new <- as.data.frame(which(DF <= -1.5, arr.ind = T, useNames = TRUE))
DF.new <- as.data.frame(setDT(DF.new, keep.rownames = TRUE)[])

DF.new$SUID <- colnames(DF[, DF.new[ ,3]])

, colnames, SUID ".1" , :

    rn row col                  SUID
1 2000   5   1   010302A620300302000
2 2002   7   1   010302A620300302000.1
3 1997   2   2   010803A110100069000
4 2001   6   2   010803A110100069000.1

!

+4
2

, .

DF.new$SUID <- colnames(DF)[DF.new[ ,3]]

DF.new$SUID <- colnames(DF[, DF.new[ ,3]])
+4

DF.new$SUID <- floor(DF.new$SUID) .

0

Source: https://habr.com/ru/post/1695184/


All Articles