简体   繁体   中英

Export csv in R

Try to export my data.frame to csv

google_analytics(214199202,
                     date_range = c("2020-05-27", "2020-06-11"),
                     metrics = c("ga:transactions","ga:transactionRevenue"),
                     dimensions = c("ga:date","ga:campaign","ga:sourceMedium"),
                     filtersExpression = "ga:sourceMedium=~(yandex / cpc|google / cpc)",
                     write.csv(google_analytics, file = "filename.csv")
                     )

But after running it, I receive this error:

Ошибка в as.data.frame.default(x[[i]], optional = TRUE): cannot coerce class '"function"' to a data.frame

I don't understand where the problem is

I don't use googleAnalyticsR but from what I can see in the manual, google_analytics() returns a data.frame and the 6th argument is met_filters . You put the function write.csv() in the 6th argument as met_filters thus resulting in error. You should save the output of google_analstics first then export to csv.


library(googleAnalyticsR)

# Fetch data and save data.frame to "yourData"
yourData <- google_analytics(
  214199202,
  date_range = c("2020-05-27", "2020-06-11"),
  metrics = c("ga:transactions","ga:transactionRevenue"),
  dimensions = c("ga:date","ga:campaign","ga:sourceMedium"),
  filtersExpression = "ga:sourceMedium=~(yandex / cpc|google / cpc)"
)

# Export "yourData" as csv
write.csv(yourData, file = "filename.csv")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM