<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coding Campus</title>
	<atom:link href="https://codingcampus.net/feed/" rel="self" type="application/rss+xml" />
	<link>https://codingcampus.net/</link>
	<description>Learn to Code</description>
	<lastBuildDate>Tue, 09 Jul 2024 15:38:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://codingcampus.net/wp-content/uploads/2022/11/Coding-Campus-Logo-150x150.png</url>
	<title>Coding Campus</title>
	<link>https://codingcampus.net/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">212689819</site>	<item>
		<title>What Does // Mean in Python? A Beginner&#8217;s Guide to Floor Division</title>
		<link>https://codingcampus.net/what-does-slash-mean-in-python/</link>
					<comments>https://codingcampus.net/what-does-slash-mean-in-python/#respond</comments>
		
		<dc:creator><![CDATA[codingxcampus013]]></dc:creator>
		<pubDate>Tue, 09 Jul 2024 15:33:00 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://codingcampus.net/?p=1615</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/what-does-slash-mean-in-python/">What Does // Mean in Python? A Beginner&#8217;s Guide to Floor Division</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In Python, the <code>//</code> operator performs <strong>floor division</strong>. This means it divides two numbers and rounds down the result to the nearest whole number. The process of rounding down is called &#8220;flooring,&#8221; hence the name &#8220;floor division.&#8221;</p>
<h2>Syntax</h2>
<p>The syntax for floor division is straightforward:</p>
<pre class="brush: python; title: ; notranslate">result = numerator // denominator</pre>
<p>Where <code>numerator</code> is the number to be divided, and <code>denominator</code> is the number by which you divide.</p>
<h2>How Does Floor Division Work?</h2>
<h3>Integer Division</h3>
<p>When both operands are integers, the result of the <code>//</code> operator is also an integer. It divides the first operand by the second and then floors the result to the nearest integer towards negative infinity.</p>
<h4>Example 1: Positive Integers</h4>
<pre class="brush: python; title: ; notranslate">result = 7 // 2
print(result)  # Output: 3
</pre>
<p>In this example, 7 divided by 2 is 3.5. Flooring 3.5 gives us 3.</p>
<h4>Example 2: Negative Integers</h4>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<pre class="brush: python; title: ; notranslate">result = -7 // 2
print(result)  # Output: -4</pre>
<p>Here, -7 divided by 2 is -3.5. Flooring -3.5 towards negative infinity gives us -4.</p>
<h2>Floating-Point Division</h2>
<h4>Example 3: Float and Integer</h4>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<pre class="brush: python; title: ; notranslate">result = 7.0 // 2
print(result)  # Output: 3.0
</pre>
<p>In this example, 7.0 divided by 2 is 3.5. Flooring 3.5 gives us 3.0 (float).</p>
<h4>Example 4: Integer and Float</h4>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<pre class="brush: python; title: ; notranslate">result = 7 // 2.0
print(result)  # Output: 3.0
</pre>
<p>Here, 7 divided by 2.0 is 3.5. Flooring 3.5 gives us 3.0 (float).</p>
<h3>Negative Floats</h3>
<p>Floor division with negative floats follows the same principle, rounding towards negative infinity.</p>
<h4>Example 5: Negative Float</h4>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<pre class="brush: python; title: ; notranslate">result = -7.0 // 2
print(result)  # Output: -4.0
</pre>
<p>In this example, -7.0 divided by 2 is -3.5. Flooring -3.5 gives us -4.0 (float).</p>
<h2>Practical Use Cases</h2>
<p>Floor division is particularly useful when you need an integer result from division, such as when working with indices in a list or when ensuring the result is a whole number for further computations.</p>
<h4>Example 6: Using Floor Division for Indexing</h4>
<p>Imagine you have a list of items and want to divide it into two equal parts:</p>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<div class="flex items-center relative text-token-text-secondary bg-token-main-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md">
<pre class="brush: python; title: ; notranslate">items = &#x5B;1, 2, 3, 4, 5, 6]
half_length = len(items) // 2
print(half_length)  # Output: 3
first_half = items&#x5B;:half_length]
second_half = items&#x5B;half_length:]
print(first_half)  # Output: &#x5B;1, 2, 3]
print(second_half)  # Output: &#x5B;4, 5, 6]
</pre>
<p>In this example, <code>len(items) // 2</code> calculates the halfway point of the list, allowing us to split it into two parts.</p>
<h4>Example 7: Ensuring Whole Number Results</h4>
<p>If you&#8217;re calculating the number of full boxes needed to pack items, floor division can help:</p>
<div class="dark bg-gray-950 rounded-md border-[0.5px] border-token-border-medium">
<pre class="brush: python; title: ; notranslate">total_items = 17
items_per_box = 5
full_boxes = total_items // items_per_box
print(full_boxes)  # Output: 3
</pre>
<p>Here, <code>17 // 5</code> calculates the number of full boxes required, ignoring any leftover items.</p>
<h2>Comparisons with Other Operators</h2>
<ul>
<li><strong><code>/</code> (True Division):</strong> This operator performs standard division and always returns a float, even if both operands are integers.</li>
<li><strong><code>%</code> (Modulo):</strong> This operator returns the remainder of a division operation.</li>
<li><strong><code>divmod(a, b)</code>:</strong> This function returns a tuple containing the result of <code>a // b</code> and <code>a % b</code>.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p>The post <a href="https://codingcampus.net/what-does-slash-mean-in-python/">What Does // Mean in Python? A Beginner&#8217;s Guide to Floor Division</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/what-does-slash-mean-in-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1615</post-id>	</item>
		<item>
		<title>print() Function in R</title>
		<link>https://codingcampus.net/print-function-in-r/</link>
					<comments>https://codingcampus.net/print-function-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Kenneth Stenberg]]></dc:creator>
		<pubDate>Fri, 17 Mar 2023 19:55:00 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://codingcampus.net/?p=1312</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/print-function-in-r/">print() Function in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The <strong>print()</strong> function allows you to print objects to the console. For example, you can use the print() function to print vectors, matrices, data frames, and lists. In addition, the print() function can be used to print the results of a computation. This guide will discuss using the <strong>print()</strong> in R.</p>
