[英]How do I split a “data.frame” type column?
I have a dataframe df
where one of the columns user
is itself a data.frame
.我有一个 dataframe
df
其中一个列user
本身就是一个data.frame
。
df <- data.frame(
user = data.frame(
id = numeric(),
name = character()
)
)
df[nrow(df)+1,] <- c(1,"joe")
How do I split the user
column into the id
and name
columns so that df
has the id
and name
columns instead of the user
column?如何将
user
列拆分为id
和name
列,以便df
具有id
和name
列而不是user
列?
We can use sub
on the column names after converting it to a regular data.frame将其转换为常规 data.frame 后,我们可以在列名上使用
sub
df <- do.call(data.frame, df)
names(df) <- sub("^user\\.", "", names(df))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.