R语言--解决4*x+y之奇技淫巧、重复数字去重

A=outer(1:4, 1:30, function(x, y) 10*x + y);A
i <- 1:4; j <- 1:30;  # i and j
ni<- length(i); nj <- length(j)  # lengths of i and j
y <- matrix(NA, nj, ni) # create a matrix with nj rows and ni columns
for (k in 1:ni){
  for (p in 1:nj){
    y [p, k] <- i[k] * 10 + j[p]  # fill the matrix
  }
}
B=matrix(rep(i, each=nj) * 10+rep(j, ni), ni, nj)

  

#去除向量重复出现的数字
d <- c(1,2,2,2,3,3,2,4,4)
e <- c(1,2,5,7,5,1,1,4,5)
f <- cbind(d,e);f
f1 <- f[!duplicated(f[,2]),];f1
#duplicated() 生成一个布尔向量,将向量f[,2]中第一次出现的数字记为F,后面重复的数字记为T
#!将上述布尔向量记为第一次出现的数字记为T,后面重复的数字记为F
#[buer vector,]只保留T代表的数字

  

Valar morghulis
原文地址:https://www.cnblogs.com/super-yb/p/11048071.html