StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Comparing Vectors and Lists in R - Essay Example

Cite this document
Summary

This essay "Comparing Vectors and Lists in R" aims at comparing two contrasting data structures in R, a vector which is atomic and list which is generic. R was developed by Ross Ihaka and Robert Gentlemen keeping this in mind. Further, R is open source and free. It makes use of the Object-oriented programming principle which treats data as data objects which have attributes and methods.
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER94.4% of users find it useful
Comparing Vectors and Lists in R
Read Text Preview

Extract of sample "Comparing Vectors and Lists in R"

Comparing Vectors and Lists in R Introduction 1 The R environment. We live in an era of Data Deluge. Automatic data acquisition in several fields like astronomy, Nuclear Physics, Geography etc. has made the conventional methods and tools of data analysis obsolete. The mounting data that is generated by automatic data gathering can be analyzed only by automating the process of data analysis . Computer science has risen to the occasion by coming up with data mining , machine learning algorithms etc. R was developed by Ross Ihaka and Robert Gentlemen keeping this in mind. Further R is open source and free . It makes use of the Object oriented programming principle which treats data as data objects which have attributes and methods which can modify the attributes. Visualising data as graphs ,maps and boxplots is another important requirement . R comes with strong graphical and mapping facilities. “R is an integrated suite of software facilities for data manipulation. R is very much a vehicle for newly developing methods of interactive data analysis. Many consider R as a statistical system. It is an environment in which most of classical and modern statistical techniques have been implemented”.(Venables et al 2009) . “Every thing is an object in R. All Objects are built of a basic set of built-in objects. The type of an object define how it is stored in R. Objects in R also are members of a class. .Classes define what information objects contain and how these objects may be used “.(Adler Joseph 2009) This paper aims at comparing two contrasting data structures in R ,vector which is atomic and list which is generic 2 Vectors Vectors can thought of as the building blocks in R. The philosophy behind R is that data is a vector . Single numbers or values can be thought of as a vector with one element 2.1 Definition Vectors are ordered collection of elements of the same type .Depending on the type of values they contain, they are numeric, character, logical, complex, and raw vectors 2.2 Creating vectors All kinds of vectors can be created using the c(….) function where c stands for combine or concatenate . Numeric vectors containing a sequence of values can be created using the sequence function seq( ) or using the operator :. Vectors can also be created by repetition of elements using rep( ) function(Alder Joseph 2009) 2.2.1 Examples Using c( ) > c(1,2,3,4) [1] 1 2 3 4 Using seq( ) function seq( ) function is used for vectors with equidistant series of numbers (Dalgaard 2008) >seq(from=0,to=2*pi,by=pi/2) [1] 0.000000 1.570796 3.141593 4.712389 6.283185 Using colon operator : > 1:10 [1] 1 2 3 4 5 6 7 8 9 10 Using rep( ) function rep( ) is a function which can be used to replicate an object rep(x, times=5) will create a vector with x repeated 5 times > rep(c(1,2),times=5) [1] 1 2 1 2 1 2 1 2 1 2 2.2.2 Vector Arithmetic and expressions Vectors can be used in arithmetic expressions ,in which case the operations are performed element by element. The elementary arithmetic operators are +,-,*,/ and ^ (Venable etal 2010).Vectors need not be of the same length 2.3 Logical vectors Logical vectors can have values TRUE, FALSE and NA (not available) and can be generated by conditions > x=1:10 > x>5 [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE 2.4 Manipulating the Character vectors The paste( ) function takes an arbitrary number of arguments and concatenates them one by one into a character string.(Venable etal 2010) labs labs [1] "X1" "Y2" "X3" "Y4" "X5" "Y6" "X7" "Y8" "X9" "Y10" 2.5 Extracting values from vectors Subsets of a vector may be selected by appending to the name of the vector an index vector in square brackets. > x=1:100 > x[1:10] [1] 1 2 3 4 5 6 7 8 9 10 The values in a vector can be given names using the names function and values extracted using names as the index > fruit names(fruit) fruit orange apple mango peach 5 1 10 2 > fruit["orange"] orange > fruit names(fruit) fruit orange apple mango peach 5 1 10 2 > fruit["orange"] orange 2.6 Functions available with numeric vectors A lot of built in mathematical functions are available in R which can take a vector as an argument and return another vector as a result .Such functions are called vectorised functions .Such functions make calculating and plotting mathematical functions easy. 2.7 Doing simple Statistics with vectors Statistical quantities like mean, variance, standard deviation etc. are available as built in functions. > height=c(150,160,171,145,180,176,173,142,168,162) > mean(height) [1] 162.7 > var(height) [1] 176.6778 3 Lists 3.1 Lists as Generic Vectors “An R list is an object consisting of an ordered collection of objects known as its components .There is no need for the components to be of the same type.(Venables et al 2010)” 3.2 Creating Lists - examples Lists are created using the list function .Objects in the list can also be named . Components in the list can accessed by the double subscript `i` where i is the position in the list. If the objects in the list are named ,the components can be accessed using listname$component form. This makes list a versatile data structure where it can duplicate as a hash table or dictionary where the values can be accessed by keys . This capability is especially useful where values (say latitude ,longitude) can be accessed using location names as values > Lst Lst`2` [1] 18.8445 > Lst`1` [1] "Mumbai" > Lst["latitude"] $latitude [1] 18.8445 3.3 Data frames –a special kind of a list Data often comes in the form of tables . Tabular data contains columns of equal length where data in each column may be of a different type. This can be easily handled by lists . But R comes with a special type of list called data frames for handling such data A data frame is a list with class “data.frame” .The objects of a data frame may be thought of as column vectors of the same length .Data frames one of the most used data structures in R after vectors. . > weight height weight gender study=data.frame(weight,height,gender) > study weight height gender 1 65 150 Fe 2 61 135 Fe 3 70 210 M 4 65 140 Fe 4 Comparing Lists and Vectors 4.1 Advantages of vectors Vector is the most primitive or fundamental object in R .The simplicity of the vector makes it easier to master it .List, Data frames etc. are made of vectors and can be comprehended easily once the concept of the vector is well understood. For the beginner vector is the ideal R object. All the arithmetic in R is vector based. Mathematical functions are vectorised in the sense that they take a vector as input and generates another vector as output .If x is the argument vector and y is the vector returned by the function .The function plot(x,y) generates a graph of the function. A vector is a one dimensional data set .Hence is the best data structure suited for doing univariate statistics. Vectors require only less disk space and its graphical outputs are more appealing. Vectored data types allows more analysis ability for networks and they allow visually easy and smooth implementation of overlay operations, particularly graphic information like maps (Cook et al 2007) 4.1.1 Examples of where vectors can be appropriately used Vectors can be used to keep track of stock prices and then find the minimum ,maximum and cumulative maximum for a period. > stock1 = c(45,43,46,48,51,46,50,47,46,45) > min(stock1) [1] 43 > max(stock1) [1] 51 > cummax(stock1) [1] 45 45 46 48 51 51 51 51 51 51 > cummin(stock1) [1] 45 43 43 43 43 43 43 43 43 43 vectors can be used to analyze categorical data observed by surveys > smoke=c("yes","no","no","no","yes","no") > table(smoke) smoke no yes 4 2 4.2 Disadvantages of vectors Vectors being primitive or fundamental is not suited for handling real data unless data frames are created out of them When doing arithmetic with vectors the lengths of the vectors should match. > a=c(1,2,3,4) > b=c(4,3,2) > a+b [1] 5 5 5 8 Warning message: In a + b : longer object length is not a multiple of shorter object length 4.3 Advantages of Lists Lists are the most general objects in R. All other objects in R can also be represented as lists with some restrictions. Vector is a list with all the elements of the same type. A list created with integers 1,2,3 will have the class attribute list ,whereas a vector with the same elements will have a class attribute numeric List is a recursive object. That is a list can contain another list . This makes lists highly versatile object that can model complicated systems( I programmer 2010) Lists are useful when the collection is frequently growing and shrinking for example when implementing a queue i.e. adding to the end and removing from the end the lists would be an efficient method to use (Cook et al 2007) 4.3.1 Examples where lists can appropriately be used Real data is heterogeneous and hence in all situations barring the simplest, list can be used for modeling or representing data. Earth quake data can be taken as an example . It contains the magnitude of the quake as a number,the time and date as type time and date ,the place of occurrence as character etc. The quake data can thus be easily represented as a list. 4.3.2 Disadvantages of Lists Lists as such is a generic object and is not the best structure for handling tabular data .But the availability of data frames overcomes this difficulty When the concatenation function c( ) is given list of arguments, the result is an object of type list, whose components are those of the lists joined together in sequence. 5 Conclusions Data takes many forms . Repeated observation of a physical quantity gives numeric values , Place names are character strings only. Geographic data contains both numeric and charcter data . Data analysis often yields Boolean data. Earth quake data is even more versatile. To handle data of different types R has different data structures .Vector is the simplest and list is the most general List is a generic data structure where as a vector is primitive structure. All objects in R can be thought of as lists with restrictions or as constructed out of vectors . Hence mastery of both Lists and vectors is essential for a R user. Vectors use less disk space than lists and are better suited for graphic and network applications . Lists are better suited for data that is growing and shrinking in time . The simplicity of vectors makes it the best choice for beginners. The restriction on the type of the data makes it suitable for numeric data analysis of one variable. Lists are the data structure of choice for multivariate and tabular data . Saving and loading large amounts of data from files is easier with lists. Lists and vectors both have their own strengths and weaknesses References Adler Joseph (2009) R in a Nutshell O’Reilly Tokyo I Programmer 2010 A programmers Guide to R –Data and Objects available at http://www.i-programmer.info/programming/other- languages/1706-a-programmers-guide-to-r.html D. Swayne D.F. and Buja 2007 Interactve and Dynamic Data Analysis with R Springer Verlag Dalgaard Peter 2008 Introductory Statistics with R Springer Venables W.M.,Smith D.M. and the R Development Core Team 2010 An Introduction to R R Development Core Team Verzani John Simple R – Introductory statistics with R available at http://www.math.csi.cuny.edu/Statistics/R/simpleR Read More
Cite this document
  • APA
  • MLA
  • CHICAGO
(Comparing Vectors and Lists in R Essay Example | Topics and Well Written Essays - 1750 words, n.d.)
Comparing Vectors and Lists in R Essay Example | Topics and Well Written Essays - 1750 words. https://studentshare.org/statistics/1583060-describe-the-differences-between-the-r-list-and-vector
(Comparing Vectors and Lists in R Essay Example | Topics and Well Written Essays - 1750 Words)
Comparing Vectors and Lists in R Essay Example | Topics and Well Written Essays - 1750 Words. https://studentshare.org/statistics/1583060-describe-the-differences-between-the-r-list-and-vector.
“Comparing Vectors and Lists in R Essay Example | Topics and Well Written Essays - 1750 Words”. https://studentshare.org/statistics/1583060-describe-the-differences-between-the-r-list-and-vector.
  • Cited: 0 times

CHECK THESE SAMPLES OF Comparing Vectors and Lists in R

Research Brief: Women and Minorities as Strategy

Research Brief: Women and Minorities as Strategy 1.... What are the strategic advantages and disadvantages of having a diverse (e.... .... gender, age, race, etc.... board of directors and executive team?... Diverse board of directors and executive team in a particular workplace of an organization include the individuals possessing different experiences, as well as ways of thinking, cultural backgrounds, ethnicities, departments and being of different age....
4 Pages (1000 words) Research Paper

Understanding project contractors and contracting businesses

This paper involves an in-depth analysis of companies that are basically construction contractors.... The analysis will be done on the basis of key performance indicators (financial ratios) during the period 2005-2011.... hellip; The two firms that have been chosen are Midas Retail Limited and Rock Fall Company Limited based in the United Kingdom whose primary line of operations includes construction and drilling....
13 Pages (3250 words) Essay

The Rationale of Equity Indexation

This paper explains the rationale behind equity indexation as used in investment management and begins with an explanation of the capital market for equities and how it behaves.... Next, equity index and how it is formulated is discussed, before looking at basic forms of investment strategies, how an equity index can be used to form the basis of an investment strategy, and how such a strategy compares with other investment strategies. … A capital market for equities is a place - it can be an actual location such as a stock exchange or virtual such as in a computer - where buyers and sellers agree to buy and sell stocks without the use of financial intermediaries like banks and insurance companies that direct the flow of resources from savers to borrowers....
4 Pages (1000 words) Essay

Enterprise and Business Development

Business can be understood as a group consisting of number of people who joined together for a common purpose for the attainment of pre-defined goals, for the emergence of profit.... Most of the business must accomplish similar functions regardless of the size and legal structure.... hellip; A business plan is a formal statement of a set of business goals and the devising of strategic plans for reaching those goals....
12 Pages (3000 words) Essay

Seventh Grade Math - Textbook and Curriculum

Russell (2009), a Vice Principal of student achievement, lists in her online page the five core topics that must be taught in the seventh grade:NumberThis topic includes factors, multiples, integer amounts, square roots and the four basic operations on fractions, decimals, percents and integers.... Later on this essay, an in-depth examination will be given by comparing the book's contents with Deb Russell's list of basic math concepts that must be learned by students before proceeding to eighth grade....
2 Pages (500 words) Essay

Big Data, IT, Cloud Computing, Analytics and Healthcare

One such sector is the healthcare system.... Technology advances in cloud computing, IT big data and analytics are examples of sectors in technology that have revolutionized the health care system. Big… ata is a compilation of data sets that is very big that it is very difficult to handle and process using traditional database and data processing tools....
10 Pages (2500 words) Essay

Mobile Computing in Retail Stores

This paper will explore how consumers owning modern mobile phones with internet connectivity will affect Agfa's supermarket and how the traditional brick and mortar retail environments like that of Agfa's can use mobile marketing to promote and sell their products.... hellip; Most experts claim that retailers tend to change their point-of-sale terminal installations every 5-7 years....
12 Pages (3000 words) Term Paper

A Comparison between Word and Pictorial Stimuli in Creating False Recognition

The study by Roediger and McDermott (1995) involved exposing test subjects to lists of semantic associates that come together on a lure word.... The paper "A Comparison between Word and Pictorial Stimuli in Creating False Recognition" states that there are still many areas of cognition which overlap with memory and as considerations are given to define them, development will lead to better learning, recognition and memory processes....
9 Pages (2250 words) Assignment
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us