-R management
R can read files from various datatype and sources suche as csv, excel, database, from web, twitter, etc
Last updated
R can read files from various datatype and sources suche as csv, excel, database, from web, twitter, etc
Last updated
Useful functions for dealing with objects
Importing data into R is fairly easy methode. The important thing that you must know the function for every sources. The most sources from getting data in R come from CSV plain text and Excel.
If you’ve already :
If you haven't set a working directory: copy the file and paste in file directory (PASTE HERE)
Export as CSV
Save the dataset as .csv with plain text editor or another program such as excel
The best ways to read an Excel file is to export it to a csv , but we can do it direct in R
Note: If you haven't set a working directory: copy the file and paste in function read_excel("PASTE HERE")
Export as excel.xlsx?????
How to get information from the dataset
The symbol NA (not available) are represented missing value. And NaN are not a number (e.g., dividing by zero).
Dates are represented as the number of days since 1970-01-01, with negative values for earlier dates.
Convert strings to dates and opposite:
format( ) function to print dates.
Symbol
Meaning
Example
%Y
4-digit year
2007
%y
2-digit year
07
%B
unabbreviated month
January
%b
abbreviated month
Jan
%m
month (00-12)
00-12
%A
unabbreviated weekday
Monday
%a
abbreviated weekday
Mon
%d
day as a number (0-31)
01-31
An example:
Use operator "<-" or "=" to create variable
Operator
Description
+
addition
-
subtraction
*
multiplication
/
division
^ or **
exponentiation
x %% y
modulus (x mod y) 5%%2 is 1
x %/% y
integer division 5%/%2 is 2
Operator
Description
==
exactly equal to
!=
not equal to
>
greater than
>=
greater than or equal to
<
less than
<=
less than or equal to
!x
Not x
x | y
x OR y
x & y
x AND y
isTRUE(x)
test if X is TRUE
Numeric Functions:
Function
Description
abs(x)
absolute value
sqrt(x)
square root
log(x)
natural logarithm
log10(x)
common logarithm
exp(x)
e^x
cos(x), sin(x), tan(x)
-
signif(x, digits=n)
signif(3.475, digits=2) is 3.5
round(x, digits=n)
round(3.475, digits=2) is 3.48
trunc(x)
trunc(5.99) is 5
floor(x)
floor(3.475) is 3
ceiling(x)
ceiling(3.475) is 4
Character Functions:
Function
Description
tolower(x)
Lowercase
toupper(x)
Uppercase
substr(x, start=n1, stop=n2)
Extract or replace substrings x <- "abcdef" substr(x, 2, 3) is "bc" substr(x, 2, 4) <- "22222" is "a22def"
strsplit(x, split)
Split the elements strsplit("abc", "") returns 3 element vector "a","b","c"
paste(..., sep="")
Going further : and
Going further for more
, , and .