<h4>Syntax</h4>
<pre><code>print(x)</code></pre>
<h4>Arguments</h4>
<ul>
<li><strong>x</strong> = The object can be of any type, including vectors, matrices, data frames, and lists.</li>
</ul>
<h3>Example 1: Print Values using print() function</h3>
<pre><code>#printing values
print("R Programming Guide")</code></pre>
<h4>Output</h4>
<pre><code>[1] "R Programming Guide"</code></pre>
<h3>Example 2: Print Variables using print() function</h3>
<pre><code>#creating a variable
x &lt;- 25
#printing variable
print(x)</code></pre>
<h4>Output</h4>
<pre><code>[1] 25</code></pre>
<h3>Example 3: Print a Vector using print() function</h3>
<pre><code>#creating a vector
x &lt;- c(1:5)
#printing vector
print(x)</code></pre>
<h4>Output</h4>
<pre><code>[1] 1 2 3 4 5</code></pre>
<h3>Example 4: Print a List using print() function</h3>
<pre><code>#creating a list
x &lt;- list('Bruce','Wayne',1.6,'Martial Arts')
#printing list
print(x)</code></pre>
<h4>Output</h4>
<pre><code>[[1]]
[1] "Bruce"

[[2]]
[1] "Wayne"

[[3]]
[1] 1.6

[[4]]
[1] "Martial Arts"</code></pre>
<h3>Example 5: Print a Data Frame using print() Function</h3>
<pre><code>#printing the preloaded iris data frame
print(iris)</code></pre>
<h4>Output</h4>
<figure id="attachment_25710" aria-describedby="caption-attachment-25710" style="width: 590px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" class="size-medium wp-image-25710" src="http://codingcampus.net/wp-content/uploads/2022/09/Print-Data-Frame-600x464-1.jpg" alt="Print Data Frame" width="600" height="464" /><figcaption id="caption-attachment-25710" class="wp-caption-text">Printing data frame to the console.</figcaption></figure>
<p>The post <a href="https://codingcampus.net/print-function-in-r/">print() Function in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/print-function-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1312</post-id>	</item>
		<item>
		<title>How to Create Stacked Histograms in R</title>
		<link>https://codingcampus.net/how-to-create-stacked-histograms-in-r/</link>
					<comments>https://codingcampus.net/how-to-create-stacked-histograms-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Kenneth Stenberg]]></dc:creator>
		<pubDate>Wed, 15 Mar 2023 21:45:00 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://codingcampus.net/?p=1326</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/how-to-create-stacked-histograms-in-r/">How to Create Stacked Histograms in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A stacked histogram is a graphical representation of data where the individual values are placed on top of each other. This type of histogram is useful for seeing data distribution and spotting patterns. With stacked histograms, we plot more than one population on one graph. Using the<strong> hist()</strong> and <strong>ggplot()</strong> functions, you can create stacked histograms. This guide explains how to create stacked histograms in R.</p>
<h2>Using hist() Function to Create Stacked Histogram in R</h2>
<p>You should use the <strong>hist()</strong> function to create a stacked histogram when you have two different variables that are to be plotted on the same graph. The <strong>hist()</strong> is a built-in function in R that takes a vector as input and creates a histogram.</p>
<p>To create a stacked histogram of two variables, we need to call the <strong>hist()</strong> function twice, as there are two variables. When you call the <strong>hist()</strong> function a second time, make sure to include the “add” argument. This argument plots the first and the second histogram on a single plot.</p>
<h4>Syntax</h4>
<pre class="brush: php; title: ; notranslate">hist(x, col=NULL,add=TRUE)</pre>
<h4>Arguments</h4>
<ul>
<li>x = It is the vector of data that you want to create the histogram from.</li>
<li>col = It is the color of the bars.</li>
<li>add = TRUE to merge the histograms.</li>
</ul>
<h3>Example</h3>
<p>In this example, we will create a stacked histogram from two different variables.</p>
<pre class="brush: php; title: ; notranslate"> #creating 1st variable
x = c(50,40,45,20,25)
#creating 2nd variable
y = c(15,5,40,10,45)
#creating histogram of x
hist(x,col = &quot;green&quot;)
#creating histogram of y and stacking x
hist(y,col = &quot;red&quot;,add=TRUE)</pre>
<h4>Output</h4>
<figure id="attachment_29475" aria-describedby="caption-attachment-29475" style="width: 426px" class="wp-caption aligncenter"><img decoding="async" class="size-full wp-image-29475" src="http://codingcampus.net/wp-content/uploads/2022/10/hist-stacked-hist.png" alt="hist - stacked hist" width="436" height="347" /><figcaption id="caption-attachment-29475" class="wp-caption-text">Two variables stacked on a single plot.</figcaption></figure>
<p>In the above example, we created a histogram of variable x and stacked it on top of the histogram of variable y.</p>
<h2>Using ggplot() Function to Create Stacked Histogram in R</h2>
<p>While the <strong>hist()</strong> function is used when you have two different variables, <strong>ggplot()</strong> is used when you have one variable with different categories. <strong>ggplot()</strong> is not a built-in function in R.</p>
<h4>Syntax of ggplot()</h4>
<pre class="brush: php; title: ; notranslate">ggplot(data=, aes(x=, fill=)) + geom_histogram()</pre>
<h4>Argument</h4>
<ul>
<li>data = It is the data frame you want to use to create the plot.</li>
<li>aes() = It is used to specify the variable to use on axes.</li>
<li>x = The variable to map on the x-axis.</li>
<li>fill = It defines the categorical variable based on which you want to color the histogram.</li>
<li>geom_histogram() = It specifies that you want to create a histogram.</li>
</ul>
<h3>Installing ggplot2</h3>
<p><strong>ggplot()</strong> comes from the ggplot2 package. To install and load the package, run the following code:</p>
<pre class="brush: php; title: ; notranslate"># install ggplot2 package
install.packages('ggplot2')
# load ggplot2 package
library('ggplot2')</pre>
<h3>Example</h3>
<p>To demonstrate how to use the <strong>ggplot()</strong> to create a stacked histogram, we will use the <strong>PlantGrowth</strong> data set. This data set is included with the base R installation. The data set contains information on the experiments to compare yields. It has two columns: weight and group.</p>
<p>In this example, we will plot the histogram of mpg column using the ggplot() function.</p>
<pre class="brush: php; title: ; notranslate">ggplot(data=PlantGrowth, aes(x=weight,fill=group)) + geom_histogram()</pre>
<h4>Output</h4>
<figure id="attachment_29474" aria-describedby="caption-attachment-29474" style="width: 426px" class="wp-caption aligncenter"><img decoding="async" class="size-full wp-image-29474" src="http://codingcampus.net/wp-content/uploads/2022/10/ggplot-stacked-hist.png" alt="ggplot - stacked hist" width="436" height="347" /><figcaption id="caption-attachment-29474" class="wp-caption-text">Stacked histogram using the ggplot() function.</figcaption></figure>
<p>In the above example, we created a plot containing stacked histograms. We specified the weight column to be plotted and then colored the histogram based on the column group.</p>
<p>The post <a href="https://codingcampus.net/how-to-create-stacked-histograms-in-r/">How to Create Stacked Histograms in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/how-to-create-stacked-histograms-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1326</post-id>	</item>
		<item>
		<title>Create an Empty Vector in R</title>
		<link>https://codingcampus.net/create-an-empty-vector-in-r/</link>
					<comments>https://codingcampus.net/create-an-empty-vector-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Kenneth Stenberg]]></dc:creator>
		<pubDate>Tue, 14 Mar 2023 13:09:00 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://codingcampus.net/?p=1321</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/create-an-empty-vector-in-r/">Create an Empty Vector in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A vector is a sequence of data elements of the same basic type. A vector whose <strong>length is zero</strong> is known as an <strong>empty vector</strong>. You can create an empty vector using the <strong>c()</strong>, <strong>vector()</strong>, <strong>rep()</strong>, and <strong>numeric()</strong> function. This guide shows different ways to create an empty vector in R.</p>
