Re: [R] adding new values to dataframe based on existing values in two columns

2016-07-24 Thread Alexander.Herr
Here is another solution using interaction, aggregate and merge: interaction(xyz[,1],xyz[,2])->nf #create a unique x.y grouping cbind(xyz[,1:2],nf) aggregate(xyz[,3],list(nf),min)->nmins names(nmins)<-c('nf','mins.1') xyz$nf<-nf merge(xyz,nmins, by='nf', all=TRUE)->nd head(nd)

[R] adding new values to dataframe based on existing values in two columns

2016-07-21 Thread Alexander.Herr
Hiya, I am trying to assign minimum values to a dataframe based on existing columns. I can do this via loops, but surely R has much more elegant solutions... Here is my code: set.seed(666) xyz<-as.data.frame(cbind(x=rep(rpois(50,10),2)+1, y=rep(rpois(50,10),2)+1,z=runif(100, min=-3, max=40)))