I have a data frame (df) with two variables shown below:
pricePerBusiness num_businesses
1 4228.966 3755
2 4966.552 3243
3 4678.073 3109
4 4752.259 2990
5 4545.194 2949
I want to make a new data frame which is a product of this dataframe and a scalar (15 in this example) that increases in value (1,2,3,...) for each row, example:
df2[1,] <- 1*df[1,]$pricePerBusiness + 0.15*df[1,]$num_businesses - 15*1
df2[2,] <- 1*df[2,]$pricePerBusiness + 0.15*df[2,]$num_businesses - 15*2
df2[3,] <- 1*df[3,]$pricePerBusiness + 0.15*df[3,]$num_businesses - 15*3
And so on. My dataframe (df) however has many rows, is there a quicker way to do this?
modify your scalar with
as.numeric(rownames(df))*0.15