Ero sivun ”OpasnetBaseUtils” versioiden välillä

Opasnet Suomista
Siirry navigaatioon Siirry hakuun
pEi muokkausyhteenvetoa
 
(5 välissä olevaa versiota 3 käyttäjän tekeminä ei näytetä)
Rivi 1: Rivi 1:
[[Luokka:Opasnet]]
[[op_en:OpasnetBaseUtils]]
[[op_en:OpasnetBaseUtils]]
[[Luokka:Sisältää R-koodia]]
:''This page is just a placeholder for code in [[:op_en:OpasnetBaseUtils]] so that it can be used in Finnish Opasnet as well.
:''This page is just a placeholder for code in [[:op_en:OpasnetBaseUtils]] so that it can be used in Finnish Opasnet as well.


Rivi 47: Rivi 49:
}
}


######################################
## opasnet.data downloads a file from Finnish Opasnet wiki, English Opasnet wiki, or Opasnet File.
## Parameters: filename is the URL without the first part (see below), wiki is "opasnet_en", "opasnet_fi", or "M-files".
## If table is TRUE then a table file for read.table function is assumed; all other parameters are for this read.table function.


opasnet.data <- function(filename, wiki = "opasnet_en", table = FALSE, ...)
{
if (wiki == "opasnet_en") {
file <- paste("http://en.opasnet.org/en-opwiki/images/", filename, sep = "")
}
if (wiki == "opasnet_fi") {
file <- paste("http://fi.opasnet.org/fi_wiki/images/", filename, sep = "")
}
if (wiki == "M-files") {
file <- paste("http://http://fi.opasnet.org/fi_wiki/extensions/mfiles/", filename, sep = "")
}
#if(table == TRUE) {
#file <- re#ad.table(file, header = FALSE, sep = "", quote = "\"'",
#          dec = ".", row.names, col.names,
#          as.is = !stringsAsFactors,
#          na.strings = "NA", colClasses = NA, nrows = -1,
#          skip = 0, check.names = TRUE, fill = !blank.lines.skip,
#          strip.white = FALSE, blank.lines.skip = TRUE,
#          comment.char = "#",
#          allowEscapes = FALSE, flush = FALSE,
#          stringsAsFactors = default.stringsAsFactors(),
#          fileEncoding = "", encoding = "unknown")
#return(file)
#}
#else {return(ge#tURL(file))}
}
############ tidy: a function that cleans the tables from Opasnet Base
# data is a table from op_baseGetData function
tidy <- function (data) {
data$Result <- ifelse(!is.na(data$Result.Text), as.character(data$Result.Text), data$Result)
if("Observation" %in% colnames(data)){test <- data$Observation != "Description"} else {test <- TRUE}
if("Havainto" %in% colnames(data)){test <- data$Havainto != "kuvaus"}
data <- data[test, !colnames(data) %in% c("id", "obs", "Result.Text")]
return(data)
}


############### Bring parts of summary table
############### Bring parts of summary table
Rivi 135: Rivi 96:


</rcode>
</rcode>
{{attack|# |Opasnet.data() does not work. Problems: 1) it seems to be unable to download files from M-files; 2) the read.table part does not work (error: line 2 did not have 7 elements (there were 29 columns!)), 3) error: could not find function getURL (this is maybe a problem with my own computer, as getURL has worked correctly in R-tools.)|--[[User:Jouni|Jouni]] 23:54, 28 December 2011 (EET)}}

Nykyinen versio 20. elokuuta 2013 kello 11.19

This page is just a placeholder for code in op_en:OpasnetBaseUtils so that it can be used in Finnish Opasnet as well.

Rcode generic

  • Functions: dropall, PTable, opasnet.data, tidy, summary.bring

+ Näytä koodi