dear R-friends, i`ve got a large dataset of vegetation-samples with about 500 variables(=species) in the following format: 1 spec1 1 spec23 1 spec54 1 spec63 2 spec1 2 spec2 2 spec253 2 spec300 2 spec423 3 spec20 3 spec88 3 spec121 3 spec200 3 spec450 . . this means: sample 1 (grassland) with the species (=spec) 1, 23, 54, 63 is it possible to get a following data-structure for further analysis? 1 2 3 ...... spec1 1 1 0 spec2 0 1 0 spec3 ... spec253 0 1 0 ... spec450 0 0 1 with thanks from the snowy tirol helli
Helmut Kudrnovsky wrote:> dear R-friends, > > i`ve got a large dataset of vegetation-samples with about 500 > variables(=species) in the following format: > > 1 spec1 > 1 spec23 > 1 spec54 > 1 spec63 > 2 spec1 > 2 spec2 > 2 spec253 > 2 spec300 > 2 spec423 > 3 spec20 > 3 spec88 > 3 spec121 > 3 spec200 > 3 spec450 > . > . > > this means: sample 1 (grassland) with the species (=spec) 1, 23, 54, 63 > > is it possible to get a following data-structure for further analysis? > > 1 2 3 ...... > spec1 1 1 0 > spec2 0 1 0 > spec3 > ... > spec253 0 1 0 > ... > spec450 0 0 1It appears that you want to form a crosstabulation. If so, you can use the table or xtabs functions. I suggest you look at the documentation and examples of those and see if they will be suitable.
Dear Helmut, How about table(species, sample)? Regards, John -------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario Canada L8S 4M4 905-525-9140x23604 http://socserv.mcmaster.ca/jfox --------------------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Helmut > Kudrnovsky > Sent: Saturday, December 18, 2004 8:31 AM > To: r-help at stat.math.ethz.ch > Subject: [R] variables - data-structure > > dear R-friends, > > i`ve got a large dataset of vegetation-samples with about 500 > variables(=species) in the following format: > > 1 spec1 > 1 spec23 > 1 spec54 > 1 spec63 > 2 spec1 > 2 spec2 > 2 spec253 > 2 spec300 > 2 spec423 > 3 spec20 > 3 spec88 > 3 spec121 > 3 spec200 > 3 spec450 > . > . > > this means: sample 1 (grassland) with the species (=spec) 1, > 23, 54, 63 > > is it possible to get a following data-structure for further analysis? > > 1 2 3 ...... > spec1 1 1 0 > spec2 0 1 0 > spec3 > ... > spec253 0 1 0 > ... > spec450 0 0 1 > > with thanks from the snowy tirol > helli > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
Helmut Kudrnovsky <hellik at web.de> writes:> dear R-friends, > > i`ve got a large dataset of vegetation-samples with about 500 > variables(=species) in the following format: > > 1 spec1 > 1 spec23 > 1 spec54 > 1 spec63 > 2 spec1 > 2 spec2 > 2 spec253 > 2 spec300 > 2 spec423 > 3 spec20 > 3 spec88 > 3 spec121 > 3 spec200 > 3 spec450 > . > . > > this means: sample 1 (grassland) with the species (=spec) 1, 23, 54, 63 > > is it possible to get a following data-structure for further analysis? > > 1 2 3 ...... > spec1 1 1 0 > spec2 0 1 0 > spec3 > ... > spec253 0 1 0 > ... > spec450 0 0 1 > > with thanks from the snowy tirol > helliShould be fairly easy. You could for instance generate a table(species,area) - with a few complications if the same combination can occur more than once. Or use matrix indexing M <- matrix(0,nspec,narea) M[cbind(species,area)] <- 1 Upon reading, the sort order of the species may be a little problematic: dd <- read.table(stdin()) 0: 1 spec1 1: 1 spec23 2: 1 spec54 3: 1 spec63 4: 2 spec1 6: 2 spec2 7: 2 spec253 8: 2 spec300 9: 2 spec423 10: 3 spec20 11: 3 spec88 12: 3 spec121 13: 3 spec200 14: 3 spec450 15: # ctrl-D terminates input names(dd) <- c("area","species") with(dd, table(species,area)) area species 1 2 3 spec1 1 1 0 spec121 0 0 1 spec2 0 1 0 spec20 0 0 1 spec200 0 0 1 spec23 1 0 0 spec253 0 1 0 spec300 0 1 0 spec423 0 1 0 spec450 0 0 1 spec54 1 0 0 spec63 1 0 0 spec88 0 0 1 To fix up, use something like specn <- paste("spec", sort(as.numeric(substring(levels(dd$species),5))), sep="") dd <- transform(dd, species=factor(species,levels=specn)) with(dd, table(species,area)) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Helmut Kudrnovsky <hellik <at> web.de> writes: : : dear R-friends, : : i`ve got a large dataset of vegetation-samples with about 500 : variables(=species) in the following format: : : 1 spec1 : 1 spec23 : 1 spec54 : 1 spec63 : 2 spec1 : 2 spec2 : 2 spec253 : 2 spec300 : 2 spec423 : 3 spec20 : 3 spec88 : 3 spec121 : 3 spec200 : 3 spec450 : . : . : : this means: sample 1 (grassland) with the species (=spec) 1, 23, 54, 63 : : is it possible to get a following data-structure for further analysis? : : 1 2 3 ...... : spec1 1 1 0 : spec2 0 1 0 : spec3 : ... : spec253 0 1 0 : ... : spec450 0 0 1 : : with thanks from the snowy tirol : helli If your intention is to use this as a community matrix with the R vegan package then I think you require the transpose of the above, namely (assuming DF contains your data frame): comm <- with(DF, table(sample, species)) library(vegan) diversity(comm) specaccum(comm, method = "random") etc.