Re: [R] Finding a Diff within a Dataframe columns

2011-01-31 Thread jim holtman
I see that others have already responded, but will add my point of view. You indicated that you wanted to take the difference between pairs of columns and did not specify exactly how many there were; in your example there were 4 columns (2 pairs). If there were only two, then the solution from De

Re: [R] Finding a Diff within a Dataframe columns

2011-01-31 Thread Ramya
Thanks. It helped me a lot. Ramya On Mon, Jan 31, 2011 at 6:56 AM, djmuseR [via R] < ml-node+3248651-1296211736-40...@n4.nabble.com > wrote: > Hi: > > I won't speak for Jim, as he's more than capable of responding to this > himself, but I'll give it a shot: > > (1) It's not just the 'double per

Re: [R] Finding a Diff within a Dataframe columns

2011-01-31 Thread Dennis Murphy
Hi: I won't speak for Jim, as he's more than capable of responding to this himself, but I'll give it a shot: (1) It's not just the 'double percent sign', it's that slash in between them, too. Certain operators in R happen to be enclosed between two percent signs. %/% is the integer division oper

Re: [R] Finding a Diff within a Dataframe columns

2011-01-31 Thread Henrique Dallazuanna
Try this: aggregate(t(x), list(gl(2, 2)), FUN = 'diff') On Sun, Jan 30, 2011 at 11:32 PM, Ramya wrote: > > Hi, > > I have a Dataframe. > > A B C D > 0.10.7 0.9 0.8 > 0.20 0.60 0.80 0.70 > 0.40 0.80 0.70 0.76 > > I need a resultant dataframe > > (A-B) (C-D) > -0.6

Re: [R] Finding a Diff within a Dataframe columns

2011-01-31 Thread Dennis Murphy
Hi: This also works on your example data. Using the 'x' data frame from Jim Holtman's post, subset(transform(x, diffAB = A - B, diffCD = C - D), select = c('diffAB', 'diffCD')) diffAB diffCD 1 -0.6 0.10 2 -0.4 0.10 3 -0.4 -0.06 transform() allows you to do the subtractions in one li

Re: [R] Finding a Diff within a Dataframe columns

2011-01-30 Thread Ramya
Hi jholtman, Thanks a ton it just worked. if you dont mind can you explain the code it a little sapply(seq(from = 1, by = 2, length = ncol(x) %/% 2), function(a){ + x[[a]] - x[[a + 1]] + }) wat is the purpose of double percent sign and is the sapply the function we generally use for the Da

Re: [R] Finding a Diff within a Dataframe columns

2011-01-30 Thread jim holtman
try this: > x A B CD 1 0.1 0.7 0.9 0.80 2 0.2 0.6 0.8 0.70 3 0.4 0.8 0.7 0.76 > source('clipboard') > x <- read.table(textConnection("A B C D + 0.10.7 0.9 0.8 + 0.20 0.60 0.80 0.70 + 0.40 0.80 0.70 0.76"), header = TRUE) > closeAllConnections() > sapply(seq

Re: [R] Finding a Diff within a Dataframe columns

2011-01-30 Thread Santosh Srinivas
Please take a look at the introduction to R too ... > df <- read.delim(textConnection(Lines),sep="") > df A B CD 1 0.1 0.7 0.9 0.80 2 0.2 0.6 0.8 0.70 3 0.4 0.8 0.7 0.76 > d['A-B'] <- with(df, A-B) Error in d["A-B"] <- with(df, A - B) : object 'd' not found > d$v1 <- with(df, A-B) Erro

[R] Finding a Diff within a Dataframe columns

2011-01-30 Thread Ramya
Hi, I have a Dataframe. A B C D 0.10.7 0.9 0.8 0.20 0.60 0.80 0.70 0.40 0.80 0.70 0.76 I need a resultant dataframe (A-B) (C-D) -0.6 0.1 -0.400.1 -0.40 -0.06 Any suggestion would be of a great help Thanks Ramya -- View this message in context: http