<?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>Universe of Data Science</title>
	<atom:link href="https://universeofdatascience.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://universeofdatascience.com</link>
	<description>For Future</description>
	<lastBuildDate>Mon, 17 Nov 2025 14:39:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.5</generator>

<image>
	<url>https://universeofdatascience.com/wp-content/uploads/2022/12/cropped-logo-32x32.png</url>
	<title>Universe of Data Science</title>
	<link>https://universeofdatascience.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Binary Classification via dce-GMDH Algorithm in R</title>
		<link>https://universeofdatascience.com/binary-classification-via-dce-gmdh-algorithm-in-r/</link>
					<comments>https://universeofdatascience.com/binary-classification-via-dce-gmdh-algorithm-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 12 Mar 2023 12:19:28 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<category><![CDATA[classification using r]]></category>
		<category><![CDATA[dce-GMDH]]></category>
		<category><![CDATA[gmdh]]></category>
		<category><![CDATA[gmdh algorithm]]></category>
		<category><![CDATA[GMDH neural network]]></category>
		<category><![CDATA[GMDH software]]></category>
		<category><![CDATA[GMDH2 package]]></category>
		<category><![CDATA[neural network in r classification]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1652</guid>

					<description><![CDATA[The dce-GMDH type neural network algorithm is a heuristic self-organizing algorithm to assemble the well-known classifiers. Find out how to apply dce-GMDH algorithm for binary classification in R. In this tutorial, we will work dce-GMDH type neural network approach for binary classification. Before we start, we need to divide data into three parts; train, validation [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>The dce-GMDH type neural network algorithm is a heuristic self-organizing algorithm to assemble the well-known classifiers. Find out how to apply dce-GMDH algorithm for binary classification in R.</p>



<span id="more-1652"></span>


<div class="wp-block-image is-style-default">
<figure class="aligncenter size-large"><img fetchpriority="high" decoding="async" width="1024" height="845" src="https://universeofdatascience.com/wp-content/uploads/2023/03/dceGMDH-1024x845.jpg" alt="" class="wp-image-1654" srcset="https://universeofdatascience.com/wp-content/uploads/2023/03/dceGMDH-1024x845.jpg 1024w, https://universeofdatascience.com/wp-content/uploads/2023/03/dceGMDH-300x247.jpg 300w, https://universeofdatascience.com/wp-content/uploads/2023/03/dceGMDH-768x633.jpg 768w, https://universeofdatascience.com/wp-content/uploads/2023/03/dceGMDH-676x558.jpg 676w, https://universeofdatascience.com/wp-content/uploads/2023/03/dceGMDH.jpg 1027w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">Architecture of dce-GMDH Algorithm (Dag et al., 2022)</figcaption></figure></div>


<p>In this tutorial, we will work dce-GMDH type neural network approach for binary classification. Before we start, we need to divide data into three parts; train, validation and test sets. We use train set for model building. We utilize validation set for neuron selection. Last, we show the performance of the model on test set.</p>



<p><strong><strong>Check Out:</strong></strong>&nbsp;<a href="https://universeofdatascience.com/shapiro-wilk-test-for-univariate-and-multivariate-normality-in-r/"></a><a href="https://universeofdatascience.com/feature-selection-and-classification-via-gmdh-algorithm-in-r/"><em>Feature Selection and Classification via GMDH Algorithm in R</em></a></p>



<p>In this tutorial, we will implement the algorithm on urine dataset, also used in the work done by Dag et al. (2022), available in <a href="https://cran.r-project.org/web/packages/mlbench/index.html">boot</a> package (Canty and Ripley, 2020). Before we go ahead, we load dataset and start to process the data.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data(urine, package =  &quot;boot&quot;)
</pre></div>


<p>After loading dataset, let&#8217;s exclude missing values to work on the complete dataset.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data &lt;- na.exclude(urine)
head(data)
##   r gravity   ph osmo cond urea calc
## 2 0   1.017 5.74  577 20.0  296 4.49
## 3 0   1.008 7.20  321 14.9  101 2.36
## 4 0   1.011 5.51  408 12.6  224 2.15
## 5 0   1.005 6.52  187  7.5   91 1.16
## 6 0   1.020 5.27  668 25.3  252 3.34
## 7 0   1.012 5.62  461 17.4  195 1.40
</pre></div>


<p><strong>Also Check:</strong>&nbsp;<a href="https://universeofdatascience.com/how-to-handle-missing-values-in-r/"><em>How to Handle Missing Values in R</em></a></p>



<p>We need to define the output variable as factor and input variables as matrix.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
x &lt;- data.matrix(data&#x5B;,2:7])
y &lt;- as.factor(data&#x5B;,1])
</pre></div>


<p>We need to divide data into three sets; train (60%), validation (20%) and test (20%) sets. Then, we obtain the number of observations in each fold.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
nobs &lt;- dim(data)&#x5B;1]
ntrain &lt;- round(nobs*0.6,0)
nvalid &lt;- round(nobs*0.2,0)
ntest &lt;- nobs-(ntrain+nvalid)
</pre></div>


<p>Now let&#8217;s obtain the indices of train, validation and test sets. Before we obtain the indices, we shuffle the indices to prevent any bias based on order. For reproducibility of results, let&#8217;s fix the seed number to 1234.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
set.seed(1234)
indices &lt;- sample(1:nobs)

train.indices &lt;- sort(indices&#x5B;1:ntrain])
valid.indices &lt;- sort(indices&#x5B;(ntrain+1):(ntrain+nvalid)])
test.indices &lt;- sort(indices&#x5B;(ntrain+nvalid+1):nobs])
</pre></div>


<p>We can construct train, validatation and test sets. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
x.train &lt;- x&#x5B;train.indices,]
y.train &lt;- y&#x5B;train.indices]
x.valid &lt;- x&#x5B;valid.indices,]
y.valid &lt;- y&#x5B;valid.indices]
x.test &lt;- x&#x5B;test.indices,]
y.test &lt;- y&#x5B;test.indices]
</pre></div>


<p>After obtaining train, validation and test sets, we can use dce-GMDH type neural network algorithm. dce-GMDH algorithm is available in <a href="https://CRAN.R-project.org/package=GMDH2">GMDH2</a> package (Dag et al., 2019).</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
library(GMDH2)
model &lt;- dceGMDH(x.train, y.train, x.valid, y.valid, alpha = 0.6, maxlayers = 10, maxneurons = 15, exCriterion =&quot;MSE&quot;, verbose = TRUE)

##  Structure : 
## 
##  Layer     Neurons     Selected neurons               Min MSE
##      0           5                    5     0.141036573711885
##      1          10                    1     0.139424256676092
## 
##  External criterion   : Mean Square Error 
## 
##  Classifiers ensemble : 2 out of 5 classifiers are assembled. 
##            
##  naiveBayes
##   cv.glmnet
</pre></div>


<p><strong>Also Check:</strong>&nbsp;<a href="https://universeofdatascience.com/how-to-handle-missing-values-in-r/"></a><em><a href="https://universeofdatascience.com/how-to-clean-data-in-r/">How to Clean Data in R</a></em></p>



<p>Now, let&#8217;s obtain performance measures on test set.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
y.test_pred &lt;- predict(model, x.test, type = &quot;class&quot;)
confMat(y.test_pred, y.test, positive = &quot;1&quot;)

## Confusion Matrix and Statistics 
## 
##     reference
## data 1 0
##    1 4 2
##    0 2 8
## 
## 
##      Accuracy             :   0.75
##      No Information Rate  :   0.625
##      Kappa                :   0.4667
##      Matthews Corr Coef   :   0.4667
##      Sensitivity          :   0.6667
##      Specificity          :   0.8
##      Positive Pred Value  :   0.6667
##      Negative Pred Value  :   0.8
##      Prevalence           :   0.375
##      Balanced Accuracy    :   0.7333
##      Youden Index         :   0.4667
##      Detection Rate       :   0.25
##      Detection Prevalence :   0.375
##      Precision            :   0.6667
##      Recall               :   0.6667
##      F1                   :   0.6667 
## 
##      Positive Class       :   1
</pre></div>


<p>In this model, dce-GMDH algorithm assembles the classification algorithms, naive bayes and elastic net logistic regression, contributing the classification performance. This ensemble algorithm classified 75.0% of individuals in a correct class. Also, sensitivity and specificity are calculated as 0.6667 and 0.8, respectively.</p>



<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe title="Binary Classification via dce-GMDH Algorithm in R" width="676" height="380" src="https://www.youtube.com/embed/VxBvNI1y3hg?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">Binary Classification via dce-GMDH Algorithm in R</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong>&nbsp;<a href="https://universeofdatascience.com/how-to-categorize-numeric-variables-in-r/"><em></em></a><em><a href="https://universeofdatascience.com/6-ways-of-subsetting-data-in-r/">6 Ways of Subsetting Data in R</a></em></p>



<p><strong>References </strong></p>



<p>Dag, O., Karabulut, E., Alpar, R. (2019). GMDH2: Binary Classification via GMDH-Type Neural Network Algorithms &#8211; R Package and Web-Based Tool. International Journal of Computational Intelligence Systems, 12:2, 649-660.</p>



<p>Dag, O., Kasikci, M., Karabulut, E., Alpar, R. (2022). Diverse Classifiers Ensemble Based on GMDH-Type Neural Network Algorithm for Binary Classification. Communications in Statistics &#8211; Simulation and Computation, 51:5, 2440-2456.</p>



<p>Canty, A., Ripley, B. (2020). boot: Bootstrap R (S-Plus) Functions. R package version 1.3-25.</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="(max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/binary-classification-via-dce-gmdh-algorithm-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Create Dummy Variables Based on Variable Class in R Data Frame</title>
		<link>https://universeofdatascience.com/how-to-create-dummy-variables-based-on-variable-class-in-r-data-frame/</link>
					<comments>https://universeofdatascience.com/how-to-create-dummy-variables-based-on-variable-class-in-r-data-frame/#comments</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sat, 04 Mar 2023 21:31:43 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1566</guid>

					<description><![CDATA[Creating dummy variables is a point not to be missed while working on nominal variables. This comphrehensive tutorial includes necessary steps to make dummy variables based on variables class in R data frame. In this tutorial, we learn the usage of dummy.data.frame() function available in&#160;dummies&#160;package (Brown, 2012). Firstly, we learn how to create dummy variables [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Creating dummy variables is a point not to be missed while working on nominal variables. This comphrehensive tutorial includes necessary steps to make dummy variables based on variables class in R data frame.</p>



<span id="more-1566"></span>



<p>In this tutorial, we learn the usage of dummy.data.frame() function available in&nbsp;<a href="https://CRAN.R-project.org/package=dummies">dummies</a>&nbsp;package (Brown, 2012). Firstly, we learn how to create dummy variables for categorical variables . Secondly, we go over how to create dummy variables for specified class. At last, we learn how to create dummy variables for all variables in R data frame.</p>



<p>In this tutorial, we do not discuss that k-1 dummy variables are used if we have k levels of a categorical variable. You can read it <a href="https://universeofdatascience.com/how-to-convert-categorical-variables-into-dummy-variables-in-r/">here</a>.</p>



<p>Let’s construct a data frame involving the variables involving four different variable types in R.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
w &lt;- factor(rep(c(&quot;apple&quot;,&quot;banana&quot;,&quot;carrot&quot;), each = 2))
x &lt;- rep(c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;), 2)
y &lt;- rep(1:3, 2)
z &lt;- rep(c(0.4,0.8), 3)
data &lt;- data.frame(w, x, y, z)

data
##        w x y   z
## 1  apple A 1 0.4
## 2  apple B 2 0.8
## 3 banana C 3 0.4
## 4 banana A 1 0.8
## 5 carrot B 2 0.4
## 6 carrot C 3 0.8

sapply(data, class) 
##           w           x           y           z 
##    &quot;factor&quot; &quot;character&quot;   &quot;integer&quot;   &quot;numeric&quot; 
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-convert-categorical-variables-into-dummy-variables-in-r/"><em>How to Convert Categorical Variables into Dummy Variables in R</em></a></p>



<h2 class="wp-block-heading">1) How to Create Dummy Variables for Categorical Variables </h2>



<p>In this part, we use dummy.data.frame() function with default arguments. It converts the variables with factor and character classes to dummy variables. If we set all = FALSE, it removes the variables except for dummy variables. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
library(dummies)
dummy.data.frame(data)
##   wapple wbanana wcarrot xA xB xC y   z
## 1      1       0       0  1  0  0 1 0.4
## 2      1       0       0  0  1  0 2 0.8
## 3      0       1       0  0  0  1 3 0.4
## 4      0       1       0  1  0  0 1 0.8
## 5      0       0       1  0  1  0 2 0.4
## 6      0       0       1  0  0  1 3 0.8

dummy.data.frame(data, all = FALSE)
##   wapple wbanana wcarrot xA xB xC
## 1      1       0       0  1  0  0
## 2      1       0       0  0  1  0
## 3      0       1       0  0  0  1
## 4      0       1       0  1  0  0
## 5      0       0       1  0  1  0
## 6      0       0       1  0  0  1
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-merge-data-frames-in-r/"><em>How to Merge Data Frames in R</em></a></p>



<h2 class="wp-block-heading">2) How to Create Dummy Variables for Specified Class</h2>



<p>We can create dummy variables by specifying the variable class with dummy.class argument. In this part, we set to dummy.class to &#8220;factor&#8221;,  &#8220;character&#8221;, &#8220;numeric&#8221; and &#8220;integer&#8221;.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
dummy.data.frame(data, dummy.classes = &quot;factor&quot;)
##   wapple wbanana wcarrot x y   z
## 1      1       0       0 A 1 0.4
## 2      1       0       0 B 2 0.8
## 3      0       1       0 C 3 0.4
## 4      0       1       0 A 1 0.8
## 5      0       0       1 B 2 0.4
## 6      0       0       1 C 3 0.8

dummy.data.frame(data, dummy.classes = &quot;character&quot;)
##        w xA xB xC y   z
## 1  apple  1  0  0 1 0.4
## 2  apple  0  1  0 2 0.8
## 3 banana  0  0  1 3 0.4
## 4 banana  1  0  0 1 0.8
## 5 carrot  0  1  0 2 0.4
## 6 carrot  0  0  1 3 0.8

dummy.data.frame(data, dummy.classes = &quot;numeric&quot;)
##        w x y z0.4 z0.8
## 1  apple A 1    1    0
## 2  apple B 2    0    1
## 3 banana C 3    1    0
## 4 banana A 1    0    1
## 5 carrot B 2    1    0
## 6 carrot C 3    0    1

dummy.data.frame(data, dummy.classes = &quot;integer&quot;)
##        w x y1 y2 y3   z
## 1  apple A  1  0  0 0.4
## 2  apple B  0  1  0 0.8
## 3 banana C  0  0  1 0.4
## 4 banana A  1  0  0 0.8
## 5 carrot B  0  1  0 0.4
## 6 carrot C  0  0  1 0.8
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-remove-outliers-from-data-in-r/"><em>How to Remove Outliers from Data in R</em></a></p>



<h2 class="wp-block-heading">3) How to Create Dummy Variables for All Variables </h2>



<p>We can create dummy variables for all variables by setting dummy.class to &#8220;ALL&#8221;.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
dummy.data.frame(data, dummy.classes = &quot;ALL&quot;)
##   wapple wbanana wcarrot xA xB xC y1 y2 y3 z0.4 z0.8
## 1      1       0       0  1  0  0  1  0  0    1    0
## 2      1       0       0  0  1  0  0  1  0    0    1
## 3      0       1       0  0  0  1  0  0  1    1    0
## 4      0       1       0  1  0  0  1  0  0    0    1
## 5      0       0       1  0  1  0  0  1  0    1    0
## 6      0       0       1  0  0  1  0  0  1    0    1
</pre></div>


<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="How to Create Dummy Variables Based on Variable Class in R Data Frame" width="676" height="380" src="https://www.youtube.com/embed/E8BstEkuuJc?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">How to Create Dummy Variables Based on Variable Class in R Data Frame</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/how-to-reinstall-all-packages-after-updating-r/"><em>How to Reinstall All Packages After Updating R</em></a></p>



<p><strong>References</strong></p>



<p>Brown, C. (2012). dummies: Create dummy/indicator variables flexibly and efficiently. R package version 1.5.6.</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/how-to-create-dummy-variables-based-on-variable-class-in-r-data-frame/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to Convert Categorical Variables into Dummy Variables in R</title>
		<link>https://universeofdatascience.com/how-to-convert-categorical-variables-into-dummy-variables-in-r/</link>
					<comments>https://universeofdatascience.com/how-to-convert-categorical-variables-into-dummy-variables-in-r/#comments</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 26 Feb 2023 23:32:00 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1564</guid>

					<description><![CDATA[It is important to create dummy variables when working on categorical variables where there is no ordered relationship. This ultimate tutorial includes necessary steps to make dummy variables in R. Sometimes, researchers can use integer encoding for a nominal variable to put it in a regression model. Integer encoding assigns a unique integer to each [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>It is important to create dummy variables when working on categorical variables where there is no ordered relationship. This ultimate tutorial includes necessary steps to make dummy variables in R.</p>



<span id="more-1564"></span>



<p>Sometimes, researchers can use integer encoding for a nominal variable to put it in a regression model. Integer encoding assigns a unique integer to each level of a categorical variable. Therefore, just integer encoding to nominal variable is misleading since it lets the model do a natural ordering between categories. This cause unexpected results and poor performance.</p>



<p>If we have a nominal variable and want to put it in the model, we need to create dummy variables for each nominal variable, i.e. one hot encoding. If we have k levels of a categorical variable, k new dummy variables are created. Each dummy variable has a value of either 0 or 1 , representing absence or presence of that feature, respectively.</p>



<p>If we have k levels of a categorical variable and we create k new dummy variables, we may fall in dummy variable trap. Dummy variable trap is a situation in which one variable can be exactly predicted by the value of other variables (multicollinearity). Therefore, we need to exclude one dummy variable while constructing regression model. <strong>As a result, if we have k levels of a categorical variable, we need to create k-1 dummy variables.</strong></p>



<p>In this tutorial, we learn the usage of dummy_cols() function available in <a href="https://CRAN.R-project.org/package=fastDummies">fastDummies</a> package (Kaplan, 2020). Firstly, we learn how to create dummy variables. Secondly, we go over how to remove the nominal variables from data after creating dummy variables. At last, we learn how to save from dummy variable trap.</p>



<p>Let’s construct a data frame involving two categorical variables in which no ordinal relation exists.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
x &lt;- factor(rep(c(&quot;apple&quot;,&quot;banana&quot;,&quot;carrot&quot;), each = 2))
y &lt;- factor(rep(c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;), 2))
data &lt;- data.frame(x, y)
data
##        x y
## 1  apple A
## 2  apple B
## 3 banana C
## 4 banana A
## 5 carrot B
## 6 carrot C
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-merge-data-frames-in-r/"><em>How to Merge Data Frames in R</em></a></p>



<h2 class="wp-block-heading">1) How to Create Dummy Variables in R</h2>



<p>In this part, we use select_columns argument to define which variables are converted into dummy variables. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
library(fastDummies)
dummy_cols(data, select_columns = c(&quot;x&quot;,&quot;y&quot;))
##        x y x_apple x_banana x_carrot y_A y_B y_C
## 1  apple A       1        0        0   1   0   0
## 2  apple B       1        0        0   0   1   0
## 3 banana C       0        1        0   0   0   1
## 4 banana A       0        1        0   1   0   0
## 5 carrot B       0        0        1   0   1   0
## 6 carrot C       0        0        1   0   0   1
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-remove-outliers-from-data-in-r/"><em>How to Remove Outliers from Data in R</em></a></p>



<h2 class="wp-block-heading">2) How to Remove Nominal Variables After Creating Dummy Variables</h2>



<p>We can use remove_selected_columns argument to remove initial categorical variables from data after creation of dummy variables by set it to TRUE.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
dummy_cols(data, select_columns = c(&quot;x&quot;,&quot;y&quot;), remove_selected_columns = TRUE)
##   x_apple x_banana x_carrot y_A y_B y_C
## 1       1        0        0   1   0   0
## 2       1        0        0   0   1   0
## 3       0        1        0   0   0   1
## 4       0        1        0   1   0   0
## 5       0        0        1   0   1   0
## 6       0        0        1   0   0   1
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-create-dummy-variables-based-on-variable-class-in-r-data-frame/">How to Create Dummy Variables Based on Variable Class in R Data Frame</a></p>



<h2 class="wp-block-heading">3) How to Save from Dummy Variable Trap in R</h2>



<p>At last, we can use remove_first_dummy argument to save from dummy variable trap by setting it to TRUE.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
dummy_cols(data, select_columns = c(&quot;x&quot;,&quot;y&quot;), remove_selected_columns = TRUE, remove_first_dummy  = TRUE)
##   x_banana x_carrot y_B y_C
## 1        0        0   0   0
## 2        0        0   1   0
## 3        1        0   0   1
## 4        1        0   0   0
## 5        0        1   1   0
## 6        0        1   0   1
</pre></div>


<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="How to Convert Categorical Variables into Dummy Variables in R" width="676" height="380" src="https://www.youtube.com/embed/r_dezUYmlMw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">How to Convert Categorical Variables into Dummy Variables in R</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/missing-data-imputations-in-r-mean-median-mode/"><em>Missing Data Imputations in R – Mean, Median, Mode</em></a></p>



<p><strong>References</strong></p>



<p>Kaplan, J. (2020). fastDummies: Fast Creation of Dummy (Binary) Columns and Rows from Categorical Variables. R package version 1.6.3.</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/how-to-convert-categorical-variables-into-dummy-variables-in-r/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to Reinstall All Packages After Updating R</title>
		<link>https://universeofdatascience.com/how-to-reinstall-all-packages-after-updating-r/</link>
					<comments>https://universeofdatascience.com/how-to-reinstall-all-packages-after-updating-r/#comments</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 19 Feb 2023 00:01:45 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1530</guid>

					<description><![CDATA[R packages are not generally compatible across upgrades and must be reinstalled after updating R. This inclusive tutorial covers the reinstallation steps of available R packages. Find out how to reinstall all packages after updating R. Managing R packages is important part for the data scientist working with R since lots of tools are available [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>R packages are not generally compatible across upgrades and must be reinstalled  after updating R. This inclusive tutorial covers the reinstallation steps of available R packages. Find out how to reinstall all packages after updating R.</p>



<span id="more-1530"></span>



<p>Managing R packages is important part for the data scientist working with <a href="https://cran.r-project.org/">R</a> since lots of tools are available in separate R packages. Firstly, we will learn how to get a list of installed packages. In second step, we pull the name of packages available in R. Then, we will learn how to save the name of the packages. After that, you can update R. Then, we learn to pull the names of packages in R console. At last, we go over how to reinstall all packages in R.</p>



<p>We can see the installed packages with installed.packages() function. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
packages &lt;- as.data.frame(installed.packages())
rownames(packages) &lt;- NULL
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-list-installed-packages-with-versions-in-r/"><em>How to List Installed Packages with Versions in R</em></a></p>



<p>After we obtained the list of install packages, we pull the names of packages.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
out &lt;- packages&#x5B;,&quot;Package&quot;]
</pre></div>


<p> Let’s see the head of the package names available in R. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
head(out)
## &#x5B;1] &quot;A3&quot; &quot;ABCanalysis&quot; &quot;abind&quot; &quot;ada&quot; &quot;admisc&quot; &quot;AER&quot;
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-install-and-load-a-package-in-r/"><em>How to Install and Load a Package in R</em></a></p>



<p>In this part, we save the names of the packages available in R with write.table() function. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
write.table(out, file = &quot;Package_List.txt&quot;, sep = &quot;\t&quot;, row.names = FALSE, col.names = FALSE)
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-clean-data-in-r/"><em>How to Clean Data in R</em></a></p>



<p>Then, we can update our R programme. After we have the new version of R, we need to read the names of R packages we saved in .txt file. We read the package names with read.table() function. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
List &lt;- read.table(&quot;Package_List.txt&quot;)
</pre></div>


<p>The class of List object is data frame having just one column which is the package names. Let’s see the head of the package names. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
head(List&#x5B;,1])
## &#x5B;1] &quot;A3&quot; &quot;ABCanalysis&quot; &quot;abind&quot; &quot;ada&quot; &quot;admisc&quot; &quot;AER&quot;
</pre></div>


<p>At last, we can install multiple R packages with install.packages() function. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
install.packages(List&#x5B;,1], repos = &quot;https://cloud.r-project.org&quot;)
</pre></div>


<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="How to Reinstall All Packages After Updating R" width="676" height="380" src="https://www.youtube.com/embed/kfI2za5csIM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">How to Reinstall All Packages After Updating R</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/missing-data-imputations-in-r-mean-median-mode/"><em>Missing Data Imputations in R – Mean, Median, Mode</em></a></p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/how-to-reinstall-all-packages-after-updating-r/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to List Installed Packages with Versions in R</title>
		<link>https://universeofdatascience.com/how-to-list-installed-packages-with-versions-in-r/</link>
					<comments>https://universeofdatascience.com/how-to-list-installed-packages-with-versions-in-r/#comments</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 12 Feb 2023 01:41:43 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<category><![CDATA[how to find a package in r]]></category>
		<category><![CDATA[list all packages in r]]></category>
		<category><![CDATA[list of installed packages in r]]></category>
		<category><![CDATA[r check package version]]></category>
		<category><![CDATA[r list loaded packages and versions]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1524</guid>

					<description><![CDATA[R&#160;is a free software&#160;environment&#160;made up of many user-written packages. In this tutorial, we work on how to get a list of installed packages, the package versions, the place of packages in R. Managing R packages is essential for R users. Firstly, we will learn how to get a list of installed packages. Secondly, we go [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>R&nbsp;is a free software&nbsp;environment&nbsp;made up of many user-written packages. In this tutorial, we work on how to get a list of installed packages, the package versions, the place of packages in R.</p>



<span id="more-1524"></span>



<p>Managing R packages is essential for R users. Firstly, we will learn how to get a list of installed packages. Secondly, we go over finding version of the package. Thirdly, we will learn the pathways of the R packages installed. At last, we check whether a package is installed or not.</p>



<p>In this article, we will learn the answers of the following questions.</p>



<ul class="wp-block-list">
<li>How can I get a list of installed packages?</li>



<li>How to find out which package version is loaded in R?</li>



<li>How do I find where R packages are installed?</li>



<li>How do you check if an R package has been installed?</li>
</ul>



<p>We can see the installed packages with installed.packages() function. Then, we pull the packages and their versions. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
packINFO &lt;- as.data.frame(installed.packages())&#x5B;,c(&quot;Package&quot;, &quot;Version&quot;)]
rownames(packINFO) &lt;- NULL
</pre></div>


<p>Let&#8217;s see the head of installed packages and their versions.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
head(packINFO)
##       Package Version
## 1          A3   1.0.0
## 2 ABCanalysis   1.2.1
## 3       abind   1.4-5
## 4         ada   2.0-5
## 5      admisc    0.30
## 6         AER  1.2-10
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-install-and-load-a-package-in-r/"><em>How to Install and Load a Package in R</em></a></p>



<h2 class="wp-block-heading">How to Find Package Version in R</h2>



<p>In this section, we learn how to find the package version in R. For instance, let&#8217;s find the version of <a href="https://CRAN.R-project.org/package=onewaytests">onewaytests</a> package (Dag et al., 2018). </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
packINFO&#x5B;packINFO$Package == &quot;onewaytests&quot;,]
##         Package Version
## 300 onewaytests     2.7

packageVersion(&quot;onewaytests&quot;)
## &#x5B;1] ‘2.7’

getNamespaceVersion(&quot;onewaytests&quot;)
## version 
##   &quot;2.7&quot;
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-change-working-directory-in-r/"><em>How to Change Working Directory in R</em></a></p>



<h2 class="wp-block-heading">How to Find Where R Packages are Installed</h2>



<p>We can find the pathways of the R packages installed with .libPaths() function.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
.libPaths()
## &#x5B;1] &quot;C:/Users/osmandag/Documents/R/win-library/4.0&quot;
## &#x5B;2] &quot;C:/Program Files/R/R-4.0.2/library&quot; 
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-import-data-into-r/"><em>How to Import Data into R</em></a></p>



<h2 class="wp-block-heading">How to Check If/Where an R Package is Installed</h2>



<p>In this part, we learn how to check whether an R package is installed or not. For example, let&#8217;s check whether <a href="https://CRAN.R-project.org/package=onewaytests">onewaytests</a> package (Dag et al., 2018) is installed with system.file() function. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
system.file(package = &quot;onewaytests&quot;)
## &#x5B;1] &quot;C:/Users/osmandag/Documents/R/win-library/4.0/onewaytests&quot;
</pre></div>


<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="How to List Installed Packages with Versions in R" width="676" height="380" src="https://www.youtube.com/embed/S4rvti7RPts?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">How to List Installed Packages with Versions in R</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/how-to-download-and-install-r-for-windows/"><em>How to Download and Install R for Windows</em></a></p>



<p><strong>References</strong></p>



<p>Dag, O., Dolgun, A., Konar, N.M. (2018). onewaytests: An R Package for One-Way Tests in Independent Groups Designs.&nbsp;<em>R Journal</em>,&nbsp;10(1), 175-199.</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/how-to-list-installed-packages-with-versions-in-r/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Missing Data Imputations in R &#8211; Mean, Median, Mode</title>
		<link>https://universeofdatascience.com/missing-data-imputations-in-r-mean-median-mode/</link>
					<comments>https://universeofdatascience.com/missing-data-imputations-in-r-mean-median-mode/#comments</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 05 Feb 2023 00:01:53 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<category><![CDATA[mean imputation in R]]></category>
		<category><![CDATA[median imputation in R]]></category>
		<category><![CDATA[mode imputation in R]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1502</guid>

					<description><![CDATA[It is very difficult to have complete data while making data analysis in practice. In this tutorial, we learn simple missing imputation techniques &#8211; mean, median, mode. Find out how to impute missing data in R. In this tutorial, we learn three simple imputation methods in R. Firstly, we learn how to make missing data [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>It is very difficult to have complete data while making data analysis in practice. In this tutorial, we learn simple missing imputation techniques &#8211; mean, median, mode.  Find out how to impute missing data in R.</p>



<span id="more-1502"></span>



<p>In this tutorial, we learn three simple imputation methods in <a href="https://cran.r-project.org/">R</a>. Firstly, we learn how to make missing data imputation with mean. Secondly, we go over median imputation. At last, we learn how to make mode imputation in <a href="https://cran.r-project.org/">R</a>.</p>



<h2 class="wp-block-heading">1) How to Make Mean Imputation in R</h2>



<p>In our example, we create a vector including a missing observation. We find the place of missing observation with is.na() function. After that, we use mean() function to find by excluding missing observations. In our example, the mean of the vector is 225 after excluding missing observations. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data &lt;- c(100, 200, 300, 300, NA)
data&#x5B;is.na(data)] &lt;- mean(data, na.rm = TRUE)
data
## &#x5B;1] 100 200 300 300 225
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-remove-outliers-from-data-in-r/"><em>How to Remove Outliers from Data in R</em></a></p>



<h2 class="wp-block-heading">2) How to Make Median Imputation in R</h2>



<p>In this section, we learn how to conduct median imputation in R. We utilize the median of the vector with median() function by keeping the missing observations out. For our example data, the median is 250 after excluding NAs. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data &lt;- c(100, 200, 300, 300, NA)
data&#x5B;is.na(data)] &lt;- median(data, na.rm = TRUE)
data
## &#x5B;1] 100 200 300 300 250
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-handle-missing-values-in-r/"><em>How to Handle Missing Values in R</em></a></p>



<h2 class="wp-block-heading">3) How to Make Mode Imputation in R</h2>



<p>In this part, we go over how to implement mode imputation in R. This imputation type is generally used for categorical variables. We need to use mode of the variable. For this purpose, we can find  frequency of each value using table() function which removes the NAs in default. After finding the frequencies, we use which.max() function to find the place of highest frequency. Then, we use names() function to find the mode, but it returns the output with &#8220;character&#8221; class. Therefore, we use as.numeric() function to return output as numeric.  In our example, the mode of the variable is 300 after keeping missing observations away. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data &lt;- c(100, 200, 300, 300, NA)
data&#x5B;is.na(data)] &lt;- as.numeric(names(which.max(table(data))))
data
## &#x5B;1] 100 200 300 300 300
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-clean-data-in-r/"><em>How to Clean Data in R</em></a></p>



<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="Missing Data Imputations in R – Mean, Median, Mode" width="676" height="380" src="https://www.youtube.com/embed/CtIJJWS1HYs?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">Missing Data Imputations in R &#8211; Mean, Median, Mode</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/how-to-merge-data-frames-in-r/"><em>How to Merge Data Frames in R</em></a></p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/missing-data-imputations-in-r-mean-median-mode/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>4 Ways of Finding Unique Values in R</title>
		<link>https://universeofdatascience.com/4-ways-of-finding-unique-values-in-r/</link>
					<comments>https://universeofdatascience.com/4-ways-of-finding-unique-values-in-r/#respond</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 29 Jan 2023 09:45:12 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<category><![CDATA[how to find unique values in r]]></category>
		<category><![CDATA[r distinct values in column dplyr]]></category>
		<category><![CDATA[r/distinct values in data]]></category>
		<category><![CDATA[unique in r]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1475</guid>

					<description><![CDATA[Finding unique values may be&#160;a necessity while analyzing a data set.&#160;In this tutorial, we will learn four ways of finding unique values. Find out how to find unique values in R. In this tutorial, we learn how to find unique values in&#160;R. Firstly, we go over unique() function. Secondly, we learn how to use duplicated() [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Finding unique values may be&nbsp;a necessity while analyzing a data set.&nbsp;In this tutorial, we will learn four ways of finding unique values. Find out how to find unique values in R.</p>



<span id="more-1475"></span>



<p>In this tutorial, we learn how to find unique values in&nbsp;<a href="https://cran.r-project.org/">R</a>. Firstly, we go over unique() function. Secondly, we learn how to use duplicated() function to obtain unique values. Thirdly, we learn how to use distinct() function available in <a href="https://cran.r-project.org/package=dplyr">dplyr</a>&nbsp;package (Wickham et al., 2022). At last, we go over names() function to find unique values in R.</p>



<p>Let’s construct an example data including duplicated observations to illustrate how to find unique values in R.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data &lt;- c(&quot;apple&quot;,&quot;banana&quot;,&quot;banana&quot;,&quot;carrot&quot;,&quot;carrot&quot;,&quot;carrot&quot;)
data
## &#x5B;1] &quot;apple&quot;  &quot;banana&quot; &quot;banana&quot; &quot;carrot&quot; &quot;carrot&quot; &quot;carrot&quot;
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-clean-data-in-r/"><em>How to Clean Data in R</em></a></p>



<h3 class="wp-block-heading">1) How to Find Unique Values with unique() Function in R</h3>



<p>In this part, we use unique() function to find unique values in R.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
unique(data)
## &#x5B;1] &quot;apple&quot;  &quot;banana&quot; &quot;carrot&quot;
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-use-apply-functions-in-r/"><em>How to Use apply Functions in R</em></a></p>



<h3 class="wp-block-heading">2) How to Find Unique Values with dublicated() Function in R</h3>



<p>In this section, we use duplicated() function to obtain duplicated values. Then, we add the sign ! before the duplicated() function in the data to obtain unique values in R.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data&#x5B;!duplicated(data)] 
## &#x5B;1] &quot;apple&quot;  &quot;banana&quot; &quot;carrot&quot;
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-recode-character-variables-in-r/"><em>How to Recode Character Variables in R</em></a></p>



<h3 class="wp-block-heading">3) How to Find Unique Values with distinct() Function in R</h3>



<p>In this section, we learn distinct() function available in&nbsp;<a href="https://cran.r-project.org/package=dplyr">dplyr</a>&nbsp;package (Wickham et al., 2022)&nbsp;to learn how to obtain unique values in R.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
library(dplyr)
distinct(data.frame(data))&#x5B;,1]   
## &#x5B;1] &quot;apple&quot;  &quot;banana&quot; &quot;carrot&quot;
</pre></div>


<h3 class="wp-block-heading">4) How to Find Unique Values with names() Function in R</h3>



<p>At last, we construct the frequency table by table() function. Then, we read the names of observations with names() function to find unique values in R.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
names(table(data))
## &#x5B;1] &quot;apple&quot;  &quot;banana&quot; &quot;carrot&quot;
</pre></div>


<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="4 Ways of Finding Unique Values in R" width="676" height="380" src="https://www.youtube.com/embed/i3Y9gM7JQAg?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">4 Ways of Finding Unique Values in R</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/what-are-data-types-in-r/"><em>What are Data Types in R?</em></a></p>



<p><strong>References</strong></p>



<p>Wickham, H., Francois, R., Henry, L., Muller, K. (2022). dplyr: A Grammar of Data Manipulation. R package version 1.0.10.</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/4-ways-of-finding-unique-values-in-r/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Use apply Functions in R</title>
		<link>https://universeofdatascience.com/how-to-use-apply-functions-in-r/</link>
					<comments>https://universeofdatascience.com/how-to-use-apply-functions-in-r/#comments</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 22 Jan 2023 00:15:56 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<category><![CDATA[apply function in r example]]></category>
		<category><![CDATA[lapply in r]]></category>
		<category><![CDATA[maaply in r]]></category>
		<category><![CDATA[saaply in r]]></category>
		<category><![CDATA[tapply in r]]></category>
		<category><![CDATA[vapply in r]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1459</guid>

					<description><![CDATA[The use of apply functions enables data scientists to make the things easier. In this tutorial, we go over apply, tapply, lapply, sapply, vapply and mapply. Find out how to use apply functions in R. In this tutorial, we learn how to use apply functions in R. Firstly, we go over apply() function. Secondly, we [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>The use of apply functions enables data scientists to make the things easier. In this tutorial, we go over apply, tapply, lapply, sapply, vapply and mapply. Find out how to use apply functions in R.</p>



<span id="more-1459"></span>



<p>In this tutorial, we learn how to use apply functions in <a href="https://cran.r-project.org/">R</a>. Firstly, we go over apply() function. Secondly, we learn how to use tapply() function to obtain results by groups. Thirdly, we learn how to use lapply() function to obtain results in listwise. Also, we use sapply() function to obtain results in vector. Moreover, we learn the use of vapply() function.  At last, we go over mapply() function.</p>



<h2 class="wp-block-heading">1) How to Use apply() Function in R</h2>



<p>The apply() function takes data frames as an input. We can apply it by row or column. First, we find sum of the observations by row. Then, we calculate the sum of values by column.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
mydata &lt;- data.frame(x = 1:3, y = 11:13, z = 101:103)

apply(mydata, 1, sum)   
## &#x5B;1] 113 116 119

apply(mydata, 2, sum) 
##   x   y   z 
##   6  36 306
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-merge-data-frames-in-r/"><em>How to Merge Data Frames in R</em></a></p>



<h2 class="wp-block-heading">2) How to Use tapply() Function in R</h2>



<p>In this section, we go over tapply() function. This function is used to obtain the result by group. For this purpose, let&#8217;s contruct a data frame. Then, we use tapply() to obtain sum of observation for each group.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
mydata &lt;- data.frame(x = c(&quot;a&quot;,&quot;a&quot;,&quot;b&quot;,&quot;b&quot;), y = 11:14)
tapply(mydata$y, mydata$x, sum) 
##  a  b 
## 23 27
</pre></div>


<h2 class="wp-block-heading">3) How to Use lapply() Function in R</h2>



<p>In this part, we learn how to use lapply() function. Firstly, we construct a list as an example. Then, we obtain sum of the observations in each of list object and return the result as a list.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
mylist &lt;- list(1:3, 11:13, 101:103)
lapply(mylist, sum) 
## &#x5B;&#x5B;1]]
## &#x5B;1] 6
## 
## &#x5B;&#x5B;2]]
## &#x5B;1] 36
## 
## &#x5B;&#x5B;3]]
## &#x5B;1] 306
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-remove-outliers-from-data-in-r/"><em>How to Remove Outliers from Data in R</em></a></p>



<h2 class="wp-block-heading">4) How to Use sapply() Function in R</h2>



<p>In this section, we use sapply() function. First, we construct a list as an example. Then, we obtain sum of the observations in each of list object and return the result as a vector.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
mylist &lt;- list(1:3, 11:13, 101:103)
sapply(mylist, sum) 
## &#x5B;1]   6  36 306
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-find-class-of-each-column-in-r-data-frame/"><em>How to Find Class of Each Column in R Data Frame</em></a></p>



<h2 class="wp-block-heading">5) How to Use vapply() Function in R</h2>



<p>The vapply() function is similar tı sapply() function, but vapply() function requires &nbsp;the output type. In our example, we return the result as numeric.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
mylist &lt;- list(1:3, 11:13, 101:103)
vapply(mylist, sum, numeric(1))
## &#x5B;1]   6  36 306
</pre></div>


<h2 class="wp-block-heading">6) How to Use mapply() Function in R</h2>



<p>The mapply() requires a function and inputs. We construct a data frame. We need to have a function or we can use available function in R. Then, we can use mapply() function in which we put our function and inputs, respectively.  </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
mydata &lt;- data.frame(x = 1:3, y = 11:13, z = 101:103)
myfunction &lt;- function(x, y, z){x+y+z}
mapply(myfunction, mydata$x, mydata$y, mydata$z)
## &#x5B;1] 113 116 119
</pre></div>


<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="How to Use apply Functions in R" width="676" height="380" src="https://www.youtube.com/embed/t10TxdwRq8U?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">How to Use apply Functions in R</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/how-to-convert-all-columns-of-data-frame-to-numeric-in-r/"><em>How to Convert All Columns of Data Frame to Numeric in R</em></a></p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/how-to-use-apply-functions-in-r/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>How to Merge Data Frames in R</title>
		<link>https://universeofdatascience.com/how-to-merge-data-frames-in-r/</link>
					<comments>https://universeofdatascience.com/how-to-merge-data-frames-in-r/#comments</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 15 Jan 2023 00:15:56 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<category><![CDATA[merge in r example]]></category>
		<category><![CDATA[merge multiple data frames in r dplyr]]></category>
		<category><![CDATA[merge r]]></category>
		<category><![CDATA[merge rows in r]]></category>
		<category><![CDATA[r combine two data frames]]></category>
		<category><![CDATA[r combine two data frames vertically]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1439</guid>

					<description><![CDATA[Sometimes, we need to merge datasets coming from different sources. This ultimate tutorial includes combining the data frames in different ways. Find out how to merge data frames in R. In this tutorial, we will cover how to merge data frames in different ways. We will learn combining data frames by common ids, first data [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Sometimes, we need to merge datasets coming from different sources. This ultimate tutorial includes combining the data frames in different ways. Find out how to merge data frames in R.</p>



<span id="more-1439"></span>



<p>In this tutorial, we will cover how to merge data frames in different ways. We will learn combining data frames by common ids, first data frame ids, second data frame ids and all ids. There are commonly used three ways of merging data frames in R. Firstly, we will learn how to join the data frames by using merge() function. Secondly, we learn <a href="https://CRAN.R-project.org/package=dplyr">dplyr</a> package (Wickham et al., 2022) to merge data frames in R. At last, we use <a href="https://CRAN.R-project.org/package=tidyverse">tidyverse</a> package (Wickham et al., 2019) to combine data drames in R.</p>



<p>Let’s construct two data frames to illustrate how to merge data frames in R.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data1 &lt;- data.frame(id = 1:4, x1 = 101:104)
data1
##   id  x1
## 1  1 101
## 2  2 102
## 3  3 103
## 4  4 104

data2 &lt;- data.frame(id = 3:6, x2 = 13:16)
data2
##   id x2
## 1  3 13
## 2  4 14
## 3  5 15
## 4  6 16
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-convert-all-columns-of-data-frame-to-numeric-in-r/"><em>How to Convert All Columns of Data Frame to Numeric in R</em></a></p>



<h2 class="wp-block-heading">1) How to Merge Data Frames Using merge() Function in R</h2>



<p>In this part, we use merge() function to combine the data frames by common ids, first data frame ids, second data frame ids and all ids, respectively.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
merge(data1, data2, by = &quot;id&quot;)
##   id  x1 x2
## 1  3 103 13
## 2  4 104 14

merge(data1, data2, by = &quot;id&quot;, all.x = TRUE) 
##   id  x1 x2
## 1  1 101 NA
## 2  2 102 NA
## 3  3 103 13
## 4  4 104 14

merge(data1, data2, by = &quot;id&quot;, all.y = TRUE) 
##   id  x1 x2
## 1  3 103 13
## 2  4 104 14
## 3  5  NA 15
## 4  6  NA 16

merge(data1, data2, by = &quot;id&quot;, all.x = TRUE, all.y = TRUE)  
##   id  x1 x2
## 1  1 101 NA
## 2  2 102 NA
## 3  3 103 13
## 4  4 104 14
## 5  5  NA 15
## 6  6  NA 16
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-find-class-of-each-column-in-r-data-frame/"><em>How to Find Class of Each Column in R Data Frame</em></a></p>



<h2 class="wp-block-heading">2) How to Merge Data Frames Using dplyr Package in R</h2>



<p>In this section, we learn inner_join(), left_join(), right_join() and  full_join() functions available in <a href="https://cran.r-project.org/package=dplyr">dplyr</a> package (Wickham et al., 2022) to merge data frames by common ids, first data frame ids, second data frame ids and all ids, respectively.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
library(dplyr)
data1 %&gt;% inner_join(data2, by = 'id')
##   id  x1 x2
## 1  3 103 13
## 2  4 104 14

data1 %&gt;% left_join(data2, by = 'id')
##   id  x1 x2
## 1  1 101 NA
## 2  2 102 NA
## 3  3 103 13
## 4  4 104 14
 
data1 %&gt;% right_join(data2, by = 'id')
##   id  x1 x2
## 1  3 103 13
## 2  4 104 14
## 3  5  NA 15
## 4  6  NA 16
 
data1 %&gt;% full_join(data2, by = 'id')
##   id  x1 x2
## 1  1 101 NA
## 2  2 102 NA
## 3  3 103 13
## 4  4 104 14
## 5  5  NA 15
## 6  6  NA 16
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-round-data-frame-containing-character-variables-in-r/"><em>How to Round Data Frame Containing Character Variables in R</em></a></p>



<h2 class="wp-block-heading">3) How to Merge Data Frames Using tidyverse Package in R</h2>



<p>In this part, we first need to list the data frames. Then, we use reduce() function. Inside reduce() function, inner_join, left_join, right_join and full_join must be defined to merge data frames by common ids, first data frame ids, second data frame ids and all ids, respectively.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
library(tidyverse)
data_list &lt;- list(data1, data2)      
 
data_list %&gt;% reduce(inner_join, by = 'id')
##   id  x1 x2
## 1  3 103 13
## 2  4 104 14

data_list %&gt;% reduce(left_join, by = 'id')
##   id  x1 x2
## 1  1 101 NA
## 2  2 102 NA
## 3  3 103 13
## 4  4 104 14

data_list %&gt;% reduce(right_join, by = 'id')
##   id  x1 x2
## 1  3 103 13
## 2  4 104 14
## 3  5  NA 15
## 4  6  NA 16

data_list %&gt;% reduce(full_join, by = 'id')
##   id  x1 x2
## 1  1 101 NA
## 2  2 102 NA
## 3  3 103 13
## 4  4 104 14
## 5  5  NA 15
## 6  6  NA 16
</pre></div>


<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="How to Merge Data Frames in R" width="676" height="380" src="https://www.youtube.com/embed/Urs9jE3q8vQ?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">How to Merge Data Frames in R</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/how-to-sort-a-data-frame-by-single-and-multiple-columns-in-r/"><em>How to Sort a Data Frame by Single and Multiple Columns in R</em></a></p>



<p><strong>References</strong></p>



<p>Wickham, H., Averick, M., Bryan, J., Chang, W., McGowan, L. D. A., François, R., &#8230; &amp; Yutani, H. (2019). Welcome to the Tidyverse.&nbsp;<em>Journal of open source software</em>,&nbsp;<em>4</em>(43), 1686.</p>



<p>Wickham, H., Francois, R., Henry, L., Muller, K. (2022). dplyr: A Grammar of Data Manipulation. R package version 1.0.10.</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/how-to-merge-data-frames-in-r/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>How to Convert All Columns of Data Frame to Numeric in R</title>
		<link>https://universeofdatascience.com/how-to-convert-all-columns-of-data-frame-to-numeric-in-r/</link>
					<comments>https://universeofdatascience.com/how-to-convert-all-columns-of-data-frame-to-numeric-in-r/#comments</comments>
		
		<dc:creator><![CDATA[Data Science Team]]></dc:creator>
		<pubDate>Sun, 08 Jan 2023 00:01:40 +0000</pubDate>
				<category><![CDATA[R]]></category>
		<category><![CDATA[convert all dataframe to numeric r]]></category>
		<category><![CDATA[convert columns to numeric in r dplyr]]></category>
		<category><![CDATA[convert multiple columns to numeric r]]></category>
		<category><![CDATA[r convert all columns to numeric dplyr]]></category>
		<guid isPermaLink="false">https://universeofdatascience.com/?p=1412</guid>

					<description><![CDATA[Converting data type to numeric is important while analyzing the data in R. In this tutorial, we will learn three ways of converting the colums of data frame to numeric. Find out how to convert all columns of data frame to numeric in R. In this tutorial, we learn three ways of converting all data [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Converting data type to numeric is important while analyzing the data in R. In this tutorial, we will learn three ways of converting the colums of data frame to numeric. Find out how to convert all columns of data frame to numeric in R.</p>



<span id="more-1412"></span>



<p>In this tutorial, we learn three ways of converting all data frame columns to numeric in R. Firstly, we go over <a href="https://CRAN.R-project.org/package=dplyr">dplyr</a> package to convert the columns to numeric in data frame. Secondly, we work on sapply() function to convert all columns to numeric in R data frame. At last, we learn how to convert all columns of data frame to numeric in R using apply() function. </p>



<p>Let&#8217;s construct a data frame including the variables with different classes as an example data frame. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
a &lt;- c(1,3,5,-4) 
b &lt;- c(&quot;5&quot;,&quot;3&quot;,&quot;1&quot;,&quot;4&quot;)
c &lt;- c(3L,-2L,4L,7L) 

data &lt;- data.frame(a,b,c)
data
##    a b  c
## 1  1 5  3
## 2  3 3 -2
## 3  5 1  4
## 4 -4 4  7

sapply(data, class)
##           a           b           c 
##   &quot;numeric&quot; &quot;character&quot;   &quot;integer&quot;
</pre></div>


<p><strong><strong>Check Out:</strong></strong> <a href="https://universeofdatascience.com/how-to-find-class-of-each-column-in-r-data-frame/"><em>How to Find Class of Each Column in R Data Frame</em></a></p>



<h2 class="wp-block-heading">1) How to Convert All Data Frame Columns to Numeric in R Using dplyr Package</h2>



<p>In this part, we use mutate_at() function available in <a href="https://CRAN.R-project.org/package=dplyr">dplyr</a> package to convert the columns to numeric in data frame.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
library(dplyr)
data2 &lt;- data %&gt;% mutate_at(1:3, as.numeric)
data2
##    a b  c
## 1  1 5  3
## 2  3 3 -2
## 3  5 1  4
## 4 -4 4  7

sapply(data2, class)
##         a         b         c 
## &quot;numeric&quot; &quot;numeric&quot; &quot;numeric&quot;
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-clean-data-in-r/"><em>How to Clean Data in R</em></a></p>



<h2 class="wp-block-heading">2) How to Convert All Data Frame Columns to Numeric in R Using sapply() Function</h2>



<p>In this section, we learn sapply() function to change the classes of all data frame columns to numeric in R. When we use sapply() function, the class of data frame becomes matrix or array. Therefore, we need to convert the class of data to data frame with as.data.frame() function. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data2 &lt;- sapply(data, as.numeric)
data2 &lt;- as.data.frame(data2)
data2
##    a b  c
## 1  1 5  3
## 2  3 3 -2
## 3  5 1  4
## 4 -4 4  7

sapply(data2, class)
##         a         b         c 
## &quot;numeric&quot; &quot;numeric&quot; &quot;numeric&quot;
</pre></div>


<p><strong>Also Check:</strong> <a href="https://universeofdatascience.com/how-to-remove-outliers-from-data-in-r/"><em>How to Remove Outliers from Data in R</em></a></p>



<h2 class="wp-block-heading">3) How to Convert All Data Frame Columns to Numeric in R Using apply() Function</h2>



<p>In this part, we work on apply() function to change the classes of all data frame columns to numeric in R. When we use apply() function, the class of data frame becomes matrix or array. Therefore, we need to convert the class of data to data frame with as.data.frame() function. </p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: r; title: ; notranslate">
data2 &lt;- apply(data, 2, function(x) as.numeric(x))
data2 &lt;- as.data.frame(data2)
data2
##    a b  c
## 1  1 5  3
## 2  3 3 -2
## 3  5 1  4
## 4 -4 4  7

sapply(data2, class)
##         a         b         c 
## &quot;numeric&quot; &quot;numeric&quot; &quot;numeric&quot; 
</pre></div>


<p>The application of the codes is available in our youtube channel below.</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="youtube-subscribe-bar-container"><div><iframe loading="lazy" title="How to Convert All Columns of Data Frame to Numeric in R" width="676" height="380" src="https://www.youtube.com/embed/O9xsmxxXapI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></div></div>
</div><figcaption class="wp-element-caption">How to Convert All Columns of Data Frame to Numeric in R</figcaption></figure>
<div class="youtube-subscribe-bar" style="color: #ffffff;background-color: #1b1b1b;">
			<div>Subscribe to YouTube Channel</div>
		<div>
		<iframe
				src="https://www.youtube.com/subscribe_embed?usegapi=1&amp;channelid=UC_sejq_JJ49KiiK4qh5r-wg&amp;layout=default&amp;theme=dark&amp;count=default&amp;origin=https%3A%2F%2Funiverseofdatascience.com%2F"></iframe></div>
	<div class="clear"></div>
</div>



<div style="height:30px" aria-hidden="true" class="wp-block-spacer"></div>



<p><strong>Don’t forget to check:</strong> <a href="https://universeofdatascience.com/how-to-sort-a-data-frame-by-single-and-multiple-columns-in-r/"><em>How to Sort a Data Frame by Single and Multiple Columns in R</em></a></p>



<p><strong>References</strong></p>



<p>Wickham, H., Francois, R., Henry, L., Muller, K. (2022). dplyr: A Grammar of Data Manipulation. R package version 1.0.10.</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<hr class="wp-block-separator has-css-opacity is-style-wide"/>


<div class="wp-block-image is-resized is-style-rounded">
<figure class="aligncenter size-full"><img loading="lazy" decoding="async" width="315" height="320" src="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg" alt="" class="wp-image-1695" style="width:155px;height:auto" srcset="https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3.jpeg 315w, https://universeofdatascience.com/wp-content/uploads/2023/11/OD-3-295x300.jpeg 295w" sizes="auto, (max-width: 315px) 100vw, 315px" /><figcaption class="wp-element-caption">Assoc. Prof. Osman Dag</figcaption></figure></div>


<ul class="wp-block-social-links aligncenter has-icon-color has-icon-background-color is-layout-flex wp-block-social-links-is-layout-flex"><li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a href="https://www.linkedin.com/in/osmandag/" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-twitter  wp-block-social-link"><a href="https://twitter.com/dr_osmandag" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M22.23,5.924c-0.736,0.326-1.527,0.547-2.357,0.646c0.847-0.508,1.498-1.312,1.804-2.27 c-0.793,0.47-1.671,0.812-2.606,0.996C18.324,4.498,17.257,4,16.077,4c-2.266,0-4.103,1.837-4.103,4.103 c0,0.322,0.036,0.635,0.106,0.935C8.67,8.867,5.647,7.234,3.623,4.751C3.27,5.357,3.067,6.062,3.067,6.814 c0,1.424,0.724,2.679,1.825,3.415c-0.673-0.021-1.305-0.206-1.859-0.513c0,0.017,0,0.034,0,0.052c0,1.988,1.414,3.647,3.292,4.023 c-0.344,0.094-0.707,0.144-1.081,0.144c-0.264,0-0.521-0.026-0.772-0.074c0.522,1.63,2.038,2.816,3.833,2.85 c-1.404,1.1-3.174,1.756-5.096,1.756c-0.331,0-0.658-0.019-0.979-0.057c1.816,1.164,3.973,1.843,6.29,1.843 c7.547,0,11.675-6.252,11.675-11.675c0-0.178-0.004-0.355-0.012-0.531C20.985,7.47,21.68,6.747,22.23,5.924z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Twitter</span></a></li>

<li style="color: #ffffff; background-color: #3962e3; " class="wp-social-link wp-social-link-mail  wp-block-social-link"><a href="mailto:osman.dag@outlook.com" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19,5H5c-1.1,0-2,.9-2,2v10c0,1.1.9,2,2,2h14c1.1,0,2-.9,2-2V7c0-1.1-.9-2-2-2zm.5,12c0,.3-.2.5-.5.5H5c-.3,0-.5-.2-.5-.5V9.8l7.5,5.6,7.5-5.6V17zm0-9.1L12,13.6,4.5,7.9V7c0-.3.2-.5.5-.5h14c.3,0,.5.2.5.5v.9z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Mail</span></a></li></ul>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://universeofdatascience.com/how-to-convert-all-columns-of-data-frame-to-numeric-in-r/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
