Combining multiple dataframe in R -
i have 5 dataframe (df1
, df2
, df3
, df4
, df5
). have same columns , column names (nir database). frist combine df1
, df2
df12
, df3
, df4
, df5
df345
, combine df12
, df345
df
. (it has 2 stages).
df12 <- do.call(rbind, list(df1,df2)) df345 <- do.call(rbind, list(df3,df4,df5)) df <- do.call(rbind, list(df12,df345)) newdf <- data.frame(oiltype="olive",nir=df[2:276]);
with got 1 of column names become nir.nir.v4
while need nir.v4
.
i think due use of list. know if there's alternative combine multiple dataframes without having face trouble. appreciate suggestion.
i have 5 data.frame df1, df2, df3, df4, df5 having same columns , column names.
> df1 sepal.length sepal.width petal.length petal.width species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa > df2 sepal.length sepal.width petal.length petal.width species 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa > df3 sepal.length sepal.width petal.length petal.width species 7 4.6 3.4 1.4 0.3 setosa 8 5.0 3.4 1.5 0.2 setosa 9 4.4 2.9 1.4 0.2 setosa > df4 sepal.length sepal.width petal.length petal.width species 10 4.9 3.1 1.5 0.1 setosa 11 5.4 3.7 1.5 0.2 setosa 12 4.8 3.4 1.6 0.2 setosa > df5 sepal.length sepal.width petal.length petal.width species 13 4.8 3 1.4 0.1 setosa 14 4.3 3 1.1 0.1 setosa 15 5.8 4 1.2 0.2 setosa
for combining df1 , df2
> df12 <- rbind(df1,df2) > df12 sepal.length sepal.width petal.length petal.width species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa
for combining df3, df4, df5 same above
> df345 <- rbind(df3,df4,df5) > df345 sepal.length sepal.width petal.length petal.width species 7 4.6 3.4 1.4 0.3 setosa 8 5.0 3.4 1.5 0.2 setosa 9 4.4 2.9 1.4 0.2 setosa 10 4.9 3.1 1.5 0.1 setosa 11 5.4 3.7 1.5 0.2 setosa 12 4.8 3.4 1.6 0.2 setosa 13 4.8 3.0 1.4 0.1 setosa 14 4.3 3.0 1.1 0.1 setosa 15 5.8 4.0 1.2 0.2 setosa
and @ last combining newly formed data frame can done in similar way
> df <- rbind(df12,df345) > df sepal.length sepal.width petal.length petal.width species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa 7 4.6 3.4 1.4 0.3 setosa 8 5.0 3.4 1.5 0.2 setosa 9 4.4 2.9 1.4 0.2 setosa 10 4.9 3.1 1.5 0.1 setosa 11 5.4 3.7 1.5 0.2 setosa 12 4.8 3.4 1.6 0.2 setosa 13 4.8 3.0 1.4 0.1 setosa 14 4.3 3.0 1.1 0.1 setosa 15 5.8 4.0 1.2 0.2 setosa
Comments
Post a Comment