Basic concepts Flashcards

(116 cards)

1
Q

When was R created and which language inspired it?

A

R was created in 1996 and was inspired by S Language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the main purpose of R?

A

It’s an statistical environment for data analysis and graphs creation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 3 main characteristics of R?

A
  • Free and open source
  • Intepreted language (instead of compiled)
  • Object oriented (everything is an object in R)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the current version of R? (as of Feb 2021)

A

4.0.4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the 4 possible IDEs mentioned by Dr. Fernando in the class?

A
  • R Studio Desktop
  • R Studio Cloud (create an account first)
  • Google Collab
  • Emacs + ESS (highly recommended)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the Working Directory? When do I need to set it? How to set it?

A

It’s the folder to which R will be redirected. All imported and exported files will be in this directory. It’s very important to set it before I start working.

I can set it with the function setwd(“/home/paulojardim/pasta”)

I can get it with the function getwd( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What function do I use to list all the objects created in an environement?

A

ls( )

It returns a vector of character strings giving the name of the objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is R Workspace?

A

It’s the place in memory where the variables (objects) are saved. It’s all that was created during a sessios, saved in RAM memory. We can save it in a .Rdata file if they were produced after a long calculation. But the ideal is saving the code itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What function should I use to generate random numbers of a uniform distribution? What are its arguments and which are mandatory? What’s the default for the not mandatory?

A

runif (n, min = 0, max = 1)

n = number of observations we want to return. It’s the mandatory argument

min and max are the limits, they are not mandatory and assume 0 and 1 if not provided.

e.g. runif(5) returns 5 random numbers between 0 and 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Do I need to name the arguments when I call a funtion in R? What about order?

A

No, I don’t neeed to name them. But if I don’t name them I need to respect the order. If I name them I can use in any order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can I easily see the arguments of a function?

A

I can call args( ) function.

e.g. args( sample ) returns:

function (x, size, replace = FALSE, prob = NULL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do I know what are the mandatory arguments of a function?

A

When I see the args of a function, the ones that don’t have a default value are mandatory:

e.g. in sample() function below, x and size are mandatory

function (x, size, replace = FALSE, prob = NULL)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the techincal name of “…” and when should I use it in my function?

A

It’s called ellipsis and I use basically in two situations:

  1. When it makes sense for a function receiving an undefined number of arguments (e.g. print function). Then I can transform the arguments in a list:
  • arguments = list(…)*
    2. When I need to receive arguments to pass to a generic function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What function should I use to concatenate strings?

A

paste(“string”, “string2”, “string3” , …… )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can I easily see the documentation of a function?

A

I can use ?function or help(function).

They both return the same thing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Within the documentation, what’s the session that tells me about what the function returns?

A

The Value session.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What function returns a list of functions/objects containing a expression?

A

apropos(“mod”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What function returns a list of functions containing a word in any part of their documentation?

A

help.search(“geo”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How can I see what are the loaded/attached packages at the moment and what are their code paths in my computer?

A
  • search()* - lists the loaded/attached packages
  • searchpaths()* - lists their paths in my computer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the most basic way of getting access to R official documentation?

A
  1. Run R from the terminal by executing “R” command
  2. In R prompt, execute help.start( ). It will launch a local webserver and open the html manuals and documentation.

Introduction to R and The R Language Definition are the main ones.

Worthy reading!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the 7 packages that are loaded/attached automatically when we run R?

A
  1. base
  2. utils
  3. stats
  4. graphics
  5. grDevices
  6. datasets
  7. methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do I load an installed package in R?

A

I need to run function library() providing the name of the package.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How do I install a new package in R?

A

Run function install.packages(“package_name”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do I verify if the installed packages need updates?

A

Execute function packageStatus()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do I update all installed packages automatically?
Run function ***update.packages(ask = FALSE)***
26
How do I create a simple function in R?
helloWorld = function( ) { writeLines("Hello") } it's preferable using the arrow instead of equal sign but Brainscape bugs with arrow
27
How can I **delete** one object of my workspace? And how can I delete all objects?
**rm**(x) **rm**(list = ls( ) )
28
What's the meaning of "**everything is a vector** in R"? Is it bad? What about simple number like 15?
R doesn't have primitive data types in the way that other languages do. In R even the simplest numeric value is an example of a **vector**. This might seems like a crazy idea and potentially inefficient, but it fits in well with the sort of calculations you want to do in R. A number occurring by itself in an expression (e.g. 15) is taken as a **vector of length one.**
29
Why R console prints **[1] 5** when I type 5?
Because 5 is also a **vector** (everything in R is). It's a vector of length one. The [1] means that the console is printing the **first element** of the vector. When I print a big vector, each row has the number corresponding to the index of the first vector element in that row.
30
What are the two types of vectors and their subtypes? What's the main difference between those two types?
**Atomic Vectors** and **Lists**. Atomic vectors have six types: * double * integer * character * logical * complex * raw Lists are also a vector but they can contain more than one datatype. That's their main difference.
31
What's the difference between type and class?
Complex data structures are created based on **atomic vectors**. When they are created we have a **class**. There are thousands of classes. One object can be of any of these clasess but their type will always be one of the **six vector types** (or a list)
32
How do I check the **type** of an object? And its **class**?
I use ***typeof( )*** function to check the type. And I use ***class( )*** function to check the class?
33
Whats the type of x? And its class? ## Footnote **x = c(2, 4, 6)**
type: double class: numeric
34
What's the type of x? And its class? ## Footnote **x = c(2L, 4L, 6L)**
Type: integer Class: integer
35
What's the type of x? And its class? ## Footnote **x = c("a", "b", "c")**
Type: character Class: character
36
What's the type of x? And its class? ## Footnote **x = c(TRUE, FALSE, TRUE)**
Type: logical Class: logical
37
Whats the type of x? And its class? ## Footnote **x = c(2 + 1i, 4 + 1i, 6 + 1i)**
Type: complex Class: complex
38
What's the type of x? And its class? ## Footnote **x = raw(3)**
Type: raw Class: raw
39
What function do I use to create new vectors?
**c( )** Concatenate function.
40
Does R understand a number like 5 as an **integer**? What do I need to do to accomplish it? Is there a difference in termos of memory usage?
No, it understands and stores as a **double**. If I want it to take the number as **integer** I need to use the sufix L: **5L** Yes, there is a difference in terms of memory usage because double numbers require more space.
41
What function to I use to see an estimate of the **space in memory** that is being used to store an R object? What package do I need to load?
function **object.size(myobject)** I don't need to load any package because it's in **utils** package which is pre loaded.
42
What function do I use to generate a **sequence**? What are its arguments?
**seq ( )** seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)), length.out = NULL, along.with = NULL, ...) - *length.out* - is the total number of elements I want * - along.with* - take the length from the length of this argument.
43
What's the difference between: rep(1:4, 2) ``` and rep(1:4, each = 2) ```
* rep(1:4, 2) returns "1 2 3 4 1 2 3 4" * rep(1:4, each = 2) returns "1 1 2 2 3 3 4 4"
44
Can I do math operations between a vector and a number? What's the result of c(3,4,5) \* 2 ?
Yes! Remember that numbers ARE vectors of lenght 1. The result is **"6 8 10"** We can do math operations with vectors of the **same legth** or of **multiple length**.
45
What's the **recycling** rule and how does it work?
It's the way R behaves when you do **arithmetic operations** with two vectors of **different sizes**. The shortest vector is concatenated to itself till it's length is the same as the longer vector. Then R does the operation. It only works if the longer object legth is multiple of the shorter object length. e.g. c(1, 2, 3) \* c(4, 5, 6, 7, 8, 9) is actually: c(1, 2, 3, 1, 2, 3) \* c(4, 5, 6, 7, 8, 9)
46
What is the type of **z**? What are the values of it? ## Footnote num = c(2, 4, 5, 6) z = num \> 4
z is a logical vector: FALSE FALSE TRUE TRUE
47
What operator do I use if I want to know if number 3 is part of this vector? **num = c(2, 4, 5, 6)** How does the code look like?
Operator %in% : ***3 %in% num***
48
What happens if I create a vector with elements of **different types**? Why that happens?
Elements are **coerced** to an unique type that can represent all the elements. This is called **implicit coercion**. It happens because a vector can only contain elements of the **same type**.
49
What's the difference between **implicit coercion** and **explicit coercion**?
**Implicit coercion** is performed by R. It happens when I provide types different from what R was expecting, for example. **Explicit coerction** is requested by me by calling the functions **as.( )**
50
What are the two main ways of creating **regular sequences** in R? What's the relationship between them?
1. Using the Colon Operator: **from:to** e. g. ***1:5*** generates 1 2 3 4 5 2. Using **seq( )** function. e. g. ***seq(1:4)*** generates 1 2 3 4 **seq( )** is a generalization of **from:to**
51
Whats the result of this code? Why? x = 0:6 typeof(x)
"**integer**" because the colon operator returns a **integer vector** unless the elements of the sequence cannot be represented as integers, in which case it returns a **double vector**.
52
What's the type of object **num** and how can I convert it to integer? ## Footnote num = c('1', '2', '5')
Type and class is 'character' I can covert to integer by calling function **as.integer(num)** I'm doing **explicit coercion** here.
53
What's the meaning of **NA**? What's the result of *typeof(NA)*
Not Available / Missing value **NA** is a **logical** constant of length 1 which contains a missing value indicator. Missing values in the **statistical sense**, that is, variables whose value is **not known**. *typeof(NA)* returns ***logical***
54
How do I test if each value of x is missing? What will be the return? ## Footnote ***x = c(3, 5, NA, 2)***
I can test with: **is.na(x)** The result will be: **FALSE FALSE TRUE FALSE**
55
How do I test if x has some missing value? **x = c(3, 5, NA, 2)** What's the result for x?
I call the function **any( is.na(x) )** The result for x will be: **TRUE**
56
What's the meaning of these constants? Give examples of ## Footnote **NaN** **Inf** **-Inf**
* NaN is "Not a Number". (e.g. "0/0") * Inf is "Infinite number" (e.g. "1/0") * -Inf is "negative infinite number" (e.g. "-1/0")
57
What's is the output of this code? ## Footnote x = c(-1,0,1)/0 x is.na(x)
-Inf NaN Inf FALSE TRUE FALSE
58
What's is the output of this code? ## Footnote x = c(-1,0,1)/0 x is.infinite(x)
-Inf NaN Inf TRUE FALSE TRUE
59
What's the difference between a **factor** and a character **vector**?
**factor** is a class used to store items that have a **finite** number of possible **values**. These values are also called **Levels** of the factor. "**levels**" is an **attribute** of the class factor. **Factors** may look like a character vector but it's stored and treated differently. Internally they are stored as **integers**, being each level an integer. Hence the type of a factor object is **integer**.
60
How can I create a **factor**?
By providing a character vector to function **factor( )**: **factor**(c("alta","baixa","baixa","media", "alta","media","baixa","media","media"))
61
What am I doing in this code and what's the output? ## Footnote fac = factor(c("alta","baixa","baixa","media","media","media")) f2 = as.character(fator) typeof(f2)
I'm creating a **factor**. Then I convert it to a **character vector**. The output are: * [1] "character" * [1] "alta" "baixa" "baixa" "media" "media" "media" Because when I convert a factor to character, I have a character vector with the names of the factor as characters.
62
What am I doing in this code and what's the output? ## Footnote fac = factor(c("alta","baixa","baixa","media","media","media")) f2 = as.integer(fator) typeof(f2) f2
I'm creating a **factor**. Then I convert it to an integer **vector**. The outputs are: * [1] "integer" * [1] 1 2 2 3 3 3 Because when I convert a factor to an integer, I have a integer vector with numbers that internally represent each level.
63
How should this function be called if I want the levels to be sorted by this order: baixa, media, alta? ## Footnote fac "alta","media","baixa","media","media"))
I should add the **arguments** levels and **ordered**: ## Footnote fac "alta","media","baixa","media","media"), **levels=c('baixa', 'media', 'alta'), ordered = TRUE** )
64
I have **factor** called *fac* and I want to know what are the levels and how many they are. What functions should I use?
* **levels(fac)** * **nlevels(fac)**
65
What are **matrices**? What are the main characteristics?
**Matrices** are **vectors** that can be in two dimensions. They are objects of class Matrix. Their type depends on their content. Main characteristics: * They are **bidimensional** * Can contain only **1 type** of data
66
How does the code look like if I want to create a matrix like this one? ## Footnote [,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12
**matrix(1:12, nrow = 3, ncol= 4)**
67
How does the code look like if I want to create a **matrix** like this one? [,1] [,2] [,3] [,4] [1,] 1 2 3 4 [2,] 5 6 7 8 [3,] 9 10 11 12
## Footnote **matrix(1:12, nrow = 3, ncol = 4, byrow = TRUE)**
68
How do I verify the **dimensions** of my matrix called "m" ?
## Footnote ***dim(m)***
69
How do I **add a new column** to this matrix called "m" with all values as 99 in the new column? [,1] [,2] [,3] [,4] [1,] 1 2 3 4 [2,] 5 6 7 8 [3,] 9 10 11 12
**cbind**(m, rep(99, 3)) [,1] [,2] [,3] [,4] [,5] [1,] 1 4 7 10 99 [2,] 2 5 8 11 99 [3,] 3 6 9 12 99
70
How do I **add a new row** to this matrix called "m" with all values as 99 in the new row? [,1] [,2] [,3] [,4] [1,] 1 2 3 4 [2,] 5 6 7 8 [3,] 9 10 11 12
**rbind**(matriz, rep(99, 4)) [,1] [,2] [,3] [,4] [1,] 1 4 7 10 [2,] 2 5 8 11 [3,] 3 6 9 12 [4,] 99 99 99 99
71
How can I easily **transform** **vector** **"m"** into a **matrix** without using matrix( ) function. ## Footnote m = 1:10
By changing its dimensions with function dim: ## Footnote **dim(m) = c(2, 5)**
72
What is ther operator used to **multiply** **matrices**?
Matrix Multiplication operator: ## Footnote **'%\*%'**
73
What is an array? What are its main characteristics?
Array is a kind of matrix which can have more than 2 dimensions. Arrays are objects of class array. Main characteristics: * n-dimensional structure * can only have **one** data **type**
74
How do I create an **array** object?
With the **array** function, providing an atomic vector and the dimensions of the array: ar = **array**(1:12, dim = c(2, 2, 3))
75
Is this code possible? Why? ## Footnote lista = **list**(1:30, "R", list(TRUE, FALSE))
Yes, because a **list** can contain **different** data **types**, including other **lists**.
76
What's the output of this code? li = **list**(1:30, "R", list(TRUE, FALSE)) class(li); typeof(li)
[1] "list" [1] "list"
77
What function can I use to **vizualize** the basic **structure** of an object (e.g. a list or data.frame)?
## Footnote **str( )**
78
What is the output of this code? Why? li =list(1:30, "R", list(TRUE, FALSE)) **dim**(li)
NULL Because a list is an **one dimensional** structure.
79
Can I put a matrix and a factor in the same **list**?
**Yes**, sure! A list can store objects of **different** **classes** and different **dimensions**.
80
What is a **dataframe**?
A dataframe is a two dimensional list to store a dataset. A dataframe object is of class 'dataframe' and its type is 'list'. They are the most common structures to work with data in R. **Main characteristics:** * a **list** of vectors and/or factors with the **same** length * It can contain **different** types of data (columns) * **Two** dimensional structure
81
How can I create this simple dataframe? name sex age 1 John M 32 2 Joseph M 34 3 Mary F 30
By calling the **data.frame** function with vectors as the arguments: da = **data.frame**(name = c("John", "Joseph", "Mary"), sex = c("M", "M", "F"), age = c(32, 34, 30))
82
What's the argument of data.frame function to say whether or not the characters will be treated as **factors**
**stringsAsFactors**
83
What if If pass two vectors of differents lengths to create a data.frame?
It will be created but the shorter vector will be filled with **NA** in the last elements.
84
What's the difference between calling these two functions for my dataframe df? * *as.matrix(df) data. matrix(df)**
* **as.matrix(df):** will try to convert df into a matrix, which will generally result in a coercion of its type to **character**. * **data.matrix(df):** Returns the matrix obtained by converting all the variables in a data frame to **numeric mode** and then binding them together as the columns of a matrix. **Factors** and ordered factors are replaced by their **internal** **codes**. Characters become **NAs** by coersion.
85
What is an **attribute** in R? Can any object have attributes?
It's a peace of information that can be **attached** to the object. All objects except **NULL** can have atttributes attached to them
86
What are the main **attributes** for objects in R?
names dimnames dim class
87
How can I see the **attributes** of an object?
I should call the function ***attributes(my\_object)***
88
How can I **get** and **set** an **attribute** of an object?
Two ways: 1. Using function **attr( )** e. g. attr(x, 'names') = c('one', 'two, 'three') 2. Using special **accessor functions** when the attribute has one e. g. **names(**x) = c('one', 'two, 'three') * *dim**(x) = c(2, 4) * *length**(x) = 10 # completes with NA
89
How can I give names to rows and columns of a **matrix**?
I need to set the **dimnames** attribute of the matrix. It can be done by using the accessor functions below: **rownames**(m) = c("A","B","C") **colnames**(m) = c("T1","T2","T3","T4")
90
How can I change names of **rows** and **columns** of a **data frame**?
I should use the functions **row.names( )** and **names( )**. There is no such a thing like *col.names* because data frames are a type of list, so it just has **names** which are the "columns" names.
91
How many **systems** for **object** orientation does R have? What are them?
Three systems: S3, S4, and RC (*Reference Classes*).
92
What are the main characteristics of **S3** system in R?
It implements an object oriented style called ***generic-function*** (opposed to *message-passing* OO that Java and C# implement). The generic functions decide which method to apply depending on the class of the object. It's the most **basic** and **most used** programming style in R.
93
What's is the main difference of **S4** system compared to S3?
The generic functions must have a formal **class** defined.
94
What's the main difference of **RC** system compared to S3 and S4?
The **methods** belong to **objects** and not functions as in S3 and S4. It makes R look more like other programming languages like C# and Java. This is the newest system in R. *(Reference Classes)*
95
What function should I use to see all the **methods** of a generic function or class? How does it work? What does it return?
Call function: **methods(function\_name)** It lists methods for S3 Generic Functions or Classes. Methods are found in all packages on the current **search()** path. The elements of the list look like: .. We have one item for each to which the generic function has a special **method**.
96
What is the ***method dispatch***? How does it work?
It's the mechanism responsible for identifying the class of the object that is passed to a *generic function* and based on that, **dispatch** the execution to the correct **method** of the function. The generic function calls UseMethod() function to decide which method to use.
97
Can I call a method directly in S3?
**Yes**, because methods are just normal R functions. But I shouldn’t do this because I lose the benefits of having a ***generic function***. I should always call the generic function and let the **method dispatch** take care of it.
98
How can I create a **method** for a *generic function* (e.g. mean) that handles a specific class? Will my new method appear in results of **methods(mean)**?
**mean**. = function(x, ...) { write my code here e.g.: rowMeans(x, ...) } Yes, the new method will appear in results of **methods(mean)**
99
Why do we say that the **S3** system gives us **freedom** and **power** to create entire R packages?
Because it allows us to create **generic functions**, then create **methods** to handle special classes with these functions and we can even create new **classes** that will also be handled by our methods later.
100
What's the difference between these two lines of code? What do they return? **-1:5** **-(1:5)**
* *-1:5** creates a sequence from -1 to 5: * *-1 0 1 2 3 4 5** * *-(1:5)** creates a sequence from 1 to 5 and changes all elements to negative: * *-1 -2 -3 -4 -5**
101
What is the basic **syntax** of a for loop in **R** which prints numbers 1 to 10?
for ( i in 1:10 ) { print(i) }
102
Do ***for*** loops need to go through a **sequence** of numbers?
No, I can use the same **for( )** structure to go through a **vector** of unordered integers or even a _character vector._
103
What is the function used to see basic **statistics** of a **data frame**, like median, quartiles, min, max?
**summary(df)**
104
How can I add a new column to my data frame **da**? The new column should be named "**grade**" and have 0 in all rows.
## Footnote **da$grade = 0**
105
How can I check the number of **rows** of my data frame **df**? And the number of **columns**?
**nrow(df) : number of rows** **length(df) or ncol(df) : number of columns**
106
What function can I use to **compare** if two data frames or two columns are **equal**?
**identical**(df$column, df2$column)
107
How can I create a **numeric** vector with **20** items, filled with **0s**? What about a **character** vector with 30 **blank** elements?
**numeric(20)** **character(30)**
108
Why should I prefer **vectorized operations** instead of loopings in R?
Because they are more **efficient** to compute, so they run faster, because R just needs to **interpret** the code one time, running **compiled** code inside. Also, they require less code.
109
What function can I use to see the **CPU** **time** of my code?
**system.time(** ***my\_code\_here*** **)**
110
What's the main recomendation if I NEED to run a for **loop** that will generate a **vector** at the end?
Create the vector **before** the loop with **enough** **length** to store ALL results. Never grow a vector using ***c( )***! At each iteration R needs to allocate a new space in **memory** to store the new vector and delete the old one.
111
How does object **x** look like and what's its **class** and **type**? **x = cbind(x1 = 3, x2 = c(4:1, 2:5))**
**x** looks like the object below. Its type is **double** and class is **matrix**. ## Footnote x1 x2 [1,] 3 4 [2,] 3 3 [3,] 3 2 [4,] 3 1 [5,] 3 2 [6,] 3 3 [7,] 3 4 [8,] 3 5
112
I have a **data frame** called **students**, with a column called **grade**. I want to add a new column called **status**, which will be "*approved*" for students with grades greater then or equal to **7** and "*not approved*" to the others. How can I accomplish this with a **vectorized** function?
Using vectorized **ifelse**: students$status = **ifelse**(students$grade \>= 7, "approved", "not approved")
113
When does the structure **repeat{ }** stop?
When I call **break** within it.
114
What is this code doing? **aggregate**(prova1 ~ situacao, data = notas, FUN = mean)
It's calling vectorized function **aggregate** on data frame **notas**. It will group by column **situacao** and will apply function **mean** over column **prova1** to each group. So it will return a **data frame** with one column for each group of **situacao** and a row with **mean** of **prova1** for each group
115
What are the functions of **\*apply( )** family? What are the basic differences between them?
* **apply( )**: able to operant on rows and columns (MARGIN) * **sapply( )**: operates on columns. Simplifies the result to a vector * **lapply( )**: operates on columns. Returns a list * **tapply( )**: operates on columns. Allows grouping the function by another column.
116
O que é importante saber ao criar **funções** que recebem um vetor de **x** como argumento, ao invés de um valor **x** apenas? Qual o efeito colateral e como resolver?
No caso de funções de uma única variável de entrada o **R** automaticamente **vetoriza** a operação, ou seja, aplica a função a cada ponto do vetor de entrada. Quando eu passo um vetor de vetores para uma função, estou passando um vetor apenas, e como minha função já está olhando pra **indices** **específicos** desse vetor, ela despreza todos os outros. Neste caso, uma das formas de avaliar a função em mais de um ponto é usar uma instrução ***for*** percorrendo uma **matriz** de entradas por linha.