Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Help . With my RStudio project it is saying it cant take my excel as an csv file because it is a xls or xslx

Help . With my RStudio project it is saying it cant take my excel as an csv file because it is a xls or xslx my code is below.
# Read the data
housing_data <- read.csv("Housing.csv", stringsAsFactors = TRUE)
# Print the first 10 observations
head(housing_data, 10)
# Select specific columns
housing_data <- housing_data[, c("price", "area", "bedrooms", "stories", "basement", "furnishingstatus")]
# Print the first 10 observations to verify
head(housing_data, 10)
# Check variable types
str(housing_data)
# Summary statistics
summary(housing_data)
# Load ggplot2 for plotting
library(ggplot2)
# Create bar charts for factor variables
factor_vars <- sapply(housing_data, is.factor)
for (var in names(factor_vars)[factor_vars]){
ggplot(housing_data, aes_string(x = var))+
geom_bar()+
ggtitle(paste("Bar Chart of", var))+
xlab(var)+
ylab("Count")+
theme_minimal()
}
# Histograms
ggplot(housing_data, aes(x = price))+
geom_histogram(binwidth =50000, fill = "blue", color = "black")+
ggtitle("Histogram of Price")+
xlab("Price")+
ylab("Frequency")+
theme_minimal()
ggplot(housing_data, aes(x = area))+
geom_histogram(binwidth =50, fill = "green", color = "black")+
ggtitle("Histogram of Area")+
xlab("Area")+
ylab("Frequency")+
theme_minimal()___
# Scatter plot
ggplot(housing_data, aes(x = area, y = price))+
geom_point()+
ggtitle("Scatter Plot of Price vs. Area")+
xlab("Area")+
ylab("Price")+
theme_minimal()
# Subset data for homes with basement
housing_basement <- subset(housing_data, basement == "yes")
# Print the first few lines
head(housing_basement)
# Pie chart
ggplot(housing_basement, aes(x ="", fill = furnishingstatus))+
geom_bar(width =1)+
coord_polar(theta ="y")+
ggtitle("Pie Chart of Furnishing Status (Homes with Basement)")+
theme_minimal()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions