[R] transform a df with a condition

2011-01-17 Thread Vijayan Padmanabhan
Hi Try the following... df - data.frame(A = c(1,1,3,2,2,3,3), B = c(2,1,1,2,7,8,7), K = c(a.1, d.2, f.3, a.1, k.4, f.9, f.5)) df$ID-rownames(df) df$K-as.character(as.character(df$K)) changefunction-function(z) { tmp - lapply(split(z, z[,4]), function(x) within(x, if(A==3)B - 5 )) dat2-tmp

[R] transform a df with a condition

2011-01-16 Thread Patrick Hausmann
Dear all, for each A == 3 in 'df' I would like to change the variables B and K. My result should be the whole df and not the subset (A==3)... df - data.frame(A = c(1,1,3,2,2,3,3), B = c(2,1,1,2,7,8,7), K = c(a.1, d.2, f.3, a.1, k.4, f.9,

Re: [R] transform a df with a condition

2011-01-16 Thread Patrick Hausmann
Arrg, sorry - of course I don't want *new* variables. So this is my correct example: df - data.frame(A = c(1,1,3,2,2,3,3), B = c(2,1,1,2,7,8,7), K = c(a.1, d.2, f.3, a.1, k.4, f.9, f.5)) x1 - within(df[df$A ==3, ], { B - 5

Re: [R] transform a df with a condition

2011-01-16 Thread Henrique Dallazuanna
Try this: df[df$A == 3, c('B', 'K')] - with(df[df$A == 3, c('B', 'K')], cbind(5, gsub(f, m, K))) On Sun, Jan 16, 2011 at 12:19 PM, Patrick Hausmann patrick.hausm...@uni-bremen.de wrote: Arrg, sorry - of course I don't want *new* variables. So this is my correct example: df - data.frame(A

Re: [R] transform a df with a condition

2011-01-16 Thread Duncan Murdoch
On 16/01/2011 9:13 AM, Patrick Hausmann wrote: Dear all, for each A == 3 in 'df' I would like to change the variables B and K. My result should be the whole df and not the subset (A==3)... df- data.frame(A = c(1,1,3,2,2,3,3), B = c(2,1,1,2,7,8,7), K =