Skip to main content

R: How to Encode your Data?

Every experiment starts with data, so the question is "how do you enter your data into R?". Well there are many ways to do that, but for this post, we will only consider the two functions below:
  • The concatenate, c; and,
  • the data.frame functions.
The concatenate function, c, is use for combining data points into single numeric R object, known as the vector. The usage of this function is simply

Where ... is the objects to be concatenated. Run ?c, for description of the second argument. Let's try an example,

What happened here is that, we defined a new object, vec1, into the workspace. We can then start manipulating the entries, say using the summary,

For dispersion, try this,

What about the data.frame function? If the first function combines data points into a single vector, data.frame from the name itself constructs a frame of data points. Here is an example,

What we did here is we defined two R objects, the weights and volunteers, then we combine the two into a table like structure, called the data frame. To extract columns of data1, try this,

And the mean of the weights is,

Comments