mergeupdate | R Documentation |
1:1 or 1:many update merge
mergeupdate(df1, df2, id, id1, id2, mergetype = "1:1")
df1 |
dataframe to be updated |
df2 |
dataframe with new observations or data to update |
id |
common id |
id1 |
id for dataframe 1 (optional if common id not specified) |
id2 |
id for dataframe 2 (optional if common id not specified) |
mergetype |
character 1:1 (default) or 1:m |
dataframe
Updates values in df1 with values from df2
If df2 columns contain NAs, df1 values are retained
1 to many merges expands original dataset(df1), creates new id and duplicates values for which there are no values in second dataset
also 1:m re-sorts dataset based on id
data(iris)
iris2<-iris
iris$id<-1:dim(iris)[1]
iris2<-iris
iris2$Sepal.Length<-rnorm(150)
iris2$Petal.Width[25:75]<-rnorm(51)
iris2$color="red"
iris$height="tall"
xx<-mergeupdate(iris, iris2, id="id")
data1<-data.frame(id=rep(1:10), x=1, y=10*runif(10), z=10)
data3<-data.frame(id=rep(1:10, 3), z=rnorm(30), y=100*runif(30))
mergeupdate(data1, data3, id="id", mergetype="1:m")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.