I have a variable named likes in R (retrieved from Rfacebook package). This variable contains all my own likes as characters. I've transformed this variable into a factor variable so that I can analyse it. Though, for the sake of my project, I need to get all my 3 different likes in the header as separate variables in a dataframe, with only myself as a row.
Context: If more people than me will be added to the dataframe, then these likes of other people should be added as variables as well and the cells are filled in with either the name of the page if they like the page and an NA if they haven't liked the page.
Help would be much appreciated!
Here is the problem: When I retrieve data from facebook the likes column returns an NA because data it contains exists of multiple characters (the three likes) as shown here.
Then I run the following code:
Retrieve own user information
me <- getUsers("1131454363567865",token=fb_oauth, private_info = TRUE)
my_likes <- getLikes(user="me", token=fb_oauth)
likes <- as.factor(my_likes$names)
dflikes <- as.data.frame(likes)
Then I end up with a data.frame with the 3 likes listed in one column, while I actually want that these 3 different factor levels are transformed to 3 new variables. So lined up next to the other variables as name, gender, etc as shown here.
Here is what the entire code looks like:
# Set up APP connection
install.packages("devtools")
library(devtools)
install_github("Rfacebook", "pablobarbera", subdir="Rfacebook")
require("Rfacebook")
fb_oauth <- fbOAuth(app_id="**", app_secret="**", extended_permissions = TRUE, legacy_permissions = TRUE)
save(fb_oauth, file="fb_oauth")
load("fb_oauth")
# Retrieve own user information
me <- getUsers("1131454363567865",token=fb_oauth, private_info = TRUE)
my_likes <- getLikes(user="me", token=fb_oauth)
likes <- as.factor(my_likes$names)
dflikes <- as.data.frame(likes)