Function to remove NA

master
Marc Gauch 2022-12-02 14:40:39 +01:00
parent 6584495be7
commit fc8d0245bc
2 changed files with 18 additions and 5 deletions

View File

@ -1544,6 +1544,12 @@ and adapted</em></p>
uniqv[which(x == max(x))] uniqv[which(x == max(x))]
}</code></pre> }</code></pre>
</div> </div>
<div id="remove-na" class="section level2" number="2.3">
<h2><span class="header-section-number">2.3</span> Remove NA</h2>
<pre class="r"><code>removeNA &lt;- function(d){
return(d[!is.na(d)])
}</code></pre>
</div>
</div> </div>
<div id="load-data" class="section level1" number="3"> <div id="load-data" class="section level1" number="3">
<h1><span class="header-section-number">3</span> Load Data</h1> <h1><span class="header-section-number">3</span> Load Data</h1>
@ -2392,9 +2398,8 @@ gibt.</p>
<div id="selbststudium-2.1" class="section level1" number="6"> <div id="selbststudium-2.1" class="section level1" number="6">
<h1><span class="header-section-number">6</span> Selbststudium 2.1</h1> <h1><span class="header-section-number">6</span> Selbststudium 2.1</h1>
<p>We have the year 2021 ## Preparation</p> <p>We have the year 2021 ## Preparation</p>
<pre class="r"><code>birthyears &lt;- litdata$D7 <pre class="r"><code># remove NAs
# remove NAs birthyears &lt;- removeNA(litdata$D7)
birthyears &lt;- birthyears[!is.na(birthyears)]
age &lt;- 2021 - birthyears</code></pre> age &lt;- 2021 - birthyears</code></pre>
<div id="frequency" class="section level2" number="6.1"> <div id="frequency" class="section level2" number="6.1">
<h2><span class="header-section-number">6.1</span> Frequency</h2> <h2><span class="header-section-number">6.1</span> Frequency</h2>

View File

@ -71,6 +71,15 @@ getmode <- function(v) {
} }
``` ```
## Remove NA
```{r}
removeNA <- function(d){
return(d[!is.na(d)])
}
```
# Load Data # Load Data
## Load from CSV ## Load from CSV
``` {r loadData} ``` {r loadData}
@ -352,9 +361,8 @@ displayFunction1(litdata, "D8")
We have the year 2021 We have the year 2021
## Preparation ## Preparation
```{r} ```{r}
birthyears <- litdata$D7
# remove NAs # remove NAs
birthyears <- birthyears[!is.na(birthyears)] birthyears <- removeNA(litdata$D7)
age <- 2021 - birthyears age <- 2021 - birthyears
``` ```