<h2>Method #1: Create an empty vector using the c() function</h2>
<p>The combine or <strong>c()</strong> function in R is used to create vectors by combining multiple values. To create an empty vector using the <strong>c()</strong> function, do not pass anything inside the parentheses.</p>
<h4>Syntax</h4>
<pre><code>vector name &lt;- c()</code></pre>
<p>Here, “vector name” can be any name you want to give to the empty vector.</p>
<h4>Example</h4>
<pre><code>x &lt;- c()
x</code></pre>
<h4>Output</h4>
<pre><code>NULL</code></pre>
<p>In the above example, the output is NULL which denotes that the vector is empty.</p>
<h2>Method #2: Create an empty vector using the vector() function</h2>
<p>To create an empty vector using the <strong>vector()</strong> function, do not pass anything inside the parentheses.</p>
<h4>Syntax</h4>
<pre><code>vector name &lt;- vector()</code></pre>
<p>Here, “vector name” can be any name you want to give to the empty vector.</p>
<h4>Example</h4>
<pre><code>v &lt;- vector()
v</code></pre>
<h4>Output</h4>
<pre><code>logical(0)</code></pre>
<p>In the above example, logical(0) denotes an empty vector.</p>
<h2>Method #3: Create an empty vector using a NULL object</h2>
<p>You can assign <strong>NULL</strong> to an existing or a new vector to create an empty vector.</p>
<h4>Example</h4>
<p>If you have a vector<strong> x = c(1, 2, 3)</strong>, you can convert it into an empty vector using the following code:</p>
<pre><code>x &lt;-c(1,2,3,5)
#converting to an empty vector
x &lt;- NULL
x</code></pre>
<h4>Output</h4>
<pre><code>NULL</code></pre>
<p>In the above example, we converted an existing non-empty vector to an empty vector by assigning the NULL object.</p>
<h2>Method #4: Create an empty vector using the rep() function</h2>
<p><strong>rep()</strong> function in R repeats the specified object a specified number of times. It is used to create a vector with a specified number of entries. To create an empty vector using the rep() function, do not pass anything inside the parentheses.</p>
<h4>Syntax</h4>
<pre><code>vector name &lt;- rep()</code></pre>
<p>Here, “vector name” can be any name you want to give to the empty vector.</p>
<h4>Example</h4>
<pre><code>y &lt;- rep()
y</code></pre>
<h4>Output</h4>
<pre><code>NULL</code></pre>
<h2>Method #5: Create an empty vector using the numeric() function</h2>
<p>The <strong>numeric()</strong> function creates a numeric vector of a defined length. To create an empty vector using the <strong>numeric()</strong> function, do not pass anything inside the parentheses.</p>
<h4>Syntax</h4>
<pre><code>vector name &lt;- numeric()</code></pre>
<p>Here, “vector name” can be any name you want to give to the empty vector.</p>
<h4>Example</h4>
<pre><code>a &lt;- numeric()
a</code></pre>
<h4>Output</h4>
<pre><code>numeric(0)</code></pre>
<p>The post <a href="https://codingcampus.net/create-an-empty-vector-in-r/">Create an Empty Vector in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/create-an-empty-vector-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1321</post-id>	</item>
		<item>
		<title>cos() Function in R</title>
		<link>https://codingcampus.net/cos-function-in-r/</link>
					<comments>https://codingcampus.net/cos-function-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Kenneth Stenberg]]></dc:creator>
		<pubDate>Mon, 13 Mar 2023 12:25:00 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://codingcampus.net/?p=1322</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/cos-function-in-r/">cos() Function in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>cos()</strong> function is a built-in function in R that calculates the cosine of a single number or a vector of numbers. This guide shows how to use the <strong>cos()</strong> function in R.</p>
<h2>Syntax</h2>
<pre><code>cos(x)</code></pre>
<h2>Argument</h2>
<ul>
<li><strong>x</strong> = It is the numeric vector you want to calculate the cosine of.</li>
</ul>
<p>Here are some examples of the cos() function in R:</p>
<h2>Example 1: Calculate the cosine of a number</h2>
<pre><code>#calculating the cosine value of a number
cos(0)
#calculating the cosine value of a number stored in a variable
x = 5
cos(x)</code></pre>
<h4>Output</h4>
<pre><code>[1] 1
[1] 0.2836622</code></pre>
<h2>Example 2: Calculate the cosine of a vector</h2>
<pre><code>#calculating the cosine value of a vector
x = (c(0,1, 2))
cos(x)</code></pre>
<h4>Output</h4>
<pre><code>[1] 1.0000000 0.5403023 -0.4161468</code></pre>
<p>The post <a href="https://codingcampus.net/cos-function-in-r/">cos() Function in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/cos-function-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1322</post-id>	</item>
		<item>
		<title>How to Calculate Square in R</title>
		<link>https://codingcampus.net/how-to-calculate-square-in-r/</link>
					<comments>https://codingcampus.net/how-to-calculate-square-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Kenneth Stenberg]]></dc:creator>
		<pubDate>Sat, 11 Mar 2023 21:49:00 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://codingcampus.net/?p=1320</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/how-to-calculate-square-in-r/">How to Calculate Square in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You can square a number, vector, matrix, and data frame in R. This guide will show you how to calculate the square of a single value, vector, matrix, and data frame in R.</p>
