So the data goes like this.
- SalesData is a data.frame.
- SalesData$Day1 is numeric column including sales data of each member on first day. Same goes for $Day2, $Day3 ... $Day50
I'm trying to make a new column with 50 numeric data, sum of each day's sale, by using loop.
I tried
for (i in 1:50)
{SalesData$Dailysum[i] <- sum(SalesData$get(colnames(SalesData)[i]))
Error: attempt to apply non-function
apparently I can't use get(colnames(SalesData)[i] to extract specific header.
SalesData$colnames(SalesData)[i]
didn't work either.
Is there any way to use loop to extract header, and use it for loop?