0% found this document useful (0 votes)
38 views3 pages

Intro Ducci On R

This document introduces vectors and matrices in R. It shows examples of creating vectors with different data types and accessing elements within vectors using indexing. It also demonstrates how to create matrices, access elements, and perform operations like transposing. Factors are introduced as a data type for categorical variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views3 pages

Intro Ducci On R

This document introduces vectors and matrices in R. It shows examples of creating vectors with different data types and accessing elements within vectors using indexing. It also demonstrates how to create matrices, access elements, and perform operations like transposing. Factors are introduced as a data type for categorical variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Introducción al R

Palomino Morales Edwin

Lambayeque 2 de diciembre

Introducción de datos

Vectores
v1 <-c(100, 500, 900, 225, 25)
v1

## [1] 100 500 900 225 25

v2 <-c("uno", "dos", "tres", "cuatro")


v2

## [1] "uno" "dos" "tres" "cuatro"

v1[1:3]

## [1] 100 500 900

v1*5

## [1] 500 2500 4500 1125 125

v1[-1]

## [1] 500 900 225 25

v1[c(1,3,5)]

## [1] 100 900 25

v1[-c(3)]

## [1] 100 500 225 25

data <-c(1, 2, 2, 2, 3, 3, 3, 3)
fdata <- factor(data)
fdata

## [1] 1 2 2 2 3 3 3 3
## Levels: 1 2 3

factor(1:3, labels = c("A", "B", "C"))

## [1] A B C
## Levels: A B C

factor(1:5, exclude = 4)
## [1] 1 2 3 <NA> 5
## Levels: 1 2 3 5

data1 <-c(10, 20, 20, 50, 10, 20, 10, 50, 20)
fdata1 <-factor(data1)
mdata1 <-factor(data1, levels<- c(10, 20, 50), ordered = TRUE)
mdata1

## [1] 10 20 20 50 10 20 10 50 20
## Levels: 10 < 20 < 50

Matrices
A <-matrix(c(3, 2, 1, -1, 4, 0, 2, 5, 4), nrow = 3, ncol = 3, byrow =T)
A

## [,1] [,2] [,3]


## [1,] 3 2 1
## [2,] -1 4 0
## [3,] 2 5 4

U <-matrix(1, nrow = 3, ncol = 4)


U

## [,1] [,2] [,3] [,4]


## [1,] 1 1 1 1
## [2,] 1 1 1 1
## [3,] 1 1 1 1

I5 <-diag(A)
I5

## [1] 3 4 4

D <-diag(A)
D

## [1] 3 4 4

solve(A)

## [,1] [,2] [,3]


## [1,] 0.37209302 -0.06976744 -0.09302326
## [2,] 0.09302326 0.23255814 -0.02325581
## [3,] -0.30232558 -0.25581395 0.32558140

t(A)

## [,1] [,2] [,3]


## [1,] 3 -1 2
## [2,] 2 4 5
## [3,] 1 0 4
M <-matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, ncol = 3, byrow =T,
dimnames = list(c("Supermercado", "Tienda"),
c("Frutas", "Verduras", "Bebidas")))
M

## Frutas Verduras Bebidas


## Supermercado 1 2 3
## Tienda 4 5 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy