The Ring programming language version 1.2 book - Part 24 of 84Mahmoud Samir Fayed
The document describes various functions available in the Ring standard library (stdlib.ring). It provides 37 functions organized into categories like math functions, string functions, date functions, etc. Each function includes its syntax, description and an example of its usage. Some key functions described are: evenorodd() to check if a number is even or odd, factors() to compute factors of a number, matrixmulti() to multiply matrices, and dayofweek() to get the day of the week from a date.
The document defines data as values of variables that belong to a set of items. It discusses that data is the second most important thing in data science after the question. Having data does not ensure finding answers without a question to guide the analysis. It then provides an overview of topics in R programming for data extraction, exploration, modeling, and machine learning.
This document provides an overview of the statistical programming language R. It discusses key R concepts like data types, vectors, matrices, data frames, lists, and functions. It also covers important R tools for data analysis like statistical functions, linear regression, multiple regression, and file input/output. The goal of R is to provide a large integrated collection of tools for data analysis and statistical computing.
The document outlines various statistical and data analysis techniques that can be performed in R including importing data, data visualization, correlation and regression, and provides code examples for functions to conduct t-tests, ANOVA, PCA, clustering, time series analysis, and producing publication-quality output. It also reviews basic R syntax and functions for computing summary statistics, transforming data, and performing vector and matrix operations.
R is a programming language and software environment for statistical analysis and graphics. It allows for effective data manipulation, storage, and graphical display. Some key features of R include being free and open source with many contributed packages, having simple yet elegant code, and the ability to perform statistical analysis and visualization. The R studio interface has components for running code in the console, editing code in the editor, and viewing outputs like plots and help documentation. Common data structures in R include vectors, matrices, lists, and data frames.
Json and SQL DB serialization Introduction with Play! and SlickStephen Kemmerling
The document discusses how to build a contacts service that stores contact information in a database and exposes it via JSON endpoints. It describes creating case classes to represent contacts and emails in Scala, implementing JSON serialization and deserialization using Play JSON, defining a database schema using Slick, and writing methods to save contacts to and load them from the database.
A high level introduction to R statistical programming language that was presented at the Chicago Data Visualization Group's Graphing in R and ggplot2 workshop on October 8, 2012.
R is a free and open-source programming language for statistical analysis and graphics. It allows users to import, clean, transform, visualize and model data. Key features of R include its large collection of statistical and graphical techniques, ability to easily extend its functionality through user-contributed packages, and open-source nature which allows for free use and development. The document provides instructions on installing R, getting started with the R interface and commands, and an overview of common functions and operations for data analysis, visualization and statistics.
The Ring programming language version 1.2 book - Part 24 of 84Mahmoud Samir Fayed
The document describes various functions available in the Ring standard library (stdlib.ring). It provides 37 functions organized into categories like math functions, string functions, date functions, etc. Each function includes its syntax, description and an example of its usage. Some key functions described are: evenorodd() to check if a number is even or odd, factors() to compute factors of a number, matrixmulti() to multiply matrices, and dayofweek() to get the day of the week from a date.
The document defines data as values of variables that belong to a set of items. It discusses that data is the second most important thing in data science after the question. Having data does not ensure finding answers without a question to guide the analysis. It then provides an overview of topics in R programming for data extraction, exploration, modeling, and machine learning.
This document provides an overview of the statistical programming language R. It discusses key R concepts like data types, vectors, matrices, data frames, lists, and functions. It also covers important R tools for data analysis like statistical functions, linear regression, multiple regression, and file input/output. The goal of R is to provide a large integrated collection of tools for data analysis and statistical computing.
The document outlines various statistical and data analysis techniques that can be performed in R including importing data, data visualization, correlation and regression, and provides code examples for functions to conduct t-tests, ANOVA, PCA, clustering, time series analysis, and producing publication-quality output. It also reviews basic R syntax and functions for computing summary statistics, transforming data, and performing vector and matrix operations.
R is a programming language and software environment for statistical analysis and graphics. It allows for effective data manipulation, storage, and graphical display. Some key features of R include being free and open source with many contributed packages, having simple yet elegant code, and the ability to perform statistical analysis and visualization. The R studio interface has components for running code in the console, editing code in the editor, and viewing outputs like plots and help documentation. Common data structures in R include vectors, matrices, lists, and data frames.
Json and SQL DB serialization Introduction with Play! and SlickStephen Kemmerling
The document discusses how to build a contacts service that stores contact information in a database and exposes it via JSON endpoints. It describes creating case classes to represent contacts and emails in Scala, implementing JSON serialization and deserialization using Play JSON, defining a database schema using Slick, and writing methods to save contacts to and load them from the database.
A high level introduction to R statistical programming language that was presented at the Chicago Data Visualization Group's Graphing in R and ggplot2 workshop on October 8, 2012.
R is a free and open-source programming language for statistical analysis and graphics. It allows users to import, clean, transform, visualize and model data. Key features of R include its large collection of statistical and graphical techniques, ability to easily extend its functionality through user-contributed packages, and open-source nature which allows for free use and development. The document provides instructions on installing R, getting started with the R interface and commands, and an overview of common functions and operations for data analysis, visualization and statistics.
The document discusses object-oriented programming in Python. It defines key OOP concepts like classes, objects, and methods. It provides examples of defining classes and methods in Python. It also covers inheritance, polymorphism, and data abstraction in OOP. Database programming in Python is also discussed, including connecting to databases and performing CRUD operations using the Python DB API.
Learn to manipulate strings in R using the built in R functions. This tutorial is part of the Working With Data module of the R Programming Course offered by r-squared.
This document discusses various functions in R for exporting data, including print(), cat(), paste(), paste0(), sprintf(), writeLines(), write(), write.table(), write.csv(), and sink(). It provides descriptions, syntax, examples, and help documentation for each function. The functions can be used to output data to the console, files, or save R objects. write.table() and write.csv() convert data to a data frame or matrix before writing to a text file or CSV. sink() diverts R output to a file instead of the console.
This document provides examples of different R data structures including vectors, matrices, lists, and data frames. Vectors are one-dimensional arrays that can contain only one data type. Matrices are two-dimensional arrays that can contain only one data type. Lists are collections of elements that can contain different data types. Data frames are two-dimensional structures similar to tables or spreadsheets that can contain different data types across rows and columns. The document demonstrates how to create, subset, and manipulate each of these structures through examples.
The Ring programming language version 1.9 book - Part 41 of 210Mahmoud Samir Fayed
This document provides summaries of Ring programming functions related to classes and objects. It describes functions for getting class names and checking class definitions, getting classes within packages, and checking class and attribute definitions. It also summarizes functions for working with objects, including getting/setting attributes and methods, checking if an object or attribute exists, and adding attributes and methods to objects. Examples are provided to demonstrate the usage of each function.
The Ring programming language version 1.7 book - Part 39 of 196Mahmoud Samir Fayed
The document provides documentation on various functions in the Ring programming language stdlib related to string manipulation, lists, stacks, queues, hashtables and other data types and classes. It includes the syntax and examples of using over 45 functions and methods, such as TrimLeft() and TrimRight() to remove spaces from strings, ListAllFiles() to get files in a folder, and classes for common data types like strings, lists, stacks and queues with methods like add(), remove(), sort() etc.
The document discusses SQL Server 2005 and includes the following sections:
1. An introduction to SQL basics including data types, functions, identifiers, and comments
2. Examples of installing SQL Server 2005 and practicing sample queries
3. Details about different data types in SQL like numeric, string, date/time, and binary data types
The Ring programming language version 1.7 book - Part 41 of 196Mahmoud Samir Fayed
This document discusses using nested structures and object composition in Ring to enable declarative programming. It shows how to:
1. Create objects inside lists and add objects to lists.
2. Return objects and lists by reference from methods to avoid copies.
3. Execute a "BraceEnd()" method after accessing an object with braces {} to run cleanup code.
4. Build a declarative programming environment on top of Ring's object orientation features using nested structures, returning references, and BraceEnd() methods.
It covers- Introduction to R language, Creating, Exploring data with Various Data Structures e.g. Vector, Array, Matrices, and Factors. Using Methods with examples.
This document provides 7 habits for writing more functional Swift code. It discusses avoiding mutability and for-loops in favor of map, filter and reduce functions. It also covers being lazy, currying functions, writing domain-specific languages, and thinking about code in terms of data and functions rather than objects.
This document provides an introduction to the R programming language. It discusses that R was created in the 1990s and is based on the S language. R is an interpreted, high-level language that supports multiple programming paradigms. The document then covers getting started with R, choosing an integrated development environment, using R as a calculator, assigning variables, comments, getting help, basic data types, and various data structures in R including vectors, matrices, arrays, and lists.
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
This document provides examples and explanations for common questions about using Ring programming language. It demonstrates how to summarize uninitialized variables, print lists containing objects, insert items into lists, print new lines and characters, create GUI applications using Qt, work with modal windows, and connect to SQLite and other databases using ODBC. Various functions, classes and concepts in Ring like Try/Catch, NULL, ISNULL(), lists, Qt classes and ODBC are explained through code examples.
The Ring programming language version 1.6 book - Part 35 of 189Mahmoud Samir Fayed
This document provides a summary of Ring object-oriented programming functions including:
- Functions to get class, object, and attribute information like classname(), objectid(), isobject(), attributes()
- Functions to add/remove attributes and methods like addattribute(), addmethod()
- Functions to get/set attribute values like getattribute(), setattribute()
- Other functions like mergemethods() to share methods between classes, and packagename() to get the imported package name
The document explains each function and provides examples of their usage.
The Ring programming language version 1.4.1 book - Part 10 of 31Mahmoud Samir Fayed
The Math class contains methods for common mathematical functions like trigonometric, exponential, logarithmic and other functions. Some examples shown include calculating the sine, cosine and tangent of angles in both radians and degrees, as well as calculating exponentials, logarithms, and other functions. The random() method generates random numbers within a range.
This hands-on R course will guide users through a variety of programming functions in the open-source statistical software program, R. Topics covered include indexing, loops, conditional branching, S3 classes, and debugging. Full workshop materials available from http://projects.iq.harvard.edu/rtc/r-prog
The Ring programming language version 1.5.2 book - Part 32 of 181Mahmoud Samir Fayed
The document provides documentation on Ring programming language functions for working with classes, objects, attributes and methods. It summarizes over 40 functions, including classes() to get class names, isclass() to check if a class exists, packageclasses() to get classes in a package, addattribute() to add attributes to an object, and getattribute()/setattrbute() to get/set attribute values. Examples are given for each function.
The goal of this workshop is to introduce fundamental capabilities of R as a tool for performing data analysis. Here, we learn about the most comprehensive statistical analysis language R, to get a basic idea how to analyze real-word data, extract patterns from data and find causality.
- R is a free software environment for statistical computing and graphics. It has an active user community and supports graphical capabilities.
- R can import and export data, perform data manipulation and summaries. It provides various plotting functions and control structures to control program flow.
- Debugging tools in R include traceback, debug, browser and trace which help identify and fix issues in functions.
The document discusses object-oriented programming in Python. It defines key OOP concepts like classes, objects, and methods. It provides examples of defining classes and methods in Python. It also covers inheritance, polymorphism, and data abstraction in OOP. Database programming in Python is also discussed, including connecting to databases and performing CRUD operations using the Python DB API.
Learn to manipulate strings in R using the built in R functions. This tutorial is part of the Working With Data module of the R Programming Course offered by r-squared.
This document discusses various functions in R for exporting data, including print(), cat(), paste(), paste0(), sprintf(), writeLines(), write(), write.table(), write.csv(), and sink(). It provides descriptions, syntax, examples, and help documentation for each function. The functions can be used to output data to the console, files, or save R objects. write.table() and write.csv() convert data to a data frame or matrix before writing to a text file or CSV. sink() diverts R output to a file instead of the console.
This document provides examples of different R data structures including vectors, matrices, lists, and data frames. Vectors are one-dimensional arrays that can contain only one data type. Matrices are two-dimensional arrays that can contain only one data type. Lists are collections of elements that can contain different data types. Data frames are two-dimensional structures similar to tables or spreadsheets that can contain different data types across rows and columns. The document demonstrates how to create, subset, and manipulate each of these structures through examples.
The Ring programming language version 1.9 book - Part 41 of 210Mahmoud Samir Fayed
This document provides summaries of Ring programming functions related to classes and objects. It describes functions for getting class names and checking class definitions, getting classes within packages, and checking class and attribute definitions. It also summarizes functions for working with objects, including getting/setting attributes and methods, checking if an object or attribute exists, and adding attributes and methods to objects. Examples are provided to demonstrate the usage of each function.
The Ring programming language version 1.7 book - Part 39 of 196Mahmoud Samir Fayed
The document provides documentation on various functions in the Ring programming language stdlib related to string manipulation, lists, stacks, queues, hashtables and other data types and classes. It includes the syntax and examples of using over 45 functions and methods, such as TrimLeft() and TrimRight() to remove spaces from strings, ListAllFiles() to get files in a folder, and classes for common data types like strings, lists, stacks and queues with methods like add(), remove(), sort() etc.
The document discusses SQL Server 2005 and includes the following sections:
1. An introduction to SQL basics including data types, functions, identifiers, and comments
2. Examples of installing SQL Server 2005 and practicing sample queries
3. Details about different data types in SQL like numeric, string, date/time, and binary data types
The Ring programming language version 1.7 book - Part 41 of 196Mahmoud Samir Fayed
This document discusses using nested structures and object composition in Ring to enable declarative programming. It shows how to:
1. Create objects inside lists and add objects to lists.
2. Return objects and lists by reference from methods to avoid copies.
3. Execute a "BraceEnd()" method after accessing an object with braces {} to run cleanup code.
4. Build a declarative programming environment on top of Ring's object orientation features using nested structures, returning references, and BraceEnd() methods.
It covers- Introduction to R language, Creating, Exploring data with Various Data Structures e.g. Vector, Array, Matrices, and Factors. Using Methods with examples.
This document provides 7 habits for writing more functional Swift code. It discusses avoiding mutability and for-loops in favor of map, filter and reduce functions. It also covers being lazy, currying functions, writing domain-specific languages, and thinking about code in terms of data and functions rather than objects.
This document provides an introduction to the R programming language. It discusses that R was created in the 1990s and is based on the S language. R is an interpreted, high-level language that supports multiple programming paradigms. The document then covers getting started with R, choosing an integrated development environment, using R as a calculator, assigning variables, comments, getting help, basic data types, and various data structures in R including vectors, matrices, arrays, and lists.
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
This document provides examples and explanations for common questions about using Ring programming language. It demonstrates how to summarize uninitialized variables, print lists containing objects, insert items into lists, print new lines and characters, create GUI applications using Qt, work with modal windows, and connect to SQLite and other databases using ODBC. Various functions, classes and concepts in Ring like Try/Catch, NULL, ISNULL(), lists, Qt classes and ODBC are explained through code examples.
The Ring programming language version 1.6 book - Part 35 of 189Mahmoud Samir Fayed
This document provides a summary of Ring object-oriented programming functions including:
- Functions to get class, object, and attribute information like classname(), objectid(), isobject(), attributes()
- Functions to add/remove attributes and methods like addattribute(), addmethod()
- Functions to get/set attribute values like getattribute(), setattribute()
- Other functions like mergemethods() to share methods between classes, and packagename() to get the imported package name
The document explains each function and provides examples of their usage.
The Ring programming language version 1.4.1 book - Part 10 of 31Mahmoud Samir Fayed
The Math class contains methods for common mathematical functions like trigonometric, exponential, logarithmic and other functions. Some examples shown include calculating the sine, cosine and tangent of angles in both radians and degrees, as well as calculating exponentials, logarithms, and other functions. The random() method generates random numbers within a range.
This hands-on R course will guide users through a variety of programming functions in the open-source statistical software program, R. Topics covered include indexing, loops, conditional branching, S3 classes, and debugging. Full workshop materials available from http://projects.iq.harvard.edu/rtc/r-prog
The Ring programming language version 1.5.2 book - Part 32 of 181Mahmoud Samir Fayed
The document provides documentation on Ring programming language functions for working with classes, objects, attributes and methods. It summarizes over 40 functions, including classes() to get class names, isclass() to check if a class exists, packageclasses() to get classes in a package, addattribute() to add attributes to an object, and getattribute()/setattrbute() to get/set attribute values. Examples are given for each function.
The goal of this workshop is to introduce fundamental capabilities of R as a tool for performing data analysis. Here, we learn about the most comprehensive statistical analysis language R, to get a basic idea how to analyze real-word data, extract patterns from data and find causality.
- R is a free software environment for statistical computing and graphics. It has an active user community and supports graphical capabilities.
- R can import and export data, perform data manipulation and summaries. It provides various plotting functions and control structures to control program flow.
- Debugging tools in R include traceback, debug, browser and trace which help identify and fix issues in functions.
The document provides an overview of object-oriented programming concepts in Python including defining classes, inheritance, methods, and data structures. Some key points:
- Classes define user-created data types that bundle together data (attributes) and functions (methods) that work with that data. Objects are instances of classes.
- Methods are defined within classes and must have "self" as the first argument to access attributes. The __init__ method serves as a constructor.
- Inheritance allows subclasses to extend existing classes, redefining or calling parent methods.
- Python supports lists, tuples, dictionaries, sets and other data structures that can be used to store and organize data. Lists are mutable while tuples are immutable.
Esoft Metro Campus - Diploma in Web Engineering - (Module VII) Advanced PHP Concepts
(Template - Virtusa Corporate)
Contents:
Arrays
Indexed Arrays
Associative Arrays
Multidimensional arrays
Array Functions
PHP Objects and Classes
Creating an Object
Properties of Objects
Object Methods
Constructors
Inheritance
Method overriding
PHP Strings
printf() Function
String Functions
PHP Date/Time Functions
time() Function
getdate() Function
date() Function
mktime() function
checkdate() function
PHP Form Handling
Collecting form data with PHP
GET vs POST
Data validation against malicious code
Required fields validation
Validating an E-mail address
PHP mail() Function
Using header() function to redirect user
File Upload
Processing the uploaded file
Check if File Already Exists
Limit File Size
Limit File Type
Check if image file is an actual image
Uploading File
Cookies
Sessions
The document discusses importing and exporting data in R. It describes how to import data from CSV, TXT, and Excel files using functions like read.table(), read.csv(), and read_excel(). It also describes how to export data to CSV, TXT, and Excel file formats using write functions. The document also demonstrates how to check the structure and dimensions of data, modify variable names, derive new variables, and recode categorical variables in R.
This document provides an overview of a lecture on R. The lecture will cover what R is and why to use it, setting up R and RStudio, performing calculations and functions in R, handling files and creating plots and graphics, performing statistical analyses, and writing functions. It also discusses R's strengths like data management, statistics, graphics, and its active user community, as well as weaknesses like not being very user friendly initially and being slower than other programming languages.
Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1ZW7TDL.
Richard Dallaway shows an example of what Scala looks like when using pattern matching over classes, how to encode an idea into types and use advanced features of Scala without complicating the code. Filmed at qconlondon.com.
Richard Dallaway is a partner at Underscore -- a consultancy specializing in Scala, especially the type-driven and functional aspects of Scala. He works on client projects writing software and helping teams deliver software with Scala. His focus is on the web, machine learning, and code review. He's the co-author of "Essential Slick" (Underscore), and author of the "Lift Cookbook" (O'Reilly).
fINAL Lesson_5_Data_Manipulation_using_R_v1.pptxdataKarthik
Anna is a junior data scientist working on a customer retention strategy. She needs to analyze data from different sources to understand customer value. To efficiently perform her job, she needs to learn techniques for reading, merging, summarizing and preparing data for analysis in R. These include reading data from files and databases, merging tables, summarizing data using functions like mean, median, and aggregate, and exporting cleaned data.
The Ring programming language version 1.5.2 book - Part 33 of 181Mahmoud Samir Fayed
This document provides summaries of various functions available in the Ring standard library (stdlib). It describes functions for input/output like print(), puts(), getstring(), as well as string functions like split(), capitalized(), startswith(), endswith(). It also covers list functions like map(), filter(), value(), mathematical functions like factorial(), fibonacci(), and file functions like file2list(), list2file(). Examples are given to demonstrate the usage of each function.
This document provides an overview of statistical concepts and analysis techniques in R, including measures of central tendency, data variability, correlation, regression, and time series analysis. Key points covered include mean, median, mode, variance, standard deviation, z-scores, quartiles, standard deviation vs variance, correlation, ANOVA, and importing/working with different data structures in R like vectors, lists, matrices, and data frames.
The Ring programming language version 1.8 book - Part 39 of 202Mahmoud Samir Fayed
This document provides documentation on Ring programming language functions from the stdlib library. It describes functions for input/output like print(), puts(), getstring(), mathematical functions like factorial(), fibonacci(), type checking functions like isprime(), and more. Examples are given showing how to use each function.
This document contains a presentation on self-learning modules in Python. It discusses:
1. Assigning modules to different students for learning.
2. Modules, packages, and libraries as different ways to reuse code in Python. A module is a file with the .py extension, a package is a folder containing modules, and a library is a collection of packages.
3. The Python standard library contains built-in functions and modules that are part of the Python installation. Common modules discussed include math, random, and urllib.
statistical computation using R- an intro..Kamarudheen KV
This presentation deals with some basics of R language. It is very useful for benners in R. It describes the basics in a very easy manner, so those who are not familiar with R it would be very helpful.
The Ring programming language version 1.6 book - Part 33 of 189Mahmoud Samir Fayed
The document provides documentation on Ring programming language features including functions, operators, inheritance, dynamic attributes, packages, printing objects, finding and sorting lists of objects, using self and this, and functional programming concepts like pure functions, first-class functions, higher-order functions, and anonymous functions.
Avoiding Bad Database Surprises: Simulation and Scalability - Steven LottPyData
The document discusses how to avoid bad database surprises through early simulation and scalability testing. It provides examples of web and analytics apps that did not scale due to unanticipated database issues. It recommends using Python classes and JSON schema to define data models and generate synthetic test data. This allows simulating the full system early in development to identify potential performance bottlenecks before real data is involved.
The Ring programming language version 1.6 book - Part 37 of 189Mahmoud Samir Fayed
This document describes various functions available in the Ring programming language's standard library (stdlib). It provides documentation on functions for string manipulation, mathematical operations, date/time, file handling, and more. Some key classes covered include the String, List, Math, DateTime, and File classes. Examples are provided for many functions to demonstrate their usage and output.
Class 12 Computer Science, Chapter 4 - Using Python Libraries. Self learning Presentation in the form of Teacher - Student conversation.
Size 20.1 MB ppt format is also available at the same site Size 5.4 MB
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataKiwi Creative
Harness the power of AI-backed reports, benchmarking and data analysis to predict trends and detect anomalies in your marketing efforts.
Peter Caputa, CEO at Databox, reveals how you can discover the strategies and tools to increase your growth rate (and margins!).
From metrics to track to data habits to pick up, enhance your reporting for powerful insights to improve your B2B tech company's marketing.
- - -
This is the webinar recording from the June 2024 HubSpot User Group (HUG) for B2B Technology USA.
Watch the video recording at https://youtu.be/5vjwGfPN9lw
Sign up for future HUG events at https://events.hubspot.com/b2b-technology-usa/
The Ipsos - AI - Monitor 2024 Report.pdfSocial Samosa
According to Ipsos AI Monitor's 2024 report, 65% Indians said that products and services using AI have profoundly changed their daily life in the past 3-5 years.
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...sameer shah
"Join us for STATATHON, a dynamic 2-day event dedicated to exploring statistical knowledge and its real-world applications. From theory to practice, participants engage in intensive learning sessions, workshops, and challenges, fostering a deeper understanding of statistical methodologies and their significance in various fields."
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...Social Samosa
The Modern Marketing Reckoner (MMR) is a comprehensive resource packed with POVs from 60+ industry leaders on how AI is transforming the 4 key pillars of marketing – product, place, price and promotions.
Monthly Management report for the Month of May 2024
R environment
1.
2. Introduction to R
Free software console environment
Statistic computing and graphics
Open Source
Expanded over the world
Base Package
Some data and graphic analysis
Can be extended with other packages
3. Pro & Cons R
Pro
Free
Versatile and dynamic
Open source (many packages)
Cons
Command line
5. Overview of R
Three main windows
Console
Editor
graphics
6. Scripts
A command written in R editor are known as script
Several advantages
Possibility to save commands in a file
Reload the same anaysis
Reuse old scripts to create new ones
Edit the commands directly
7. Basics: objects and functions
What are typed into the console is named “command”
Command is composed by two parts, separated by “<-”
Objects
Functions
“object is created from function”
Object can be: variable, collection, model, graphic, …
Function: thing to create objects
object <- function
8. Examples
Object: var 1, Function: 25
Object: var 2, Function: string “Hello”
Object: var 3, Function: c(….)
c() (concatenate): groups more elements in a single object
var1 <- 25
var2 <- “Hello”
var3 <- c(“Hello”, “World”)
9. Examples
To display the contents of an object in the console, we
type its name
Be careful: R is case sensitive
student is different from Student
students <- c(“Adam”, “Kate”, “Paul”)
students
[1] “Adam” “Kate” “Paul”
10. Workspace
All the objects are stored in memory
The collection of objects is named workspace
When we quit R, it will ask to choose if to save the
workspace
Saving the workspace, the contents of the console
window and any objects that have been created are
saved.
11. Add & Remove
We can insert and remove elements from an object
Add: c(object, newElement)
I added “John” into students
Delete: object[object != elementToRemove]
I removed “John” from students
students <- c(students, “John”)
students <- students[students != “John”]
12. Variables
Collections of values (numeric and not)
A value into an object
A value can be a string or a number
If string we must place the value in quotes ( “ ” ).
More values into an object
Object1 is a numeric variable
Object2 is a string variable
myobject <- 20 myobject <- “hello”
object1 <- c(10, 20, 30, 40)
object2 <- c(“adam”, “john”, “lisa”)
13. Dataframes
Objects containing variables
combines more objects into a single one
data.frame() function
To view the content of the dataframe we can just write
its name
obj1 <- c(“Steve”, “Jim”) obj2 <- c(35, 25)
container <- data.frame(Name = obj1, Age = obj2)
container
Name Age
1 Steve 35
2 Jim 25
14. Dataframes
Dataframe in previous example has two variables:
Names and Age
We can refer to these variables unsing $
We can add a new variable in a dataframe
container$Age
[1] 35 25
container$Job <- c(“Teacher”, “Engineer”)
container
Name Age Job
1 Steve 35 Teacher
2 Jim 25 Engineer
15. Dataframes
We can list the variable in the dataframe
names() function
names(container)
[1] “Name” “Age” “Work”
16. Calculate new variables
Calculate new variable from other ones
We can use mathematic operations on dataframe’s
variables ( +, -, /, *, …)
scoreExA <- c(12, 15, 9, 10)
scoreExB <- c(17, 15, 6, 12)
scores <- data.frame(class1 = scoreExA, class2 = scoreExB)
scores$sumScores <- scores$class1 + scores$class2
scores
class1 class2 sumScores
1 12 17 29
2 15 15 30
3 9 6 15
4 10 12 22
17. Wide format
We must insert new sets of data in a logical way
The most logical way is known as wide format
In wide format
each row represent data from one entity (samples)
each column represents a variable
Example
I want to examine the performance of a group of people
in a test, indicating their sex.
We have two column: “result of test” and “gender”
We have several rows that are the partecipants
19. Factor
Before we have used a “gender” variable
The column with the information about the gender is
called a “grouping variable” or factor
A factor is a variable that groups different entities
Very often a factor is a numeric variable (levels)
Example: we decide if a person is a male, we give the
number 0, if a person is a female we give the number 1
This feature can be useful in order to split up the data
Separated analysis of males and females
20. Factor
Example: we have 10 students, 4 females and 6 males.
We need to enter a series of 0s and 1s.
Useful function: rep()
gender <- c(0,0,0,0,1,1,1,1,1,1)
gender <- c(rep(0, 4), rep(1, 6))
gender
[1] 0 0 0 0 1 1 1 1 1 1
21. Factor
To turn this variable into a factor we use: factor()
gender <- factor(gender, levels=c(0,1),
labels=c(“Female”, “Male”))
gender
[1] Female Female Female Female Male Male
Male Male Male Male
22. Date variable
To create a date variable we use the function
as.Date()
The date format is the same as a string, but has a
particular format
Allows to calculate differences (days)
. How to make a date variable:
1. Write the date as a text string: “YYYY-MM-DD”
2. Use as.Date(object) function
birthDate <- as.Date(c(“1987-01-12”, “1990-05-20”, “1988-03-04”))
23. Missing values
Often, missing data can occur in a set of values
Examples:
Some partecipants miss out a question
There is not signal result at certain times
…
We have to tell R that a value is missing
The code used is “NA” (not available)
testResults <- c(12, 30, NA, 25, NA, 10, 34)
job <- c(“Teacher”, NA, “Waiter”, “Sales girl)
24. Select part of data
We can select small portion of a dataframe
Select particular variables (some columns)
Select a subset of cases (some rows)
General command: [rows, columns]
Examples
newDF <- oldDF[rows, columns]
names <- people[, “name”]
names&ages <- people[, c(“name”, “age”)]
25. Select part of data
Examples
I want the names of all the people that have an age
greater than 20
names <- people[age > 20, “name”]
26. Select part of data
Another way: subset() function
Examples
newDF <- subset(oldDF, conditions, select = c(list of
variables))
success <- subset(students, score >= 18, select = c(“Name”,
“Surname”, “Score”))
27. Working directory
There is a default directory of R, named workind
directory
Tipically is: "C:/Users/username/Documents“
(Windows)
We can check the working dir with getwd() function
We can change the default directory: setwd()
getwd()
[1] “C:/Users/daniele/Documents”
setwd(“C:/Users/daniele/R/Examples”)
getwd()
[1] “C:/Users/daniele/R/Examples”
28. Import and export data
We can import data from Excel, OpenOffice, SPSS, …
Usually data imported are in a dataframe format
Two common types of files
Text (tab-delimited text): read.delim()
CSV (comma-delimited tex): read.csv()
textdata <- read.delim(“data.dat”, header=TRUE)
csvdata <- read.csv(“students.cvs”, header=TRUE)
29. Import and export data
We can export data to a variety of formats
Two way to export
General form: write.table()
CSV (comma-delimited tex): write.csv()
Separator is “ , “ as the default
write.csv(dataframe, “data.csv”)
write.table(dataframe, “file.txt”, sep=“t”, row.names=FALSE)
Editor's Notes
Im going to describe R environment. A sw that we will use to do some computations, data analysis, and so on
Is a free software, we can download it from official webside or other mirrors.
With this sw we can perform several statistic, mathematics, computations.
We can obtain Analitical or graphical results.
Opens source: unlike commercial (choemmerscial) software agency, who develop R allows every one to access their code, to modify it and so, in short, contribute to the software delopment.
R is provided as a basic package with the most useful functions. We can already…. However we can add some other packages to expand the number of feature in R.
Other packages, that add new functionalities to the program.
The main advantage is that R is free. Anybody can use this software right away (subito) and modify it because is also an open source software. (mostly /above all is open source)
The downside/disadvatage, regards the use/usability of this. Since there is a command line console and not a GUI, for some people it is difficult.
To install R in our computer we just need to download it from this website, and select the platform (linux, windows and mac).
Then we select the version (tipically the last version) and install it in the machine.
When we start the application, we can see three main windows: console, editor, and graphics.
Console is where we put and execute the commands and see the results.
editor is a windows where we can write our commands and then edit and reuse them. it is lust like a block note.
Finally we have graphic that produces some graphics, graph and so on.
The console is the main window where we can execute the commands. but an useful way to write and execute commands is through the editor. A command, or a set of commands written in the editor are known as script.
there are some advantages to use the editor:
reexecute the same commands for other data,
and we can modify, or correct the commands in the editor.
As i sad before, … come back to the command
less than / lower and dash/hypen. the two parts are object and function.
as shown in the example below.
This particular structure, This means “is created from” .
Ano object is anything created in R, can be…
Functions are things that we make in R to create objects.
where i put 25 into the var 1, that is created. This object is stored in the memory, and so we can refer this one in a future time.
The third example uses a function called c(), naming concatenate function. that assembles more elements into a single object. take a look in the example where in var3 two elements are concatenated.
This is another example. I put three strings into a variable called students.
we just have to type the name of the variable.
We must to be careful because R is case sensitive. for instance if we write a variable named students in lowercase and another one named student with upper case, they are two different variables.
And what is shown on the console window..
We start exploring the characteristics of the various commands that we can write.
In a set of elements that we have created with the c function, we can insert or remove some elements.
add element using this command function c that concatenates the same object with the element that we want to insert.
To remove an object we use this command that means: we recreate the students but get rid the element john.
Several = severol
A variable can be a string variable or a numeric variable.
string values should always be placed inside the quotes and this tells R that this data is not numeric,
This feature discriminate a string form a number value.
Series = siris
.
dataframe is a container that groups different variables. In this way we can combine more objects into a single one. A dataframe id displayed like a spreadsheet in exel, where we have columns and rows.
With this command we create a new object container and then we tell R how to build the dataframe.
Espacially if we have many data, we may need
using also $. for example i want to insert a variable named job. using the c function i put the two jobs to the elements.
sometimes it is useful to list the variables in a dataframe, for instance when we have a large dataframe. this ca be done using the names() function. specifying the name of the dataframe within the bracket.
We can also use arithmetic operators to compute and create new variables in a dataframe. and these variables can be placed in turn into a dataframe.
When we input a new set of data, we must do so in a logical way. The best logical way is the wide format, where each row represent the data (the values) of one entity (a person, a subject, ..) and each column represents one variable (age, score, ..). It’s like a spreadsheet in excel.
Is a common format that we all use.
gender= genda
the first columns is simple reference of the person is an identification
for instance if we want to divide some entities, for ages classes, from 1 to 10, from 11 to 20, and so one, we define a factor that assume number 1 for
Almost always is a numeric variable
It is recommended numeric variable because this factor can represents different levels of a treatment variable.
Ascending or descending
factor has three parameters, the first one is the variable that we have to turn into factor, the second one is used to denote different groups, in this case 2 levels. The last parameter is the assignment of labels to these levels, in our case female and male.
label = leibl
It is not the same, differences in terms of days
Are unable to respond/answer to a givend question.
This lack of data
When we have a dataframe it’s useful/convenient to select a part of this. for instance we must take just a variable, o a subset of variable or subset of cases.
square bracket
Which rows i want, which columns i want.
[, because in this case i want all the people
With which (con la quale)
Choose, anything else
from which
another function that does the same
Students who have passed an exam
more equal
the working directory is a directory in which we save or load some files (commands, or data, or our output results).
there is a default directory of R,.
Obviously we can change this directory, for our convenience (conviniens),
setwd and as parameter we put the the path that we want to use.
There are also functions to import and export
There are two types of files, and they differ in which delimiter is used to separate the elements
Both the function require two parameters.
The header true tells R that the data file has variable names in the first row of the file.
the first parameter is the name of the object to export, the second is the name of the file, the third is the separator used to seprate data values (i’ve used tab delimiter), and the last tell R to write or not the number of rows (in this case not).