[R] Dataframe modification

From: Sachin J <sachinj.2006_at_yahoo.com>
Date: Tue 22 Aug 2006 - 03:56:44 EST


Hi,    

  How can I accomplish this in R.    

  I have a Dataframe with 3 columns. Column B and C have same elements. But column A has more elements than B and C. I want to compare Column A with B and do the following:    

  If A is not in B then insert a new row in B and C and fill these new rows with   B = A and C = 0. So finally I will have balanced dataframe with equal no of rows (entries) in all the columns.    

  For example:    

  A[3] = 3 but is not in B. So insert new row and set B[3] = 3 (new row) and C[3] = 0. Final result would look like:    

  A B C
  1 1 5
  2 2 3
  3 3 0
  4 4 10
  5 5 0
  6 6 0
  7 7 12
  8 8 17    

  These are the columns of DF
> a <- c(1,2,3,4,5,6,7,8)
> b <- c(1,2,4,7,8)
> c(5,3,10,12,17)
   

  Thanx in advance for the help.    

  Sachin


        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch 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. Received on Tue Aug 22 04:12:28 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 22 Aug 2006 - 06:23:35 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.