我正在尝试在两列上应用相交或者说一列和一个列表。它适用于我是否有一个列的多个组但不是如果我只有一个,我不能理解为什么?它会抛出警告,不知何故它会以不同的方式列出...
使用:
$ awk 'NR==2{next} # skip second line
r {t=$1; $1=$2; $2=t} # if r (reverse) flag is set, swap fields
1; # print line
/^#Start hosts lists/{r=1}' file # if the line matches set the r flag
#hosts entry
#Start hosts lists
Server1 10.0.0.1
Server2 10.0.0.2
Server1 10.0.0.3
Server2 10.0.0.4
但不适用于:
dt <- data.table(a = c("a","a", "b","b", "c"), b = c("PKR","AFB", "ICH",
"PKR", "GHI"))
dt <- dt[, c :=.(list(unique(b))), by=a]
y <- nrow(dt)
dt <- dt[, i := mapply(intersect, c, rep(list(c("AFB","PKR")), y))]
dt <- data.table(a = c("a","a", "b","b"), b = c("PKR","AFB", "ICH", "PKR"))
dt <- dt[, c :=.(list(unique(b))), by=a]
y <- nrow(dt)
dt <- dt[, i := mapply(intersect, c, rep(list(c("AFB","PKR")), y))]
dt <- data.table(a = c("a","a", "b"), b = c("PKR","AFB", "ICH"))
dt <- dt[, c :=.(list(unique(b))), by=a]
y <- nrow(dt)
dt <- dt[, i := mapply(intersect, c, rep(list(c("AFB","PKR")), y))]
有人可以分享这是如何运作的吗?或者我错过了什么。