Re: [R] Add a column to a dataframe based on multiple other column values

2013-06-12 Thread Keith S Weintraub
Tom, Here is my solution. Note that I assume the columns are interleaved as you describe below. I'm sure others will have better replies. Note that using dput helps the helpers. # From dput(mdat) mdat-structure(list(x1 = c(2L, 2L, 2L, 3L, 3L, 30L, 32L, 33L, 33L), y1 = c(100L, 100L, 100L,

Re: [R] Add a column to a dataframe based on multiple other column values

2013-06-12 Thread arun
HI, You could also try: dat2- dat1[-ncol(dat1)] fun1- function(dat,value){     datNew- dat     n1- ncol(datNew)     indx1- seq(1,n1,by=2)     indx2- indx1+1     datNew[indx2][datNew[indx1] value]-NA     dat$output-rowMeans(datNew[indx2],na.rm=TRUE)     dat     }     fun1(dat2,10)  # x1  y1  x2 

[R] Add a column to a dataframe based on multiple other column values

2013-06-11 Thread Tom Oates
Hi I have a dataframe as below: x1y1x2y2x3y3output 21001909914307989 21001926314317569 21001926314445157 301959914995074.5 301989815008089 300198

Re: [R] Add a column to a dataframe based on multiple other column values

2013-06-11 Thread arun
HI, May be this helps: dat1- read.table(text= x1    y1    x2    y2    x3    y3    output 2    100    190    99    1430    79    89 2    100    192    63    1431    75    69 2    100    192    63    1444    51    57 3    0    195    99    1499    50    74.5 3    0    198    98    1500    80    89