I wonder how to transform a list generated by a FQL-query into a structured data frame.
I use Rfacebook
to ask FQL-queries like:
getFQL("SELECT name, friends_count, sex, languages FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1=me()), token)
This provides me with a list as output, which looks like:
[[1]]
[[1]]$name
[1] "Peter Fuller"
[[1]]$friend_count
[1] 186
[[1]]$sex
[1] "male"
[[1]]$languages
list()
[[2]]
[[2]]$name
[1] "Max Tester"
[[2]]$friend_count
[1] NULL
[[2]]$languages
[[2]]$languages[[1]]
[[2]]$languages[[1]]$id
[1] 1.056736e+14
[[2]]$languages[[1]]$name
[1] "English"
[[2]]$languages[[2]]
[[2]]$languages[[2]]$id
[1] 1.060595e+14
[[2]]$languages[[2]]$name
[1] "Italian"
[[2]]$languages[[3]]
[[2]]$languages[[3]]$id
[1] 1.144157e+14
[[2]]$languages[[3]]$name
[1] "Persian"
My aim is to convert the list into a data frame, such that the list above looks like:
name friend_count languages
1 Peter Fuller 186 NA
2 Max Tester NA Englisch, Italian, Persian
Unfortunately, my efforts with unlist()
and matrix
failed.
First unlist each record separately giving
LL
, then concatenate into a common string components with the same name usingtapply
andtoString
. Then userbind.fill
from plyr to create the final data frame:giving:
Note that we assumed this input: