'adding rows to table1 function r”翻译成中文可得'向table1添加行的函数r”,可以通过以下代码实现:
add_row <- function(table, values) {
table[nrow(table) + 1, ] <- values
return(table)
}
# 示例
table1 <- data.frame(name = c("John", "Alice", "Bob"), age = c(25, 30, 35))
new_row <- c("Tom", 27)
table1 <- add_row(table1, new_row)
print(table1)
输出结果为:
name age
1 John 25
2 Alice 30
3 Bob 35
4 Tom 27