英文:
Extract values from a data frame in one line
问题
我有一个包含多边形的xy坐标的数据框,例如
head(df)
x y
1 -80.59264 40.88406
2 -80.50539 40.91076
3 -80.41909 40.93284
4 -80.32967 40.94047
5 -80.24228 40.93894
6 -80.16811 40.93434
我尝试提取它以获得像这样的结果:
df
(-80.59264 40.88406, -80.50539 40.91076, -80.41909 40.93284, -80.32967 40.94047, -80.24228 40.93894, -80.16811 40.93434...)
即每一行由逗号分隔,列值用空格分隔。
这在R中是可以做到的吗?
感谢您的建议。
英文:
I have a data frame with xy coordinates of a polygon, such as
head(df)
x y
1 -80.59264 40.88406
2 -80.50539 40.91076
3 -80.41909 40.93284
4 -80.32967 40.94047
5 -80.24228 40.93894
6 -80.16811 40.93434
I try to extract it to obtain something like this:
df
(-80.59264 40.88406, -80.50539 40.91076, -80.41909 40.93284, -80.32967 40.94047, -80.24228 40.93894, -80.16811 40.93434...)
i.e. each line is separated by a comma and column values with a space.
This is possible to do this in R?
Thank you for your suggestions.
答案1
得分: 4
使用 paste
do.call(paste, c(df, collapse = ", "))
英文:
Perhaps use paste
do.call(paste, c(df, collapse = ", "))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论