I downloaded a JSON file of tweets from Twitter and imported this into R and made it into a dataframe using the following:
json_data_frame <- do.call(rbind, Datafile)
dataf <- as.data.frame(json_data_frame)
However, many of the functions in the script I had been using (which worked fine with a .csv file) don't now seem to work with this new data frame.
Data <- dataf %>%
mutate(Date = as.Date(created_at)) %>%
group_by(month = floor_date(Date, unit = "month")) %>%
count(month) %>%
mutate(Month_Year = format(as.Date(month), "%m%-%Y"))
I get the following error: Date = as.Date(created_at)
.
x do not know how to convert 'created_at' to class “Date”
The created_at column is currently in the format yyyy-mm-dd Thh:mm:ss.000 It shouldn't have a problem with this as it worked just fine with the .CSV file.
However, just in case the issue was the presence of the hours and minutes, I then ran the following:
Data <- dataf %>%
mutate(Date = format(as.character(substr(created_at,
1, 10)))) %>%
mutate(month = format(as.Date(Date), "%m-%y")) %>%
group_by(mutate(month_year = floor_date(Date, unit = "month")))
Just running up to the final line works without any errors. However, when I add the final line I get the following error
Problem with mutate()
input ..1
.
i ..1 = mutate(month_year= floor_date(Date, unit = "month"))
.
x subscript out of bounds
As I said, I used the exact same data file in .csv and the script worked fine, but for some reason it is not working with the JSON file. I am also not sure what the 'subscript out of bounds' refers to, as my understanding that was only when you requested a line or column in the data which did not exist.
Created on 2022-06-06 by the reprex package (v2.0.1)