{"id":194,"date":"2026-09-03T10:47:15","date_gmt":"2026-09-03T10:47:15","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=194"},"modified":"2026-09-03T10:47:15","modified_gmt":"2026-09-03T10:47:15","slug":"write-r-language-for-customer-details","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2026\/09\/03\/write-r-language-for-customer-details\/","title":{"rendered":"Write R Language For Customer Details"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Q. 1. Write R script to connect to a SQLite database and import a table named customer, which contains columns: CustID, CustName, Bill, and City. Display the imported data using R commands<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q. 2. After importing the customer table from the SQLite database, create a histogram of the bill column.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># ============================================\n# Q1: Connect to SQLite Database and Import Customer Table\n# ============================================\n\n# Load required libraries\nlibrary(RSQLite)\n\n# Create SQLite database with Indian customer data\nconn &lt;- dbConnect(SQLite(), dbname = \"customer_data.db\")\n\n# Sample Indian customer data\ncustomer_data &lt;- data.frame(\n  CustID = c(101, 102, 103, 104, 105, 106, 107, 108),\n  CustName = c(\"Rajesh Kumar\", \"Priya Sharma\", \"Amit Patel\", \"Sneha Reddy\", \n               \"Vikram Singh\", \"Ananya Gupta\", \"Rahul Joshi\", \"Meera Nair\"),\n  Bill = c(1500, 2500, 3200, 1800, 4500, 2100, 3800, 2900),\n  City = c(\"Mumbai\", \"Delhi\", \"Ahmedabad\", \"Hyderabad\", \n           \"Jaipur\", \"Kolkata\", \"Pune\", \"Chennai\"),\n  stringsAsFactors = FALSE\n)\n\n# Write to database\ndbWriteTable(conn, \"customer\", customer_data, overwrite = TRUE)\n\n# Import the table\nimported_data &lt;- dbGetQuery(conn, \"SELECT * FROM customer\")\n\n# Display imported data\ncat(\"\\n========== Q1: Imported Customer Data ==========\\n\")\nprint(imported_data)\n\n# Display data structure\ncat(\"\\nData Structure:\\n\")\nstr(imported_data)\n\n# Display summary\ncat(\"\\nData Summary:\\n\")\nsummary(imported_data)\n\n# ============================================\n# Q2: Create Histogram of Bill Column\n# ============================================\n\ncat(\"\\n========== Q2: Creating Histogram ==========\\n\")\n\n# Set up plot layout\npar(mfrow = c(1, 2))\n\n# Plot 1: Basic histogram\nhist(imported_data$Bill,\n     main = \"Distribution of Customer Bills\",\n     xlab = \"Bill Amount (\u20b9)\",\n     ylab = \"Number of Customers\",\n     col = \"lightblue\",\n     border = \"black\",\n     breaks = 5)\n\n# Plot 2: Enhanced histogram with density curve\nhist(imported_data$Bill,\n     main = \"Bill Distribution with Density\",\n     xlab = \"Bill Amount (\u20b9)\",\n     ylab = \"Frequency\",\n     col = \"lightgreen\",\n     border = \"white\",\n     breaks = 6,\n     probability = TRUE)\n\n# Add density curve\nlines(density(imported_data$Bill), col = \"red\", lwd = 2)\n\n# Add mean and median lines\nabline(v = mean(imported_data$Bill), col = \"blue\", lwd = 2, lty = 2)\nabline(v = median(imported_data$Bill), col = \"darkgreen\", lwd = 2, lty = 3)\n\n# Add legend\nlegend(\"topright\", \n       legend = c(\"Mean\", \"Median\", \"Density\"),\n       col = c(\"blue\", \"darkgreen\", \"red\"),\n       lty = c(2, 3, 1),\n       lwd = 2,\n       cex = 0.7)\n\n# Additional analysis: Bills by city\ncat(\"\\nAverage Bill by City:\\n\")\nprint(aggregate(Bill ~ City, data = imported_data, FUN = mean))\n\ncat(\"\\nTotal Bills by City:\\n\")\nprint(aggregate(Bill ~ City, data = imported_data, FUN = sum))\n\n# Close connection\ndbDisconnect(conn)\n\ncat(\"\\nAnalysis Complete!\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Q. 1. Write R script to connect to a SQLite database and import a table named customer, which contains columns: CustID, CustName, Bill, and City. Display the imported data using R commands Q. 2. After importing the customer table from the SQLite database, create a histogram of the bill column. # ============================================ # Q1: Connect [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":189,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,54],"tags":[25,26,56,57],"class_list":["post-194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bca","category-statistical-analysis-using-r","tag-bca","tag-bca-paper-solution","tag-r-language","tag-statistical-analysis-using-r"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=194"}],"version-history":[{"count":1,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions"}],"predecessor-version":[{"id":195,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/194\/revisions\/195"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/189"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}