Week 5- R and COVID-19

Jayant Siva
4 min readJul 19, 2021

--

The summer has passed by pretty quickly, and we have arrived at a point where we are learning more of the programming itself. With that said, I started learning more about the R programming language. I’ll place all the information I learned below:

First and foremost, assigning variables is different with R. Instead of using the = sign, we have to now use the -> sign. However, the equals sign can be used as an assignment operator in R — but not all the time.

It’s also different to create arrays with R. An example of the syntax can be found below:

my_vector <- c(1, 1, 2, 3, 5, 8)

One more very important point about the c() function- as you can see above: It assumes that everything in your vector is of the same data type — that is, all numbers or all characters. To create a collection with multiple object types, you need a list, not a vector. You create a list with the list() function, not c(), such as:

My_list <- list(1,4,"hello", TRUE)

Additionally, there are different types of loops in R:

apply() runs a function on either every row or every column of a 2-dimensional matrix where all columns are the same data type. For a 2-D matrix, you also need to tell the function whether you’re applying by rows or by columns: Add the argument 1 to apply by row or 2 to apply by column. For example:

apply(my_matrix, 1, median)

returns the median of every row in my_matrix and

apply(my_matrix, 2, median)

calculates the median of every column.

Additionally, R assumes that 3 is the same class as 3.0 — numeric (i.e., with a decimal point). If you want integer 3, you need to sign it as 3L or with the integer() function. In a situation where this matters to you, you can check what type of number you’ve got by using the class() function:

class(3)

class(3.0)

class(3L)

class(as.integer(3))

R also has special vector and list types that are of special interest when analyzing data, such as matrices and data frames. A matrix has rows and columns; you can find a matrix dimension with dim() such as

dim(my_matrix)

A matrix needs to have all the same data types in every column, such as numbers everywhere.

Data frames are like matrices except one column can have a different data type from another column, and each column must have a name. If you’ve got data in a format that might work well as a database table (or well-formed spreadsheet table), it will also probably work well as an R data frame.

You can think of each row as similar to a database record and each column like a database field in a data frame. You can apply lots of useful functions to data frames, some of which I’ve gone over in earlier sections, such as summary() and the psych package’s describe().

There are several ways to find an object’s underlying data type, but not all of them return the same value. For example, class() and str() will return data.frame on a data frame object, but mode() returns the more generic list.

R doesn’t use semicolons to end a line of code. Instead, R uses line breaks (i.e., new line characters) to determine when an expression has ended.

In addition to saving your entire R workspace with the save.image() function and various ways to save plots to image files, you can save individual objects for use in other software. For example, if you’ve got a data frame just so and would like to share it with colleagues as a tab- or comma-delimited file, say for importing into a spreadsheet, you can use the command:

write.table(myData, "testfile.txt", sep="\t")

This will export all the data from an R object called myData to a tab-separated file called testfile.txt in the current working directory. Changing sep=”\t” to sep=”c” will generate a comma-separated file and so on.

With the above explaining the parts of the syntax of R, I am now going to talk about the parts of the coronavirus!

More information about the structure of SARS-V 2

At their core, coronaviruses contain a genetic blueprint called RNA, similar to DNA. The single-stranded RNA acts as a molecular message that enables the production of proteins needed for other elements of the virus. Bound to this string of RNA are nucleoproteins — proteins that help give the virus its structure and enable it to replicate.

Encapsulating the RNA genome is the viral envelope, which protects the virus when it is outside of a host cell. This outer envelope is made from a layer of lipids, a waxy barrier containing fat molecules. As well as protecting the genes, this layer anchors the different structural proteins needed by the virus to infect cells. Envelope proteins embedded in this layer aid the assembly of new virus particles once it has infected a cell.

The bulbous projections seen on the outside of the coronavirus are spike proteins. This fringe of proteins gives the virus its crown-like appearance under the microscope, from which the Latin name corona is derived. The spike proteins act as grappling hooks that allow the virus to latch onto host cells and crack them open for infection. Like all viruses, coronaviruses are unable to thrive and reproduce outside of a living host.

--

--