cad <- data.table(name)
y <- colnames(cad)[1]
cad <- add_row(cad, y = 100)
Error: New rows can't add columns. x Can't find column
y
in.data
.
It needs evaluation to get the value
library(data.table)
library(tibble)
add_row(cad, !! y := 100)
-output
# col1 col2
#1: 1 6
#2: 2 7
#3: 3 8
#4: 4 9
#5: 5 10
#6: 100 NA
cad <- data.table(col1 = 1:5, col2 = 6:10)
y <- colnames(cad)[1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.