Plants

> wdir <- "C:/Users/vlado/DL/UCI/plants"
> setwd(wdir)
> # in original table missing pe and gl (=dengl ?)
> S <- c( "ab",  "ak",  "al",  "ar",  "az",  "bc",  "ca",  "co",  "ct",  "dc",  
+  "de",  "dengl",  "fl",  "fraspm",  "ga",  "gl",  "hi",  "ia",  "id",  "il",  
+  "in",  "ks",  "ky",  "la",  "lb",  "ma",  "mb",  "md",  "me",  "mi",  "mn",    
+  "mo",  "ms",  "mt",  "nb",  "nc",  "nd",  "ne",  "nf",  "nh",  "nj",  "nm", 
+  "ns",  "nt",  "nu",  "nv",  "ny",  "oh",  "ok",  "on",  "or",  "pa",  "pe",  
+  "pr",  "qc",  "ri",  "sc",  "sd",  "sk",  "tn",  "tx",  "ut",  "va",  "vi",
+  "vt",  "wa",  "wi",  "wv",  "wy",  "yt" )  
> dat <- file("plants.data","r")
> i <- 0; P <- list()
> while ( TRUE ) {
+   line = readLines(dat, n=1)
+   if ( length(line) == 0 ) break
+   i <- i+1; L <- strsplit(line,",")[[1]]
+   P[[i]] <- list(L[1],as.integer(factor(L[2:length(L)],levels=S)))
+ }
> close(dat)
> n <- length(P); m <- length(S)
> net <- file("plants.net","w")
> cat("% Plants 2 Pajek,", date(),"\n% by Vladimir Batagelj\n",file=net)
> cat("% source: https://archive-beta.ics.uci.edu/dataset/180/plants\n",file=net)
> cat("*vertices",n+m,n,"\n",file=net)
> for(i in 1:n) cat(i,' "',P[[i]][[1]],'"\n',sep='',file=net)
> for(j in 1:m) cat(n+j,' "',S[j],'"\n',sep='',file=net)
> cat('*arcslist\n',file=net)
> for(i in 1:n) cat(i,n+P[[i]][[2]],'\n',file=net)
> close(net)

To do

Species / Genera partition of plants !!???

> source("https://raw.githubusercontent.com/bavla/Rnet/master/R/Pajek.R")
> p <- rep(1,n) 
> for(i in 2:n) if(startsWith(P[[i]][[1]],P[[i-1]][[1]])) p[i-1] <- 2
> table(p)
p
    1     2 
28160  6621 
> vector2clu(p,Clu="plants.clu")
vlado/work/2m/dat/plants.txt · Last modified: 2023/03/20 05:31 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki