Skip to content

How to add a new row in to an existing data set in R Language?

4 messages · killerkarthick, Ista Zahn

#
Hi...
I have one 2 data set with 3 variables and 4 observations. I want to combine
the two data sets. I tried with merge but it gives only the common values. I
need common values and and remaining values also. Please help me?
this is my data set
dataset:1
name	va1	va2
AA	10	100
BB	20	200
CC	30	300
DD	40	400

dataset:2
name	va1	va2
AA	36	444
BB	10	111
CC	20	222
DD	NA	333
Please reply me.....................................



--
View this message in context: http://r.789695.n4.nabble.com/How-to-add-a-new-row-in-to-an-existing-data-set-in-R-Language-tp4644855.html
Sent from the R help mailing list archive at Nabble.com.
#
Hi,

Have you read the documentation for merge? The relevant section says

"     If 'all.x' is true, all the non matching cases of 'x' are appended
     to the result as well, with 'NA' filled in the corresponding
     columns of 'y'; analogously for 'all.y'."

Please do get in the habit of reading the documentation before posting
on the mailing list.

Best,
Ista
On Wed, Oct 3, 2012 at 7:30 AM, killerkarthick <karthick.gdi at gmail.com> wrote:
1 day later
#
Hi Ista Zahn,
                             Thanks for your advice. Please see the
following Image.




<http://r.789695.n4.nabble.com/file/n4645113/data.png> 






 i am expecting the result should same in the image. 
                            



--
View this message in context: http://r.789695.n4.nabble.com/How-to-add-a-new-row-in-to-an-existing-data-set-in-R-Language-tp4644855p4645113.html
Sent from the R help mailing list archive at Nabble.com.
#
Hi,
On Fri, Oct 5, 2012 at 12:27 AM, killerkarthick <karthick.gdi at gmail.com> wrote:
To me this example looks plain wrong. You end up with a row that
contains the date of birth for subject 104 and the date of informed
consent for subject 105.

If this really is the situation you face, I suggest correcting the ID
before merging.
OK, then fix your ID numbers and use merge(DF1, DF2).

Best,
Ista