My previous question, though unanswered, allowed me to better formulate the issue in my head. I am still a beginner in R and I have no programming experience, just a strong desire (more like 'need') to use R in statistics. I will try to be as descriptive as possible.
I have a dataframe (df.x) that looks like this
Channel Week.nr MT DT EF PT LF NT
A 40 76.0% 83.6% 81.2% 33.7% 76.6% 65.6%
A 41 79.0% 83.4% 81.3% 35.6% 86.6% 74.3%
A 42 76.5% 82.0% 83.6% 33.8% 83.5% 71.9%
B 40 42.2% 68.9% 68.1% 67.4% 70.9% 0.0%
B 41 47.8% 78.9% 77.5% 76.5% 81.2% 0.0%
B 42 47.8% 79.1% 78.0% 76.0% 81.2% 0.0%
I want to create multiple dataframes for each column (except Channel and Week.nr), so in the end I should have df.x.MT, df.x.DT, df.x.EF etc.
Furthermore, the format of the dataframe should be changed, meaning that the week number will be columns, instead of elements inside a column. To better visualise what I mean, here is an example of how I need df.x.MT to look
Channel W40 W41 W42
A 76.0% 79.0% 76.5%
B 42.2% 47.8% 47.8%
keep in mind that there will be atleast 52 weeks, and around 150 channels, so in the end the dataframe will be huge.
So I have thought of isolating data for each week, so it would be simpler (i hope so) to recall it later in the df.x.MT dataframe. For this I have split the df.x dataframe in several dataframes (one for each week). I have used this code:
unique.weeks <- unique(df.x$Week) #identify unique weeks number
for(i in unique.weeks) {
assign(paste("df.x.week.", i, sep = ""), subset(df.x, Week == i))
}
Now all I need to do is to populate df.x.MT with df.x.week.40$MT, df.x.week.41$MT, df.x.week.42$MT etc. How can I do this in an automatic manner, rather than manually writing the code for each week? It feels like it should be a manner to call the names with a for*, but I can't figure it out.
*something like this (i know it's not correct)
for(i in unique.weeks) {
df.x.MT$[unique.weeks] <- df.x.week.[unique.weeks]
}