<h2>Calculate the Square of a Single Value in R</h2>
<p>There are 3 ways to calculate the square of a vector in R.</p>
<h3>Method #1: Using the ^ operator</h3>
<p>To calculate the square of a single value, use the <strong>^</strong> operator.</p>
<p>For example, to calculate the square of <strong>5</strong>, you would use the following code:</p>
<pre><code>5^2</code></pre>
<h4>Output</h4>
<pre><code>[1] 25</code></pre>
<h3>Method #2:  Using the * operator</h3>
<p>You can square a number using the multiplication operator, also known as an asterisk symbol (‘*’). To use it, take the number and multiply it by itself. For example, to take the square of 5, you can use the following formula:</p>
<pre><code>5*5</code></pre>
<h4>Output</h4>
<pre><code>[1] 25</code></pre>
<h3>Method #3: Using the ** operator</h3>
<p>You can also square a number using the double asterisk ** operator. So we type the number to square, then **, and end with 2. For example, to get the square of 5, use the following formula:</p>
<pre><code>5**2</code></pre>
<h4>Output</h4>
<pre><code>[1] 25</code></pre>
<h2>Calculate the Square of a Vector in R</h2>
<p>There are three ways to calculate the square of a vector in R.</p>
<h3>Method #1: Using the ^ operator</h3>
<p>To calculate the square of a vector, use the <strong>^</strong> operator.</p>
<p>For example, if you have a vector <strong>x = c(1,2,3)</strong>, you can calculate the square of each element in the vector using the following code:</p>
<pre><code>x = c(1,2,3)
x^2</code></pre>
<h4>Output</h4>
<pre><code>[1] 1 4 9</code></pre>
<h3>Method #2: Using the * operator</h3>
<p>Alternatively, you can use the <strong>*</strong> operator to square a vector.</p>
<h4>Syntax</h4>
<pre><code>vector * vector</code></pre>
<p>For example, if you have a vector <strong>x = c(1,2,3) </strong>you would use this code:</p>
<pre><code>x = c(1,2,3)
x*x</code></pre>
<h4>Output</h4>
<pre><code>[1] 1 4 9</code></pre>
<h3>Method #3: Using the ** operator</h3>
<p>Use the<strong> **</strong> operator to square a vector.</p>
<h4>Syntax</h4>
<pre><code>vector ** 2</code></pre>
<p>For example, if you have a vector <strong>x = c(1,2,3)</strong> you would use this code:</p>
<pre><code>x = c(1,2,3)
x**2</code></pre>
<h4>Output</h4>
<pre><code>[1] 1 4 9</code></pre>
<h2>Calculate the Square of a Matrix in R</h2>
<p>To calculate the square of a matrix in R, use the <strong>^</strong> operator with the matrix.</p>
<p>For example, if you have a matrix <strong>A = matrix(1:9, 3, 3)</strong> you can calculate the square of each element in the matrix using the following code:</p>
<pre><code>A = matrix(1:9, 3, 3)
A^2</code></pre>
<h4>Output</h4>
<pre><code>[1] 1 4 9 16 25 36 49 64 81</code></pre>
<h2>Calculate the Square of a Data Frame in R</h2>
<p>To calculate the square of a data frame in R, use the <strong>^</strong> operator with the data frame.</p>
<p>For example, if you have a data frame <strong>df</strong>, you can calculate the square of each element in the data frame using the following code:</p>
<pre><code>df = data.frame(x = c(1,2,3), y = c(4,5,6))
df^2</code></pre>
<h4>Output</h4>
<pre><code>  x y
1 1 16
2 4 25
3 9 36</code></pre>
<p>The post <a href="https://codingcampus.net/how-to-calculate-square-in-r/">How to Calculate Square in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/how-to-calculate-square-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1320</post-id>	</item>
		<item>
		<title>dim() in R</title>
		<link>https://codingcampus.net/dim-in-r/</link>
					<comments>https://codingcampus.net/dim-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Kenneth Stenberg]]></dc:creator>
		<pubDate>Fri, 10 Mar 2023 04:18:00 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://codingcampus.net/?p=1315</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/dim-in-r/">dim() in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><strong>dim()</strong> function is used to get the dimension of a matrix, array, data frame, or vector. It is a part of the base R package. This guide explains how to use the dim() in R.</p>
