R - Create DataFrame from Existing DataFrame means making a new data frame using the data already present in another data frame. We can do this by selecting specific columns, filtering rows or combining data. It helps in reusing and reshaping data for analysis. This can be done using base R, dplyr or data.table functions.
1. Using data.frame() with Direct Column Referencing
We create a new data frame and extract specific columns using the dollar sign operator.
data.frame(): Creates a new data frame.
df$column_name: Accesses specific columns from an existing data frame.
The final output shows a new data frame with only the selected columns (Name and Age) using the data.table package, confirming that we successfully filtered the desired data.