我正在尝试绑定数据帧行。我在聚合后生成一些带有列表列的数据框,但有些是字符。我找不到绑定它们的方法。我尝试使用// Entity is a subclass of GameObject.
// It does not override paintComponent.
// All it does is add an update method that is called every game tick.
public class MicroObject extends Entity {
protected Location location; // variable to store position and rotation
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.translate(this.getWidth() / 2, this.getHeight() / 2);
g2.rotate(Math.toRadians(location.getRotation()));
// In the following two lines, image is inherited from GameObject
g2.translate(-image.getWidth(this) / 2, -image.getHeight(this) / 2);
g2.drawImage(image, 0, 0, null);
}
}
转换字符列,但这不起作用。
as.list()
答案 0 :(得分:2)
我不太了解dplyr
库,但使用下面的基础R' rbind()
似乎正在运作:
df1 <- data.frame(a = c(1,2,3),stringsAsFactors = F)
df1$b <- list(c("1","2"),"4",c("5","6"))
df2 <- data.frame(a=c(4,5),b=c("9","12"),stringsAsFactors = F)
result <- rbind(df1, df2)
class(result$a)
[1] "numeric"
class(result$b)
[1] "list"
如果您想使用bind_rows()
,请先查看错误消息。看起来dplyr
并不像一个数据框有字符数据而另一个数据框有列表数据。您可以尝试将字符列转换为列表,然后调用bind_rows
,例如
df2$b <- as.list(df2$b)
dplyr::bind_rows(df2,df1)