0

I'm quite new to R or programming in general, so it's hard to articulate my thoughts right now.

I have a huge database that has two main differentiation factors name and date. The final product will be something that will look like this:

name  W1   W2   W3
 A    10   12   22
 B    20   13   44
 C    15   14   11

But also, it has to allow me to add a new week to the column.

Currently, I have managed to write the code for only one week. I guess I can put the weeks together, one by one, but I am sure that there should be another simpler/automatic method.

I have managed to write a code to identify the week based on the date, so in the database i have a column with the week.

With summarise and group by, I have managed to create a function that sum all identical names and split them by weeks. The data frame looks like this:

Channel        Week    allday.sum
ALL             41      870969 
ALL             42      5317647
A               41      261623
A               42      223144 

Now I need a method that will allow me to add to another data frame a new column with any possible weeks that may appear - so the data.frame will look like this

 name   W41  W42  W43
 ALL    10   12   22
 A      20   13   44
 B      15   14   11

I hope I was descriptive enough :D

kozoCMT
  • 3
  • 1
  • What do the values 10, 12, 22, etc. represent in your desired data frame? – Mako212 Oct 22 '19 at 15:49
  • @Mako212 The values from the data frame will be percentile/numerical and if it matters, the intent is to use those numbers for visualisation in ggplot2 mostly – kozoCMT Oct 22 '19 at 19:22
  • I still don't understand what you're trying to do, or how you would get to your desired result from your provided data. – Mako212 Oct 22 '19 at 21:24
  • what I have is a data base that is being updated weekly with new data. the data processing part I have managed to write it. What I don't know is how can I add a new column automatically to the data frame when a new week is being introduced. Basically how can I add a new column automatically for the new week. – kozoCMT Oct 23 '19 at 11:42
  • You seem to be asking for a very nuanced and specific solution, but you've provided only general information about what you're trying to do. Please see [How to create a great reproducible example in R](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and either update your question, or ask a new one. – Mako212 Oct 23 '19 at 15:24
  • Some thoughts: you say you have a database, what DBMS is it running on, and how are you connecting to it with R? Are you trying to add this column in an R data frame, or does it make sense to add it using SQL? Is there a reason why it needs to be a column, rather than in long format, which is typically better for storage in a database? Where is your data coming from, and how does the input move from the raw input to where you are stuck? – Mako212 Oct 23 '19 at 15:27

0 Answers0