Re: [R] new column that applies function to all rows based on last row

2014-03-03 Thread arun
HI BNC, For the example you provided: CHAR1n_totalNew <- within(CHAR1n_total,Newvar <- (Freq/tail(Freq,1))*100) #If you have more than one column #For example set.seed(42)  Freq2 <- sample(4,10,replace=TRUE)  CHAR1n_total$Freq2 <- c(Freq2,sum(Freq2))  dat2 <- as.data.frame(matrix(NA,ncol=((ncol

[R] new column that applies function to all rows based on last row

2014-03-03 Thread bcrombie
I know this is a simple question, but I am having trouble generating output without errors. I want to create a column containing values for each row that are generated by dividing another column's row value by the same column's sum (last-row value):