Professional Documents
Culture Documents
Difference Between Print and Paste Function?
Difference Between Print and Paste Function?
Difference Between Print and Paste Function?
• R automatically determines the variable data type → revealed by using the typeof() function
• numeric variables are by default created as a double data type unless assigned an integer
type by the letter L (e.g. number = 5L) – for more efficient data storage
• use the is.character() function to test data type → returns a boolean value – true/false
• assign boolean values via TRUE/FALSE or T/F
# Second example
[1] "file_number_32"
• vector = variable that can contain multiple values – each value is contained within an element of the
vector
• assign multiple values to a variable by using the “combine function” → c()
- e.g. data < - list(12, 3.14, “Mike”, TRUE) ==> BACK TO Using the <-
- lists are NOT flexible → cannot dynamically add on extra elements unlike vectors
- can use c() combine function to combine 2 lists
can name each element in a list: data<- list(dozen=12, pi=3.14, name= “Mao”, flag=TRUE) so that if you use the
$ operator you can retrive the specific value ==> data$name will retrieve the value “Mao” → this is called the
KEY=VALUE pairs
IF THE VALUES IN THE LIST ARE NUMERICAL, MATHEMATICAL FUNCTIONS CAN BE APPLIED
the axes are not yet defined, and hence the y-axis just shows the name of the list, while x-axis is “index”
if we just input plot(year, type="o", col="Blue", pch=4) without defining the ann or axes → by default their
value will be set to TRUE
combining:
and hence we will need to add the title and make a box
day<-list(monday=1,tuesday=2,wednesday=3,thursday=4)
plot(days, type="o", col="Red", pch=20, ann=FALSE, axes=FALSE)
results in an error as the plot function cannot form a plot based on LISTS – has to be a
vector → e.g. of numerical values.
The vector needs to appear in the values table in the environment section →
hence, we need to use the unlist() function to form a vector from the list [remembering
that the unlist functions returns a vector of all keys and values, and names can be
explicitly ignored by including a use.names=FALSE argument.]
days<-unlist(day)
axis(1, at=1:4, lab=c(names(day))) ← the at=1:x , x depends on the no. of values
IF WE had typed:
axis(1, at=1:4, lab=c(names(day))) → x-axis will have mon/tues/wed because the names
is defined within the variable “day” VS
axis(1, at=1:4, lab=c(names(days))) → x-axis will NOT have mon/tues/wed because the
vector days has been defined to exclude the keys (mon/tues/etc)