Está en la página 1de 3

Datos: 2,3,0,3,1,0,0,1

> datos<-c(2,3,0,3,1,0,0,1)
> datos
[1] 2 3 0 3 1 0 0 1

Buscando valores de inters

> z<-c(1,2,3,4,12,31,2,51,23,1,23,2341,23,512,32,312,123,21,3)
> z[3:7]
[1] 3 4 12 31 2

Cambiando un valor por otro

> z[3]<-7
> z[3:7]
[1] 7 4 12 31 2

Ordenando datos de menor a mayor y verificar en que ubicacin estaba previamente


el dato

> sort(z)
[1] 1 1 2 2 3 3 4 12 21 23 23 23 31 32 51 123 312 512 2341
> order(z)
[1] 1 10 2 7 3 19 4 5 18 9 11 13 6 15 8 17 16 14 12
# por ejemplo el nmero 1 estaba originalmente en la posicin 1 y en la
posicin 10

Crear matriz

> mat<-matrix(c(2,3,1,5),nrow=2,ncol=2)
> mat
[,1] [,2]

[1,] 2 1
[2,] 3 5

Agregar una fila

> onemat<-matrix(1,nrow=2,ncol=3)
> onemat
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 1 1 1

Crear matriz con un nmero fijo de nmeros

> matrix(c(1,2,3,4,5,6,7),ncol=3)
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 1
[3,] 3 6 2

1. Creando data frames


> organism<-c("Human","Mouse","Fruit Fly", "Roundworm","Yeast")
> genomeSizeBP<-c(3000000000,3000000000,135600000,97000000,12100000)
> estGeneCount<-c(30000,30000,13061,19099,6034)
> comparativeGenomeSize<data.frame(organism=organism,genomeSizeBP=genomeSizeBP,estGeneCount=estGeneCou
nt)
>
>
>
>
x
1
2
3
4

x<-c(1,3,2,1)
y<-c(2,3,4,1)
xy<-data.frame(x,y)
xy
y
1 2
3 3
2 4
1 1

2. Crear un nuevo vector de una de las columnas del data frame


> q<-xy$x
> q
[1] 1 3 2 1

3. Extraer un elemento especfico del data frame


> xy$x[2]
[1] 3
# el nmero 3 est en la segunda columna de la fila x

4. Crear nueva columna y combinarla a un data frame


>
>
>
>
x
1
2
3

#create and bind column z to


z<-c(2,1,4,7)
xyz<-cbind(xy,z)
xyz
y z
1 2 2
3 3 1
2 4 4

4 1 1 7
>
>
>
>
x
1
2
3
4
5

#create and bind new row w


w<-c(3,4,7)
xyz<-rbind(xyz,w)
xyz
y z
1 2 2
3 3 1
2 4 4
1 1 7
3 4 7

5. Realizando clculos matemticos


> whale = c(74, 122, 235, 111, 292, 111, 211, 133, 156, 79)
> mean(whale)
[1] 152.4
> var(whale)
[1] 5113.378
> sqrt(var(whale))
[1] 71.50789

Utilizando funciones matemticas para la frmula de la desviacin estndar

> sqrt( sum( (whale - mean(whale))^2 /(length(whale)-1)))


[1] 71.50789
> std(whale)
[1] 71.50789

frijol<-read.table("C:/Users/Pedro/Desktop/DATA FRAME
DEBER/frijol_prod.txt",header=TRUE)
bact<-read.table("C:/Users/USER/Desktop/Agricola/bact.txt",header=TRUE)
bactVOEDING<-factor(bact$VOEDING)
library(car)
leveneTest(CONCEN~bactVOEDING,data=bact,center=mean)
aovbact<-aov(CONCEN~bactVOEDING,data=bact) ANOVA
summary(aovbact)
lillie.test(aovbact$res)
TurkeyHSD(aovbact)
plot(vector1,vector2)
hist(vector1)

str(cotton)
attach(cotton)
> tapply.stat(yield,cotton[,c(1,3)],mean)

También podría gustarte