Accessing columns ($, [])
📖 Scenario: You have a small table of fruits and their prices. You want to get the prices using two common ways in R: the $ operator and the [] operator.
🎯 Goal: Learn how to access columns in a data frame using $ and [] in R.
📋 What You'll Learn
Create a data frame called
fruits with columns name and priceCreate a variable called
col_name with the value "price"Use the
$ operator to get the price column and save it in prices_dollarUse the
[] operator with col_name to get the price column and save it in prices_bracketsPrint both
prices_dollar and prices_brackets💡 Why This Matters
🌍 Real World
Accessing columns in data frames is a common task when working with data in R, such as analyzing sales, survey results, or scientific data.
💼 Career
Data analysts and scientists frequently use these techniques to manipulate and explore data sets efficiently.
Progress0 / 4 steps