[R] grab values in R

arun smartpink111 at yahoo.com
Tue Mar 11 13:27:20 CET 2014


Hi,
Use ?aggregate(), ?ddply() from library(plyr) etc.

dat <- read.table(text="ua ELM PRP
  122C MO 5
  122C BR 3
  122C FA 1
  122C MO 1
  122D BR 7
  122D MO 2
122D BR 1",sep="",header=TRUE,stringsAsFactors=FALSE)

library(plyr)
 ddply(dat,.(ua,ELM),summarize,PRP=sum(PRP))
#    ua ELM PRP
#1 122C  BR   3
#2 122C  FA   1
#3 122C  MO   6
#4 122D  BR   8
#5 122D  MO   2
A.K.




On Tuesday, March 11, 2014 6:04 AM, catalin roibu <catalinroibu at gmail.com> wrote:
Hello all!

I have a problem with R. How can I do this assemble the ELM PRP for each ua.
My data is like this:

ua ELM PRP  122C MO 5  122C BR 3  122C FA 1  122C MO 1  122D BR 7  122D MO 2
122D BR 1

and I want to obtain something like this:

ua ELM PRP  122C MO 6  122C BR 3  122C FA 1  122D BR 8  122D MO 2

Thank you very much!


-- 


---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone     +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
                       +4 0766 71 76 58
FAX:                +4 0230 52 16 64
silvic.usv.ro

    [[alternative HTML version deleted]]

______________________________________________
R-help at 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.





More information about the R-help mailing list