-1

I have the data frame df which is structured the following way:

df
.. $data1
.. .. $data12
.. .. $data13
.. $data2
.. .. $1
.  . .. .. $something1
.. .. .. $something2
.. .. .. $something3
.. .. $2
.. .. .. $something1
.. .. .. $something2
.. .. .. $something3

I use: something1 <- sapply(df$data2, function(x) x$something1, USE.NAMES = FALSE)

to extract the data for each number. What I can't figure out is how to extract the number and store it as an ID for the extracted data (1 for the first dataset etc.)

OilFerry
  • 15
  • 6
  • 4
    Are you sure that's a proper data.frame? It doesn't seem to follow the data.frame rules. It would be easier to help you if you provided a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data (via `dput`) and the desired output for that input so possible solutions can be tested. – MrFlick Aug 23 '17 at 17:20
  • What @MrFlick said and shouldn't it be `x$1$something1`? – Rui Barradas Aug 23 '17 at 17:22

1 Answers1

-1

I figured out that I was dealing with a list not a data frame. And to extract the names of the objects I simply used

names(df$data2)

to extract the ID.

Andy
  • 49,085
  • 60
  • 166
  • 233
OilFerry
  • 15
  • 6