<h2>Syntax</h2>
<pre><code>dim(x)</code></pre>
<h2>Arguments</h2>
<ul>
<li><strong>x</strong> = a vector, matrix, array, or data frame</li>
</ul>
<h2>Using dim() to get the dimension of a Vector</h2>
<p>A vector is a one-dimensional data structure. To get the dimension of a vector, you need to specify the vector as an argument to the dim() function. It will always return <strong>NULL</strong>.</p>
<h4>Example</h4>
<pre><code>#creating a vector
x &lt;- 1:3
#printing vector
x
#getting the dimension of a vector
dim(x)</code></pre>
<h4>Output</h4>
<pre><code>[1] 1 2 3
NULL</code></pre>
<h2>Using dim() to get the dimension of a Matrix</h2>
<p>A matrix is a two-dimensional array. To get the dimension of a matrix, you need to specify the matrix as an argument to the dim() function. It will return a vector of <strong>two integers</strong> that indicate <strong>the number of rows and columns in the matrix</strong>.</p>
<h4>Example</h4>
<pre><code>#creating a matrix
y &lt;- matrix(1:9, nrow=3, ncol=3)
#printing matrix
y
#getting the dimension of a matrix
dim(y)</code></pre>
<h4>Output</h4>
<pre><code>[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9

[1] 3 3</code></pre>
<h2>Using dim() to get the dimension of an Array</h2>
<p>An array is a three-dimensional data structure. To get the dimension of an array, you need to specify the array as an argument to the dim() function. It will return a vector of <strong>three integers</strong> that indicate the <strong>size of the array</strong>.</p>
<h4>Example</h4>
<pre><code>#creating an array
a &lt;- array(1:8, c(2, 2, 2))
#printing array
a
#getting the dimension of the array
dim(a)</code></pre>
<h4>Output</h4>
<pre><code>, , 1
[,1] [,2]
[1,] 1 3
[2,] 2 4

, , 2
[,1] [,2]
[1,] 5 7
[2,] 6 8

[1] 2 2 2</code></pre>
<h2>Using dim() to get the dimension of a Data Frame</h2>
<p>A data frame is a two-dimensional data structure. To get the dimension of a data frame, you need to specify the data frame as an argument to the dim() function. It will return a vector of <strong>two integers</strong> that indicate <strong>the number of rows and columns in the data frame</strong>.</p>
<h4>Example</h4>
<pre><code>#creating a data frame
df &lt;- data.frame(x=1:3, y=4:6)
#printing data frame
df
#getting the dimension of the data frame
dim(df)</code></pre>
<h4>Output</h4>
<pre><code>x y
1 1 4
2 2 5
3 3 6

[1] 3 2</code></pre>
<p>Here, 3 indicates the number of rows in the data frame, and 2 indicates the number of columns.</p>
<p>The post <a href="https://codingcampus.net/dim-in-r/">dim() in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/dim-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1315</post-id>	</item>
		<item>
		<title>How to Find a File in Linux</title>
		<link>https://codingcampus.net/how-to-find-a-file-in-linux/</link>
					<comments>https://codingcampus.net/how-to-find-a-file-in-linux/#respond</comments>
		
		<dc:creator><![CDATA[codingxcampus013]]></dc:creator>
		<pubDate>Thu, 09 Mar 2023 19:47:00 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<guid isPermaLink="false">https://codingcampus.net/how-to-find-a-file-in-linux/</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/how-to-find-a-file-in-linux/">How to Find a File in Linux</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Do you ever no longer remember where exactly you put a file on your Linux computer or server? You&#8217;re confident that it <em>was</em> saved somewhere but can&#8217;t find exactly where. For Windows users, the obvious solution is to use Explorer&#8217;s &#8216;Find&#8217; function. But what if you&#8217;re unsure about how to find a file in Linux?</p>
<p>We&#8217;ve compiled a list of methods you can use to locate missing files in Linux. As always, we include tools for both more experienced users and beginners, and we hope that these suggestions allow you to avoid the traumatic loss of important data!</p>
<h2>Using the grep command to find a file by its contents</h2>
<p>Grep has been part of Unix for so long that you will often see the term used as a verb in Linux discussions online (it&#8217;s generally synonymous with &#8220;search locally&#8221;). It can be thought of as the ultimate &#8220;pattern recognition tool&#8221;. However, Grep should only be used to search for the contents of a file rather than finding items using their filename.</p>
<p>Now, let&#8217;s look at how grep is actually used. Let&#8217;s say you had a file in your ~/Documents directory called &#8216;Give.txt&#8217;. The contents of the file are as follows:</p>
<pre><code>What's real can't die
You only get what you give
You're gonna get what you give
Don't give up
Just don't be afraid to leave</code></pre>
<p>Of course, these are the lyrics to a <a href="https://www.youtube.com/watch?v=cPAEFnVZVOs&amp;ab_channel=wares_for_coin">famous song by New Radicals</a>. It&#8217;s an excellent example in this case, as it highlights how useful grep is and a few of its behaviors that might appear idiosyncratic at first to new users.</p>
<p>From our Documents directory, we&#8217;re going to execute the following command:<code></code></p>
<pre><code>grep you give.txt</code></pre>
<p>Press return, and you&#8217;ll see that it returns every line with the word &#8220;you&#8221; in it:</p>
<figure id="attachment_3951" aria-describedby="caption-attachment-3951" style="width: 726px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-grep-lowercase-you-e1645361092348.png"><img loading="lazy" decoding="async" class="wp-image-3951 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-grep-lowercase-you-e1645361092348.png" alt="Finding files using Grep. Query is &quot;you&quot; in lower case." width="736" height="483" /></a><figcaption id="caption-attachment-3951" class="wp-caption-text">Looking for instances of the term &#8220;you&#8221; in give.txt</figcaption></figure>
<p>Now, let&#8217;s try another command (remember to include the escaped apostrophe):</p>
<pre><code>grep don't give.txt</code></pre>
<p>And here is our result:</p>
<figure id="attachment_3954" aria-describedby="caption-attachment-3954" style="width: 726px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-grep-lowercase-dont.png"><img loading="lazy" decoding="async" class="wp-image-3954 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-grep-lowercase-dont.png" alt="Finding files using grep. Query is &quot;don't&quot; in lower case." width="736" height="483" /></a><figcaption id="caption-attachment-3954" class="wp-caption-text">Looking for instances of the word &#8220;don&#8217;t&#8221; in &#8216;give.txt&#8217;</figcaption></figure>
<p>As you can see, the fifth line was identified; however, because grep is case-sensitive by default, the fourth line (&#8220;Don&#8217;t give up&#8221;) was not returned.</p>
<p>Now, we&#8217;ll use the &#8220;-i&#8221; flag to turn off case-sensitivity in our following query (I&#8217;ve also now used quotations to avoid relying on the backslash character this time):</p>
<pre><code>grep -i "don't" give.txt</code></pre>
<figure id="attachment_3956" aria-describedby="caption-attachment-3956" style="width: 717px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-grep-anycase-dont.png"><img loading="lazy" decoding="async" class="wp-image-3956 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-grep-anycase-dont.png" alt="Finding files in Grep. Query is &quot;don't&quot;, with case sensitivity turned off." width="727" height="339" /></a><figcaption id="caption-attachment-3956" class="wp-caption-text">The &#8216;-i&#8217; flag will allow us to turn off case sensitivity.</figcaption></figure>
<p>This time, we can see that every instance of the word &#8211; regardless of case &#8211; is brought back. If you use the &#8220;-i&#8221; flag when searching for &#8220;you&#8221;, you&#8217;ll also notice that it now highlights the capitalized appearances of the word as well:</p>
<figure id="attachment_3970" aria-describedby="caption-attachment-3970" style="width: 753px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-grep-anycase-you.png"><img loading="lazy" decoding="async" class="wp-image-3970 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-grep-anycase-you.png" alt="Using Grep to find instances of the word &quot;you&quot; in any case" width="763" height="249" /></a><figcaption id="caption-attachment-3970" class="wp-caption-text">Using Grep to find instances of the term &#8220;you&#8221; in any case</figcaption></figure>
<h2>Using the find command to find a file by its name</h2>
<p>While grep allows users to query the contents of files on their computer, the find tool provides an efficient way to locate items based on their actual filename.</p>
<p>The most basic use of the find command is as follows:</p>
<pre><code>find .</code></pre>
<p>The period (&#8216;.&#8217;) tells the command to return every file and subdirectory found if we search from the present working directory. Essentially, all this is is a good starting point.</p>
<figure id="attachment_3959" aria-describedby="caption-attachment-3959" style="width: 717px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-period.png"><img loading="lazy" decoding="async" class="wp-image-3959 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-period.png" alt="Finding all files of any type within the present working directory and its subdirectories" width="727" height="339" /></a><figcaption id="caption-attachment-3959" class="wp-caption-text">Finding all files within the present working directory and its subdirectories</figcaption></figure>
<p>However, there are a variety of additional arguments which allow us to get a lot more specific with how we use the find tool. For example, the following command will return all subdirectories from the present location (with &#8216;d&#8217; standing for &#8220;directories&#8221;):</p>
<pre><code>find . -type d</code></pre>
<figure id="attachment_3960" aria-describedby="caption-attachment-3960" style="width: 753px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-type-d.png"><img loading="lazy" decoding="async" class="wp-image-3960 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-type-d.png" alt="Finding all files with type 'directory' (i.e. only folders)" width="763" height="285" /></a><figcaption id="caption-attachment-3960" class="wp-caption-text">Finding all files with type &#8216;directory&#8217; (i.e., only folders)</figcaption></figure>
<p>Alternatively, we can return only files by typing:</p>
<pre><code>find . -type f</code></pre>
<figure id="attachment_3963" aria-describedby="caption-attachment-3963" style="width: 753px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-type-f.png"><img loading="lazy" decoding="async" class="wp-image-3963 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-type-f.png" alt="Finding files which are not subdirectories (i.e. single files only)" width="763" height="195" /></a><figcaption id="caption-attachment-3963" class="wp-caption-text">Finding files that are not subdirectories (i.e., single files only)</figcaption></figure>
<p>The find command becomes especially useful for locating misplaced files when switching out the &#8220;-type&#8221; option with &#8220;-name&#8221;. For example, we can return all ePub files (either in the current directory or within its subdirectories) by using:</p>
<pre><code>find . -name "*.epub"</code></pre>
<figure id="attachment_3973" aria-describedby="caption-attachment-3973" style="width: 753px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-ext-epub.png"><img loading="lazy" decoding="async" class="wp-image-3973 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-ext-epub.png" alt="Using the find command to locate files with the .ePub extension" width="763" height="249" /></a><figcaption id="caption-attachment-3973" class="wp-caption-text">Using the find command to locate files with the .ePub extension</figcaption></figure>
<p>Or, we can find all ePub files with the word &#8220;great&#8221; in the name by typing:</p>
<pre><code>find . -name "*great*epub"</code></pre>
<figure id="attachment_3974" aria-describedby="caption-attachment-3974" style="width: 753px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-great-epub-lowercase.png"><img loading="lazy" decoding="async" class="wp-image-3974 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-find-great-epub-lowercase.png" alt="Using the find tool to locate the lowercase word &quot;great&quot; in filenames with a .epub extension" width="763" height="249" /></a><figcaption id="caption-attachment-3974" class="wp-caption-text">Using the find tool to locate the lowercase word &#8220;great&#8221; in filenames with a .epub extension</figcaption></figure>
<p>And, as with the grep tool, we can choose to make our query case-insensitive:</p>
<pre><code>find . -iname "*great*epub"</code></pre>
<figure id="attachment_3975" aria-describedby="caption-attachment-3975" style="width: 753px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-great-epub-anycase.png"><img loading="lazy" decoding="async" class="wp-image-3975 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-great-epub-anycase.png" alt="Using find to locate ePub files with the word &quot;great&quot; (in any case) in their title" width="763" height="249" /></a><figcaption id="caption-attachment-3975" class="wp-caption-text">Using find to locate ePub files with the word &#8220;great&#8221; (in any case) in their title</figcaption></figure>
<p>And, if we want to narrow it down even further, we can combine options too:</p>
<pre><code>find . -type f -iname "*GrEat*"</code></pre>
<figure id="attachment_3976" aria-describedby="caption-attachment-3976" style="width: 753px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-combining-options.png"><img loading="lazy" decoding="async" class="wp-image-3976 size-full" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-combining-options.png" alt="Combining the options provided by the find tool" width="763" height="249" /></a><figcaption id="caption-attachment-3976" class="wp-caption-text">Combining the options provided by the find tool</figcaption></figure>
<p>The above example is slightly redundant, as we only have files with the word &#8216;great&#8217; in their title. However, if the ~/Downloads folder also had a subdirectory called &#8220;Great Expectations&#8221;, it would be omitted from our results as we have specifically included the &#8216;-type f&#8217; option.</p>
<h2>Find files using Catfish</h2>
<p>For those who prefer not to use the command line, you can use a GTK3 application called Catfish. This can be installed from the software repository of your Linux distribution by typing:</p>
<pre><code>sudo apt-get install catfish -y</code></pre>
<p>Other popular choices for Linux users who prefer to use GUI to locate files include fsearch, Cerebro, and Terrier.</p>
<p><a href="http://codingcampus.net/wp-content/uploads/2022/02/find-files-catfish-epub.png"><img loading="lazy" decoding="async" class="wp-image-3965 size-full aligncenter" src="http://codingcampus.net/wp-content/uploads/2022/02/find-files-catfish-epub.png" alt="Finding all ePub files using Catfish" width="650" height="517" /></a></p>
<p>Catfish can provide complex searches (based on criteria like date of modification, file type, and so on). While it&#8217;s not quite as powerful as grep or find, it should suit most users fine.</p>
<p>The post <a href="https://codingcampus.net/how-to-find-a-file-in-linux/">How to Find a File in Linux</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/how-to-find-a-file-in-linux/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1595</post-id>	</item>
		<item>
		<title>How to Check CentOS Version</title>
		<link>https://codingcampus.net/how-to-check-centos-version/</link>
					<comments>https://codingcampus.net/how-to-check-centos-version/#respond</comments>
		
		<dc:creator><![CDATA[codingxcampus013]]></dc:creator>
		<pubDate>Thu, 09 Mar 2023 16:22:00 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<guid isPermaLink="false">https://codingcampus.net/how-to-check-centos-version/</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/how-to-check-centos-version/">How to Check CentOS Version</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Though there is certainly reason to be sad about CentOS&#8217; discontinuation, the good news is that the midstream version will receive long-term support up until at least June 2024. So, for any of you who would still like to continue using the RHEL-derived OS, you&#8217;re more than welcome to. In this guide, we&#8217;ll show you how to check the CentOS version running on your machine. I&#8217;ll be checking using CentOS 8 (8.4.2105).</p>
<h2>Check CentOS Using RPM (Easiest)</h2>
<p>The RPM Package Manager provides the quickest and easiest way to find out which version of CentOS is running.</p>
<ol>
<li>From the home screen, click &#8216;Activities&#8217; in the top left-hand corner.
<p><figure id="attachment_2124" aria-describedby="caption-attachment-2124" style="width: 872px" class="wp-caption alignnone"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen1.png"><img loading="lazy" decoding="async" class="wp-image-2124 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen1.png" alt="CentOS Article Screen 1" width="882" height="665" /></a><figcaption id="caption-attachment-2124" class="wp-caption-text">Click &#8216;activities&#8217; to bring up the search box</figcaption></figure></li>
<li>Then, type &#8216;terminal&#8217; into the search box which appears. Now, click the terminal button.
<p><figure id="attachment_2125" aria-describedby="caption-attachment-2125" style="width: 873px" class="wp-caption alignnone"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen2.png"><img loading="lazy" decoding="async" class="wp-image-2125 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen2.png" alt="CentOS Article Screen 2" width="883" height="665" /></a><figcaption id="caption-attachment-2125" class="wp-caption-text">Search for &#8216;terminal&#8217;</figcaption></figure></li>
<li>In the terminal window, enter the following command:</li>
</ol>
<pre><code>rpm -q centos-linux-release</code></pre>
<p>Then hit enter.</p>
<figure id="attachment_2126" aria-describedby="caption-attachment-2126" style="width: 872px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen3.png"><img loading="lazy" decoding="async" class="wp-image-2126 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen3.png" alt="CentOS Article Screen 3" width="882" height="666" /></a><figcaption id="caption-attachment-2126" class="wp-caption-text">The rpm command should let you see exactly which version of CentOS is installed</figcaption></figure>
<p>As you can see, the exact version of CentOS (including the major release number, as well as the revision).</p>
<h2>Check CentOS Version Using Your Release File</h2>
<p>You might not know this, but there&#8217;s actually a text file included in your CentOS installation. It&#8217;s located in the &#8216;/etc/&#8217; directory, and it&#8217;s very handy for checking your release version.</p>
<ol>
<li>From the home screen, click &#8216;Activities&#8217; in the top left-hand corner.
<p><figure id="attachment_2124-2" aria-describedby="caption-attachment-2124-2" style="width: 872px" class="wp-caption alignnone"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen1.png"><img loading="lazy" decoding="async" class="wp-image-2124 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen1.png" alt="CentOS Article Screen 1" width="882" height="665" /></a><figcaption id="caption-attachment-2124-2" class="wp-caption-text">Click &#8216;activities&#8217; to bring up the search box</figcaption></figure></li>
<li>Now, click the Terminal icon which appears on the left-hand sidebar.
<p><figure id="attachment_2127" aria-describedby="caption-attachment-2127" style="width: 874px" class="wp-caption alignnone"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen4.png"><img loading="lazy" decoding="async" class="wp-image-2127 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen4.png" alt="CentOS Article Screen 4" width="884" height="668" /></a><figcaption id="caption-attachment-2127" class="wp-caption-text">This time, we&#8217;re using the Terminal icon (circled in red here)</figcaption></figure></li>
<li>In the window which opens, enter the following command:</li>
</ol>
<pre><code>cat /etc/centos-release</code></pre>
<p>Then hit enter.</p>
<figure id="attachment_2128" aria-describedby="caption-attachment-2128" style="width: 873px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen5.png"><img loading="lazy" decoding="async" class="wp-image-2128 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen5.png" alt="CentOS Article Screen 5" width="883" height="663" /></a><figcaption id="caption-attachment-2128" class="wp-caption-text">The &#8216;cat&#8217; command provides another easy way to view our current version of CentOS</figcaption></figure>
<p>There&#8217;s also a way to find out more details about your release, by using the following command instead:</p>
<pre><code>cat /etc/os-release</code></pre>
<p>And hit enter.</p>
<figure id="attachment_2129" aria-describedby="caption-attachment-2129" style="width: 875px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen6.png"><img loading="lazy" decoding="async" class="wp-image-2129 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen6.png" alt="CentOS Article Screen 6" width="885" height="665" /></a><figcaption id="caption-attachment-2129" class="wp-caption-text">Using the &#8216;os-release&#8217; file provides more information about our current installation</figcaption></figure>
<p>As you can see, this command doesn&#8217;t provide your exact release number, but it does provide other useful information such as the &#8216;Platform_ID&#8217; and the &#8216;Pretty Name&#8217;.</p>
<h2>Check the &#8216;Pretty Name&#8217; Using the GUI</h2>
<p>If you&#8217;re also content just to know which major release of CentOS you&#8217;re using, you can do this using the graphical interface. This method might also be useful if &#8211; for whatever reason &#8211; you can&#8217;t use the terminal.</p>
<ol>
<li>Again, click &#8216;activities&#8217; in the top left-hand corner.
<p><figure id="attachment_2124-3" aria-describedby="caption-attachment-2124-3" style="width: 872px" class="wp-caption alignnone"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen1.png"><img loading="lazy" decoding="async" class="wp-image-2124 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen1.png" alt="CentOS Article Screen 1" width="882" height="665" /></a><figcaption id="caption-attachment-2124-3" class="wp-caption-text">Click &#8216;activities&#8217; to bring up the search</figcaption></figure></li>
<li>Then, type &#8216;version&#8217; into the search box which appears.
<p><figure id="attachment_2130" aria-describedby="caption-attachment-2130" style="width: 875px" class="wp-caption alignnone"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen7.png"><img loading="lazy" decoding="async" class="wp-image-2130 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen7.png" alt="CentOS Article Screen 7" width="885" height="666" /></a><figcaption id="caption-attachment-2130" class="wp-caption-text">Typing &#8216;version&#8217; should bring up the &#8216;About&#8217; app</figcaption></figure></li>
<li>You can now see the release of CentOS you&#8217;re currently running. Although less detailed, this method only requires using the GUI.</li>
</ol>
<figure id="attachment_2131" aria-describedby="caption-attachment-2131" style="width: 877px" class="wp-caption aligncenter"><a href="http://codingcampus.net/wp-content/uploads/2022/01/Screen8.png"><img loading="lazy" decoding="async" class="wp-image-2131 size-full" src="http://codingcampus.net/wp-content/uploads/2022/01/Screen8.png" alt="CentOS Article Screen 8" width="887" height="666" /></a><figcaption id="caption-attachment-2131" class="wp-caption-text">Find your CentOS version in the GUI</figcaption></figure>
<p><strong>Bonus Tip:</strong> You can click the &#8216;View Updates&#8217; button in the bottom right-hand area of the above screenshot to begin updating your current installation (if needed).</p>
<p>The post <a href="https://codingcampus.net/how-to-check-centos-version/">How to Check CentOS Version</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/how-to-check-centos-version/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1580</post-id>	</item>
		<item>
		<title>sample() Function in R</title>
		<link>https://codingcampus.net/sample-function-in-r/</link>
					<comments>https://codingcampus.net/sample-function-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Kenneth Stenberg]]></dc:creator>
		<pubDate>Thu, 09 Mar 2023 10:53:00 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://codingcampus.net/?p=1310</guid>

					<description><![CDATA[<p>The post <a href="https://codingcampus.net/sample-function-in-r/">sample() Function in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>The <strong>sample()</strong> function allows you to select a <strong>random set of data points from a vector</strong>. This enables you to perform statistical analysis on a <strong>sample</strong> of a data set without having to input all the data manually. This guide explains how to use the <strong>sample()</strong> function in R.</p>
<h4>Syntax</h4>
<pre><code>sample(x, size, replace, probability)</code></pre>
<h4>Arguments</h4>
<ul>
<li><strong>x</strong> = a vector of data points from which you want to select a random sample.</li>
<li><strong>size</strong> = the number of data points you want to select.</li>
<li><strong>replace</strong> = can be <strong>TRUE</strong> or <strong>FALSE</strong>. If TRUE, the values can be repeated in the sample. By default, it is set to FALSE.</li>
<li><strong>prob</strong> = a vector of probability weights.</li>
</ul>
<p>Now that we&#8217;ve gone over the basics of the function, let&#8217;s look at some examples of how to use it.</p>
<h3>Example 1: Creating a sample without replacement</h3>
<p>We can use the sample() function to select a random sample of data points <strong>without replacement</strong>. This means that once a data point is selected, it will not be selected again. Let&#8217;s say we have a vector x that contains 100 data points. To select a random sample of 10 data points from this vector, we use the following code:</p>
<pre><code>#creating a vector of 100 values
x = c(1:100)
#generating a sample of 10 values
sample(x, size = 10)</code></pre>
<h4>Output</h4>
<pre><code>[1] 10 62 56 97 64 9 26 87 52 41</code></pre>
<p>In this example, the function returned a vector containing ten randomly selected data points from x, where no data point was selected more than once. Also, note that values are not repeated because, by default, the replace argument is set to be <strong>FALSE</strong>.</p>
<h3>Example 2: Creating a sample with replacement</h3>
<p>Let&#8217;s take the same example used in Example 1. We can use the sample() function to select a random sample of 10 data points from this vector <strong>with replacement of the values</strong> using the following code:</p>
<pre><code>#creating a vector of 100 values
x = c(1:100)
#generating a sample of 10 values
sample(x, size = 10, replace=TRUE)</code></pre>
<h4>Output</h4>
<pre><code>[1] 28 34 32 68 67 91 88 2 14 88</code></pre>
<p>In this example, the function returned a vector containing ten randomly selected data points from x. Also, note that values may be repeated because we have set the replace argument as <strong>TRUE</strong>. In this example, 88 got repeated twice.</p>
<h3>Example 3: Creating a sample with uneven probabilities</h3>
<p>In the following example, we will define each element&#8217;s probabilities in the data set. Kindly note that the probability value should be between 0 to 1.</p>
<pre><code>#creating a vector of 5 values
x = c(25,50,75,100,125)
#generating a sample of 3 values
sample(x, size = 3, replace=TRUE, prob = c(0.7,0.3,0.8,0.6,0.7))</code></pre>
<h4>Output</h4>
<pre><code>[1] 75 25 25</code></pre>
<p>In the above example, we have defined the probability weights of each element using the prob argument. Notice that the value 75 has the highest probability of 0.8 and thus was represented in the sample output.</p>
<h3>Example 4: Reordering the elements inside a vector</h3>
<p>If you use the sample() function without defining the size, the function will return the same data set but with reordering it in ascending order.</p>
<pre><code>#creating a vector of 5 values
x = c(25,50,75,100,125)
#reordering the data
sample(x)</code></pre>
<h4>Output</h4>
<pre><code>[1] 25 50 100 125 75</code></pre>
<p>The post <a href="https://codingcampus.net/sample-function-in-r/">sample() Function in R</a> appeared first on <a href="https://codingcampus.net">Coding Campus</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingcampus.net/sample-function-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1310</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Page Caching using Disk: Enhanced 

Served from: codingcampus.net @ 2026-10-02 20:08:13 by W3 Total Cache
-->