smartinsightsfromdata/rpivotTable

How to add more than 1 vals = "" fields in "rpivotTable"

amitaharish opened this issue · 5 comments

Dear Team,

Please help in modifying the code for rpivottable. I need to add more then 1 values. The code I tried is -
vals = c("ABC" , "XYZ") , aggregatorName = "Sum"

No error is received but the code is not working.

Regards,
Amita

Amita, can you please provide a minimal reproducible example? Thanks

https://github.com/smartinsightsfromdata/rpivotTable
https://cran.r-project.org/web/packages/rpivotTable/vignettes/rpivotTableIntroduction.html

In the above mentioned website, there is an option of only one value ie vals = "Freq" only.
I need to add one more ie vals='Freq' and vals='Sum' and more.
The code I tried is -
vals = c("ABC" , "XYZ") , aggregatorName = "Sum"
but this is not working.

Amita, that is not what I need to be able to help you.

Can you please post a fully coded minimal reproducible example? Thanks

Please note, the base data has been taken from Google Analytics, a pivot has been made out of this. Below is the code for extraction from GA and then pivot.

#install devtools package for downloading packages from github
install.packages("devtools")
library(devtools)
#install curl for easier use
install.packages("curl")
library(curl)

#install RCurl
install.packages("RCurl")

library(RCurl)
library(bitops)
library(jsonlite)
library(httr)

#installing rga package from github
install_github("skardhamar/rga")
library(rga)

rga.open(instance = "ga")

#enter the code in console
id<-"...."

ga$getData(id)

'Adwords from GA'
gaData <- ga$getData(id,batch = TRUE,start.date = as.Date("2017-04-01"),
end.date=as.Date("2017-05-15"),
metrics = "
ga:impressions,
ga:adClicks,
ga:sessions,
ga:percentNewSessions,
ga:bounces,
ga:users,
ga:newusers
",
dimensions = "ga:channelGrouping,ga:date", start = 1,max = 10000)

rpivotTable::rpivotTable(gaData)
rpivotTable(gaData,rows = "channelGrouping",vals = "freq",aggregatorName = "Sum" ,cols = c("deviceCategory"))
rpivotTable(gaData)

The changes I made here are -
rpivotTable(gaData,rows = "channelGrouping",vals = "freq",aggregatorName = c("Sum","count") ,cols = c("deviceCategory"))

Please guide me in the above code. All i am trying is sum and count both for a particular column.

pivot

Any comments on this?