How can R combine multiple columns into one column?
In R language, you can use the c() function to combine multiple columns of data into one column. Here is an example:
# 创建示例数据
df <- data.frame(x = c(1, 2, 3),
y = c(4, 5, 6),
z = c(7, 8, 9))
# 合并多列数据
merged <- c(df$x, df$y, df$z)
In the example above, a data frame called df with 3 columns – x, y, and z – is created first. Then, the c() function is used to merge these three columns into one and store them in a variable called merged. The final result is a vector containing 9 elements, with values from the original three columns stored sequentially.