stephen sefick
2008-Oct-29 01:41 UTC
[R] help with doing a manipulation on a column of a data frame based on another column
#this is my stab at - I am sure that I am missing something. If this doesn't make sense then please ask for more details. #This may show my low level of programing knowledge hester. <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4) value <- rnorm(16) x <- data.frame(value, hester.) z <- (if(x[,"hester."]==1){ x[,"value"]*6.250} else if(x[,"hester."]==2){ x[,"value"]*3.125} else if(x[,"hester."]==3){ x[,"value"]*2.100} else if(x[,"hester."]==4){ x[,"value"]*1.600}) thanks stephen -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
Rolf Turner
2008-Oct-29 01:54 UTC
[R] help with doing a manipulation on a column of a data frame based on another column
On 29/10/2008, at 2:41 PM, stephen sefick wrote:> #this is my stab at - I am sure that I am missing something. If this > doesn't make sense then please ask for more details. #This may show > my low level of programing knowledge > > hester. <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4) > value <- rnorm(16) > x <- data.frame(value, hester.) > > z <- > (if(x[,"hester."]==1){ > x[,"value"]*6.250} > else > if(x[,"hester."]==2){ > x[,"value"]*3.125} > else > if(x[,"hester."]==3){ > x[,"value"]*2.100} > else > if(x[,"hester."]==4){ > x[,"value"]*1.600})Does this do what you want? > h <- rep(1:4,each=4) > z <- c(6.25,3.125,2.1,1.6)[match(h,1:4)] > x <- data.frame(hester.=h,value=z) cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
joris meys
2008-Oct-29 12:39 UTC
[R] help with doing a manipulation on a column of a data frame based on another column
> #this is my stab at - I am sure that I am missing something. If this > doesn't make sense then please ask for more details. #This may show > my low level of programing knowledge > > hester. <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4) > value <- rnorm(16) > x <- data.frame(value, hester.) > > z <- > (if(x[,"hester."]==1){ > x[,"value"]*6.250} > else > if(x[,"hester."]==2){ > x[,"value"]*3.125} > else > if(x[,"hester."]==3){ > x[,"value"]*2.100} > else > if(x[,"hester."]==4){ > x[,"value"]*1.600})Does this do what you want? > h <- rep(1:4,each=4) > z <- c(6.25,3.125,2.1,1.6)[match(h,1:4)] > x <- data.frame(hester.=h,value=z) cheers, Rolf Turner --------------------------------------------- I suspect some random values should be included, making the code :> h <- rep(1:4,each=4)> z <- c(6.25,3.125,2.1,1.6)[match(h,1:4)] > x <- data.frame(hester.=h,value=z*rnorm(16)) Kind regards Joris
Reasonably Related Threads
- Graphing question (multiple line graphs arranged spatially)
- stacking consecutive columns
- Removing rows with rowsums==0 (I can't figure this out)
- for loop question Documentation and its application for calculating euclidean distance on MDS ordination axis scores
- persp question