Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (50.2k points)
I am having a dataset that is having GPS data for objects and time components.

The dataframe is having 2 columns: Object and Time. Each row in the time column matches a dataframe within the Object column, which holds a unique name/ID of each object (there are 5) and the X, Y, and Z coordinates at that instance of time.

My question is, is there a way to extract just one of the ID's and coordinates from the "dataframe within a dataframe" to create a new DF with the XYZ coordinates, ID, and time? The final goal is to have new 5 dataframes for each object so I can separately plot the location for each object.

1 Answer

0 votes
by (108k points)

Let me tell you that without any information about the test data, in R programming, it will be challenging to answer but something along the lines of the following code might be the solution:

coord <- df1$Time

coord <-, coord)

merge(df1['ID'], coord)

And I have tested with the following data:


df1 <- data.frame(ID = 1:5)

df1$Time <- lapply(df1$ID, function(i){

  data.frame(ID = i, Time = Sys.time(),

             X = runif(1, 0, 180),

             Y = runif(1, 0, 180),

             Z = runif(1, 0, 180))


Browse Categories