Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract values from a data frame in one line

I have a data frame with xy coordinates of a polygon, such as

head(df)
         V1       V2
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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is possible to do this in R?

Thank you for your suggestions.

To help you

dput(head(df))
structure(list(V1 = c(-80.592638147978, -80.5053900250096, -80.4190851177927, 
-80.3296723477363, -80.2422811180695, -80.1681095463581), V2 = c(40.8840646013078, 
40.9107575870107, 40.9328429088589, 40.940470505061, 40.9389413287036, 
40.9343356232221)), row.names = c(NA, 6L), class = "data.frame")

>Solution :

Perhaps use paste

do.call(paste, c(df, collapse = ", "))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading