Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在数据帧中组合列_R - Fatal编程技术网

R 在数据帧中组合列

R 在数据帧中组合列,r,R,在一个数据框中,我有三列分别代表名字、中间名和姓氏。如果我想将3列合并为1个全名列,我该怎么做? 例如,如果我有 df$firstname <- c("Mike","Jake", "Bob") df$middlename <- c("John", "Jay", "Peter") df$lastname <- c("Turner", "Larson", "Simmons") 我们可以使用粘贴 df$fullname <- do.call(paste, df) df$fu

在一个数据框中,我有三列分别代表名字、中间名和姓氏。如果我想将3列合并为1个全名列,我该怎么做? 例如,如果我有

df$firstname <- c("Mike","Jake", "Bob")
df$middlename <- c("John", "Jay", "Peter")
df$lastname <- c("Turner", "Larson", "Simmons")

我们可以使用
粘贴

df$fullname <- do.call(paste, df)

df$fullname我们可以使用
paste

df$fullname <- do.call(paste, df)
df$fullname
df <- structure(list(firstname = structure(c(3L, 2L, 1L), 
.Label = c("Bob", 
"Jake", "Mike"), class = "factor"), middlename = structure(c(2L, 
1L, 3L), .Label = c("Jay", "John", "Peter"), class = "factor"), 
lastname = structure(c(3L, 1L, 2L), .Label = c("Larson", 
"Simmons", "Turner"), class = "factor")), .Names = c("firstname", 
"middlename", "lastname"), row.names = c(NA, -3L),
class = "data.frame")