Sunteți pe pagina 1din 4

UNIVERSIDAD DE EL SALVADOR

FACULTAD MULTIDISCIPLINARIA DE OCCIDENTE


DEPARTAMENTO DE MATEMÁTICA
LICENCIATURA EN ESTADISTICA
PAQUETA R

CURSO DE R AÑO 2019

Por: Rebeca Abigail López Rivera

Importar y exportar datos


CONTENIDO
Exportar datos en R..................................................................................................................................... 2
Importar datos en SPSS............................................................................................................................. 2

library(readxl)
LungCapData<-read_excel("LungCapData.xlsx")
head(LungCapData,10)

## # A tibble: 10 x 6
## LungCap Age Height Smoke Gender Caesarean
## <dbl> <dbl> <dbl> <chr> <chr> <chr>
## 1 6.48 6 62.1 no male no
## 2 10.1 18 74.7 yes female no
## 3 9.55 16 69.7 no female yes
## 4 11.1 14 71 no male no
## 5 4.8 5 56.9 no male no
## 6 6.22 11 58.7 no female no
## 7 4.95 8 63.3 no male yes
## 8 7.32 11 70.4 no male no
## 9 8.88 15 70.5 no male no
## 10 6.8 11 59.2 no male no

library("xlsx")
i2<-read.xlsx("LungCapData.xlsx",1,header=TRUE)
head(i2,6)

## LungCap Age Height Smoke Gender Caesarean


## 1 6.475 6 62.1 no male no
## 2 10.125 18 74.7 yes female no
## 3 9.550 16 69.7 no female yes
## 4 11.125 14 71.0 no male no
## 5 4.800 5 56.9 no male no
## 6 6.225 11 58.7 no female no

dim(LungCapData)

## [1] 725 6

length(LungCapData)

## [1] 6

tail(LungCapData)

## # A tibble: 6 x 6
## LungCap Age Height Smoke Gender Caesarean
## <dbl> <dbl> <dbl> <chr> <chr> <chr>
## 1 7.32 9 66.3 no male no
## 2 5.72 9 56 no female no
## 3 9.05 18 72 yes male yes
## 4 3.85 11 60.5 yes female no
## 5 9.82 15 64.9 no female no
## 6 7.1 10 67.7 no male no

library(psych)
str(LungCapData)

## Classes 'tbl_df', 'tbl' and 'data.frame': 725 obs. of 6 variables:


## $ LungCap : num 6.47 10.12 9.55 11.12 4.8 ...
## $ Age : num 6 18 16 14 5 11 8 11 15 11 ...
## $ Height : num 62.1 74.7 69.7 71 56.9 58.7 63.3 70.4 70.5 59.2 ...
## $ Smoke : chr "no" "yes" "no" "no" ...
## $ Gender : chr "male" "female" "female" "male" ...
## $ Caesarean: chr "no" "no" "yes" "no" ...

data1<-read.table("LungCapData.txt", header = TRUE)


head(data1)

## LungCap Age Height Smoke Gender Caesarean


## 1 6.475 6 62.1 no male no
## 2 10.125 18 74.7 yes female no
## 3 9.550 16 69.7 no female yes
## 4 11.125 14 71.0 no male no
## 5 4.800 5 56.9 no male no
## 6 6.225 11 58.7 no female no

data2<-read.table("LungCapData.txt", header = TRUE)

Exportar datos en R
write.table(LungCapData,file = "LungCapData.csv")
write.table(LungCapData,file = "LungCapData.txt")
Importar datos en SPSS
library(haven)
demo<-read_sav("demo.sav")
class(demo)

## [1] "tbl_df" "tbl" "data.frame"

demo<-as.data.frame(demo)
class(demo)

## [1] "data.frame"

head(demo)

## edad marital direcc ingres ingcat coche cochecat educ empleo


retirado
## 1 55 1 12 72 3 36.2 3 1 23
0
## 2 56 0 29 153 4 76.9 3 1 35
0
## 3 28 1 9 28 2 13.7 1 3 4
0
## 4 24 1 4 26 2 12.5 1 4 0
0
## 5 25 0 2 23 1 11.3 1 2 5
0
## 6 45 1 9 76 4 37.2 3 3 13
0
## empcat satlab genero residen inalam multline voz busca internet
idllam
## 1 3 5 m 4 0 0 1 0 0
0
## 2 3 4 h 1 1 0 1 1 0
1
## 3 1 3 m 3 1 0 1 0 0
1
## 4 1 1 h 3 1 1 1 0 0
0
## 5 2 2 h 2 0 0 0 0 0
1
## 6 2 2 h 2 0 1 1 1 0
0
## espera tv video cd pda pc fax noticias respuest
## 1 0 1 1 1 0 0 0 0 1
## 2 1 1 1 1 0 0 0 0 0
## 3 1 1 1 1 1 1 0 1 1
## 4 1 1 1 1 1 1 1 1 1
## 5 0 1 1 1 0 0 0 1 1
## 6 0 1 1 1 0 1 0 0 1
attach(demo)
library(modes)
mean(demo$edad)

## [1] 42.05859

modes(demo$edad)

## [,1]
## Value 39
## Length 214

median(demo$edad)

## [1] 41

skewness(demo$edad)

## [1] 0.2991271

library(haven)
turismo<-read_sas("turismo.sas7bdat")
head(turismo)

## # A tibble: 6 x 2
## T TURISTAS
## <date> <dbl>
## 1 1978-01-01 2
## 2 1978-04-01 6
## 3 1978-07-01 3
## 4 1978-10-01 1
## 5 1979-01-01 3
## 6 1979-04-01 9

library(haven)
mydata<-read_dta("mydata.dta")
class(mydata)

## [1] "tbl_df" "tbl" "data.frame"

mydata=as.data.frame(mydata)
head(mydata)

## x
## 1 4.47
## 2 4.47
## 3 3.48
## 4 5.00
## 5 3.42
## 6 3.78

S-ar putea să vă placă și