R: Rotate list data into Dataframe

I have list data generated from JSON file generated by ODK Aggregate. It looks something like this:

P1 <- list(a01 = 1:11, a02 = letters[1:11], a03 = list(letters), a04 = (1:11)^2)

      

What I would like to do is basically convert P1 to dataframe by dropping all nested lists ( a03

). With this simple example, we get the following as our final result.

P1data <- data.frame(a01 = 1:11, a02 = letters[1:11], a04 = (1:11)^2)

      

Thanks for any help you can provide!

+3


source to share


1 answer


try it



as.data.frame(Filter(Negate(is.list), P1))
#    a01 a02 a04
# 1    1   a   1
# 2    2   b   4
# 3    3   c   9
# 4    4   d  16
# 5    5   e  25
# 6    6   f  36
# 7    7   g  49
# 8    8   h  64
# 9    9   i  81
# 10  10   j 100
# 11  11   k 121

      

+7


source







All Articles