I would like to create new column in data.frame as following:
Data description:
`'data.frame': 20 obs. of 3 variables:
$ gvkey : int 1004 1004 1004 1004 1004 1004 1004 1004 1004 1004 ...
$ DEF : int 0 0 0 0 0 0 0 0 0 0 ...
$ FittedRobustRatio: num 0.549 0.532 0.519 0.539 0.531 ...`
Function I wrote and doesn't work:
fun.mark <- function(x,y){
if (x==0) { y[y>0.60] <- "Del"
} else (x==1) {
y[y<0.45] <- "Del2"}}
NewDataFrame <- ddply(ShorterData,~gvkey,transform,Fitcorr=fun.mark(DEF, FittedRobustRatio))
So basically what I want to do is to look into DEF column if 0 and FittedRobustRatio > 0.60 then replace the value with "Del" and if column DEF is 1 (there are only 0 or 1 values in the column) then look into FittedRobustRatio column and replace values where <0.45 with for example "Del2". Thanks.