Posts

Importing and Exporting Data in R Studio

In this post i am going to talk about importing common data format like Excel/CSV files or Text files in R studio and also how you can export the data out of R studio to Excel,CSV and Text file formats. CSV Files The utils package, which is automatically loaded in R studio on startup, can import CSV files using read.csv function. To import CSV data files we can do it in the following ways: 1) file <- read.csv(file.choose()) This will initiate a pop-up window to open and you can manually choose the desired CSV file. It will create a dataframe named "file". The other important arguments to consider in the above statement are header=True when the CSV file contains header (column names). The default for this argument is always true. Also, an important argument to specify is separator (sep= ) . You have to specify the character that is separating the fields. "," means data is separated by comma. 2) file <- read.csv("file-name.csv",header=,sep=) This state...

Data Structure in R

Image
We will look at five basic data structures that are available in R. Vectors   A vector is the simplest type of data structure in R. Simply put, a vector is a sequence of data elements of the same basic type. Members of a vector are called Components. The elements of a vector are all numbers, giving a numeric vector, or all character values, giving a character vector. A vector can be used to represent a single variable in a data set.   Factors   A collection of values that all come from a fixed set of possible values. A factor is similar to a vector, except that the values within a factor are limited to a fixed set of possible values. A factor can be used to represent a  categorical   variable in a data set.   Matrices   This is a two-dimensional structure (like a data frame), but one where all values are of the same type (like a vector)...