[R-sig-eco] Understanding cbind
Mario José Marques
mariojosebr at yahoo.com.br
Fri Jul 20 19:25:19 CEST 2012
Hi Manuel,
when you use cbind(finaldf[, 3:22], cbind function waiting that you gave
second data to bind with first. How you use only one data, its result like:
DEV <- finaldf[, 3:22]
with the same structure of data frame finaldf.
When you use cbind(finaldf$oc1, finaldf$oc2,... you bind a vector of
number into columns. Its like:
v1 <- 0,0,0,1,1,1
v2 <- 1,1,1,0,0,0
...
cbind(v1, v2, ...)
that result:
[ ,1] [ ,1]
[1, ] 0 1
[2, ] 0 1
[3, ] 0 1
[4, ] 1 0
[5, ] 1 0
[6, ] 1 0
Regards,
MJ
...................................................
Mario José Marques
Master student in Ecology
Institute of Biology, Dept. Plant Biology, Ecology Lab.
State University of Campinas - UNICAMP
Campinas, São Paulo, Brazil
On 20/07/2012 13:13, Manuel Spínola wrote:
> Dear list members,
>
> I am using function cbind but I got 2 different results, one is a data
> frame and the other is a matrix and I would like to undertand why is the
> reason:
>
> I have a data frame called "finaldf"
>
>> names(finaldf)
> [1] "especie" "estrato" "oc1" "oc2" "oc3" "oc4" "oc5"
> "oc6"
> [9] "oc7" "oc8" "oc9" "oc10" "oc11" "oc12" "oc13"
> "oc14"
> [17] "oc15" "oc16" "oc17" "oc18" "oc19" "oc20"
>
> I tried (gave me a data frame):
>
> DET <- cbind(finaldf[, 3:22])
>
>> head(DET)
> oc1 oc2 oc3 oc4 oc5 oc6 oc7 oc8 oc9 oc10 oc11 oc12 oc13 oc14 oc15 oc16
> oc17 oc18
> 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
> 0 0
> 27 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
> 0 0
> 53 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0
> 2 1 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1
> 1 1
> 28 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1
> 1 0
> 54 1 1 1 1 1 1 1 1 0 0 0 1 1 0 1 0
> 0 0
> oc19 oc20
> 1 0 0
> 27 1 0
> 53 0 0
> 2 1 1
> 28 1 0
> 54 0 1
>
> and gave me a different results when I tried (gave me a matrix):
>
> DET <- cbind(finaldf$oc1, finaldf$oc2, finaldf$oc3, finaldf$oc4,
> finaldf$oc5, finaldf$oc6, finaldf$oc7, finaldf$oc8, finaldf$oc9,
> finaldf$oc10, finaldf$oc11, finaldf$oc12, finaldf$oc13, finaldf$oc14,
> finaldf$oc15, finaldf$oc16, finaldf$oc17, finaldf$oc18, finaldf$oc19,
> finaldf$oc20)
>
>> head(DET)
> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
> [,14]
> [1,] 0 0 0 0 0 0 0 0 1 0 0 0 0
> 0
> [2,] 0 0 0 1 0 0 0 0 0 0 0 0 0
> 0
> [3,] 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0
> [4,] 1 1 1 1 1 1 0 1 1 1 1 1 0
> 1
> [5,] 1 0 1 0 1 1 1 1 1 1 1 1 0
> 1
> [6,] 1 1 1 1 1 1 1 1 0 0 0 1 1
> 0
> [,15] [,16] [,17] [,18] [,19] [,20]
> [1,] 0 0 0 0 0 0
> [2,] 0 1 0 0 1 0
> [3,] 0 0 0 0 0 0
> [4,] 0 1 1 1 1 1
> [5,] 1 1 1 0 1 0
> [6,] 1 0 0 0 0 1
>
> Best,
>
> Manuel
>
>
>
>
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
More information about the R-sig-ecology
mailing list