[R] hi have a question about merging.
Santosh Srinivas
santosh.srinivas at gmail.com
Thu Dec 9 07:19:56 CET 2010
Try this
male.df <- subset(raceprofiling, (male==1))
female.df <- subset(raceprofiling, (male==0))
people.df <- rbind(male.df,female.df)
works?
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of tanzia chaudhury
Sent: 09 December 2010 09:02
To: r-help at r-project.org
Subject: [R] hi have a question about merging.
this is the problem:
load this R data frame over the internet and save it to your hard drive.
http://rss.acs.unt.edu/Rdoc/library/twang/data/racepro
ling.RData
please show how to save a dataset of males only (the variable male=1) to a
new dataframe. Then do the same thing for females (male=0). Then show how to
recombine the two datasets to belike the original one except that the female
observations come
rst, then the male observations. This resultingdataset should be the same
size as the original.
this is what i did so far:
# loading the R data frame over the internet
and saving it to your hard drive
>rp<-url("http://rss.acs.unt.edu/Rdoc/library/twang/data/raceprofiling.RData
")
>load(rp)
>str(raceprofiling)
#this shows that in the RData file there are
5000 obs. of 10 variables.
# For
the fourth dataset, please show how to save a dataset of males only (the
variable male=1)
#to a new #data frame.
>attach(raceprofiling)
>s<-male[male==1]
>news<-data.frame(s)
#The same thing for females (male=0).
>r<-male[male==0]
>newr<-data.frame(r)
now to merge:
I tried >merge(newr,news)
but this does not give the same observation as the original file. I also
tried rbind, but this gives me error. Please help
[[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