R Programming - Remove Solar.R and 'Wind' Variables from airqualit
R Programming: Data frame Exercise-26 with Solution
Write a R program to call the (built-in) dataset airquality. Remove the variables 'Solar.R' and 'Wind' and display the data frame.
Sample Solution :
R Programming Code :
# Load the built-in airquality dataset
data = airquality
# Print a message indicating that the following data is from the airquality dataset
print("Original data: Daily air quality measurements in New York, May to September 1973.")
# Print the original data frame
print(data)
# Remove the 'Solar.R' variable from the data frame
data[,c("Solar.R")] = NULL
# Remove the 'Wind' variable from the data frame
data[,c("Wind")] = NULL
# Print a message indicating that the following data frame has had 'Solar.R' and 'Wind' variables removed
print("data.frame after removing 'Solar.R' and 'Wind' variables:")
# Print the modified data frame
print(data)
Output:
[1] "Original data: Daily air quality measurements in New York, May to September 1973." Ozone Solar.R Wind Temp Month Day 1 41 190 7.4 67 5 1 2 36 118 8.0 72 5 2 3 12 149 12.6 74 5 3 4 18 313 11.5 62 5 4 5 NA NA 14.3 56 5 5 ......... 152 18 131 8.0 76 9 29 153 20 223 11.5 68 9 30 [1] "data.frame after removing 'Solar.R' and 'Wind' variables:" Ozone Temp Month Day 1 41 67 5 1 2 36 72 5 2 3 12 74 5 3 4 18 62 5 4 5 NA 56 5 5 ......... 152 18 76 9 29 153 20 68 9 30
Explanation:
- data = airquality
- Loads the built-in dataset airquality into the variable data.
- print("Original data: Daily air quality measurements in New York, May to September 1973.")
- Prints a message indicating the following output is the original airquality dataset.
- print(data)
- Displays the content of the data data frame before any modifications.
- data[,c("Solar.R")] = NULL
- Removes the column Solar.R from the data data frame.
- data[,c("Wind")] = NULL
- Removes the column Wind from the data data frame.
- print("data.frame after removing 'Solar.R' and 'Wind' variables:")
- Prints a message indicating that the following output is the data data frame after removing the specified columns.
- print(data)
- Displays the content of the modified data data frame, showing that the Solar.R and Wind columns have been removed.
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Test your Programming skills with w3resource's quiz.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/r-programming-exercises/dataframe/r-programming-data-frame-exercise-26.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics