For the following: Bldgid<-c(1000,1000,1000,1001,1002,1003,1003,1003) Maplot<-c(20000,20001,20002,30000,30001,40000,40001,40002) Area<-c(40,170,160,50,100,100,90,110) #Construct Sample dataframe MultiLotBldgs..<-data.frame(Bldgid,Maplot,Area)
CondoLots_ <- tapply(MultiLotBldgs..$Maplot, MultiLotBldgs..$Bldgid, length) CondoLots_ Returns: 1000 1001 1002 1003 3 1 1 3 What i want to do is to subtract 1 from the above for all cases where there are more than one, so that CondoLots_ returns: 1000 1001 1002 1003 2 1 1 2 I have tried for(i in 1:length(CondoLots_)){ ifelse(CondoLots_>1){ CondoLots2_<-CondoLots_-1 } } But it doesnt seem to work properly. I think this should be simple. Thanks in advance. JR -- View this message in context: http://n4.nabble.com/Subtracting-one-based-on-an-If-tp1561047p1561047.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.