Re: [R] Recode Variable

2012-04-12 Thread S Ellison
> myData[myData$var1==5;"var1"]<-NA # recode value "5" into "NA" try myData[!is.na(myData$var1) & myData$var1==5;"var1"]<-NA or, more simply, myData$var1[myData$var1==5]<-NA *** This email and any attachments are confid

Re: [R] Recode Variable

2012-04-12 Thread Rainer Schuermann
1. Some data structured the way you are using would have been helpful. I used Tal Galil's play data and set up a dataframe with the variable names you are using: structure(list(var1 = c(1, NA, NA, 4, 5, 6, 7, 8, 9, 10, 5), var2 = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5)), .Names = c("var1", "var2

Re: [R] Recode Variable

2012-04-12 Thread Milan Bouchet-Valat
Le jeudi 12 avril 2012 à 11:08 +0200, David Studer a écrit : > Hello everybody, > > I know this is pretty basic stuff, but could anyone explain me how to > recode a single value of a variable > into a missing value? > > I used to do it like this: > > myData[myData$var1==5;"var1"]<-NA

Re: [R] Recode Variable

2012-04-12 Thread Milan Bouchet-Valat
Le jeudi 12 avril 2012 à 12:29 +0300, Tal Galili a écrit : > Hi David, > You bring up a good question. I am not sure what is the "right" way to > solve it. But here is a simple solution I put together: > > x = c(1:10,5) > y = x > x[c(2,3)] <- NA > > # reproducing the problem: > y[x==5] > > na2

Re: [R] Recode Variable

2012-04-12 Thread Tal Galili
Hi David, You bring up a good question. I am not sure what is the "right" way to solve it. But here is a simple solution I put together: x = c(1:10,5) y = x x[c(2,3)] <- NA # reproducing the problem: y[x==5] na2F <- function(x) { x2 <- x x2[is.na(x)] <- F x2 } na2F(x==5) # "solved

[R] Recode Variable

2012-04-12 Thread David Studer
Hello everybody, I know this is pretty basic stuff, but could anyone explain me how to recode a single value of a variable into a missing value? I used to do it like this: myData[myData$var1==5;"var1"]<-NA # recode value "5" into "NA" But the column "var1" already contains NAs, whic

Re: [R] recode Variable in dependence of values of two other variables

2011-08-12 Thread Dennis Murphy
Hi: Here are several equivalent ways to produce your desired output: # Base package: transform() df <- transform(df, mean = ave(x, id, FUN = mean)) # plyr package library('plyr') ddply(df, .(id), transform, mean = mean(x)) # data.table package library('data.table') dt <- data.table(df, key = '

Re: [R] recode Variable in dependence of values of two other variables

2011-08-12 Thread Mikhail Titov
?aggregate aggregate(X~ID, your.data.frame.goes.here, "mean") Mikhail > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Julia Moeller > Sent: Friday, August 12, 2011 10:10 AM > To: r-help@r-project.

[R] recode Variable in dependence of values of two other variables

2011-08-12 Thread Julia Moeller
Hi, as an R-beginner, I have a recoding problem and hope you can help me: I am working on a SPSS dataset, which I loaded into R (load("C:/...) I have 2 existing Variables: "ID" and "X" , and one variable to be computed: meanX.dependID (=mean of X for all rows in which ID has the same value)