<?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>columns Archives - Data Analytics</title>
	<atom:link href="https://dataanalytics.org.uk/tag/columns/feed/" rel="self" type="application/rss+xml" />
	<link>https://dataanalytics.org.uk/tag/columns/</link>
	<description>Understanding Data</description>
	<lastBuildDate>Tue, 21 Jun 2022 16:23:27 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.1</generator>

<image>
	<url>https://dataanalytics.org.uk/wp-content/uploads/2019/11/cropped-DA-graph-logo-2019-cyan-600-32x32.png</url>
	<title>columns Archives - Data Analytics</title>
	<link>https://dataanalytics.org.uk/tag/columns/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Naming rows and columns of a matrix in R</title>
		<link>https://dataanalytics.org.uk/naming-rows-and-columns-of-a-matrix-in-r/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=naming-rows-and-columns-of-a-matrix-in-r</link>
		
		<dc:creator><![CDATA[aJfsfjlser3f]]></dc:creator>
		<pubDate>Tue, 11 Jun 2019 17:13:45 +0000</pubDate>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[columns]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[rows]]></category>
		<guid isPermaLink="false">https://www.dataanalytics.org.uk/?p=3983</guid>

					<description><![CDATA[<p>You make a matrix using matrix()rbind() or cbind() commands. The names of the rows and columns can be set after the matrix is [&#8230;]</p>
<p>The post <a href="https://dataanalytics.org.uk/naming-rows-and-columns-of-a-matrix-in-r/">Naming rows and columns of a matrix in R</a> appeared first on <a href="https://dataanalytics.org.uk">Data Analytics</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>You make a matrix using matrix()rbind() or cbind() commands. The names of the rows and columns can be set after the matrix is produced in various ways:</p>
<ul>
<li>rownames() – sets the row names</li>
<li>colnames() – sets the column names</li>
<li>dimnames() – sets both row and column names in one command</li>
</ul>
<p>The rownames() and colnames() commands set the row and column names respectively:</p>
<pre>&gt; m1 &lt;- matrix(1:12, nrow = 3)
&gt; m1
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12

&gt; rownames(m1)  &lt;- letters[26:24]
&gt; m1
  [,1] [,2] [,3] [,4]
z    1    4    7   10
y    2    5    8   11
x    3    6    9   12

&gt; colnames(m1)  &lt;- LETTERS[26:23]
&gt; m1
  Z Y X  W
z 1 4 7 10
y 2 5 8 11
x 3 6 9 12</pre>
<p>The commands can also query the names:</p>
<pre>&gt; rownames(m1)
[1] "z" "y" "x"

&gt; colnames(m1)
[1] "Z" "Y" "X" "W"</pre>
<p>Note that the basic names() command does not work for matrix objects:</p>
<pre>&gt; names(m1)
NULL</pre>
<p>If you use the rbind() command then the rows will be named according to the data names that you use unless you specify otherwise:</p>
<pre>&gt; d1 &lt;- 1:4 ; d2 = 5:8 ; d3 = 9:12

&gt; rbind(d1, d2, d3)
   [,1] [,2] [,3] [,4]
d1    1    2    3    4
d2    5    6    7    8
d3    9   10   11   12

&gt; rbind(Row1 = d1, Row2 = d2, Row3 = d3)
     [,1] [,2] [,3] [,4]
Row1    1    2    3    4
Row2    5    6    7    8
Row3    9   10   11   12</pre>
<p>Similarly with the cbind() command the columns take the names of the objects unless you specify them explicitly.</p>
<p>You can set the row and column names in one go using the dimnames() command. This requires a list() of two items (the row names and the column names):</p>
<pre>&gt; m1
  Z Y X  W
z 1 4 7 10
y 2 5 8 11
x 3 6 9 12

&gt; dimnames(m1) &lt;- list(letters[1:3], LETTERS[1:4])
&gt; m1
  A B C  D
a 1 4 7 10
b 2 5 8 11
c 3 6 9 12</pre>
<p>If you use the matrix() command you can incorporate the dimnames() command within it to set the names:</p>
<pre>&gt; m3 &lt;- <span style="color: #0000ff;">matrix</span>(1:12, nrow = 3, dimnames = list(month.abb[1:3], month.abb[4:7]))
&gt; m3
    Apr May Jun Jul
Jan   1   4   7  10
Feb   2   5   8  11
Mar   3   6   9  12</pre>
<p>Of course you can also use the dimnames() command to view the current names – more on this another time.</p>
<p>The post <a href="https://dataanalytics.org.uk/naming-rows-and-columns-of-a-matrix-in-r/">Naming rows and columns of a matrix in R</a> appeared first on <a href="https://dataanalytics.org.uk">Data Analytics</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
