トップ
新規
一覧
単語検索
最終更新
ヘルプ
ログイン
アールメカブ
ConvertTableToRawData
をテンプレートにして作成
開始行:
[[Rの備忘録]]
古い記事だがhttp://tolstoy.newcastle.edu.au/R/e2/help/06/...
expand.dft <- function(x, na.strings = "NA", as.is = FAL...
# Take each row in the source data frame table and repl...
# using the Freq value
DF <- sapply(1:nrow(x), function(i) x[rep(i, each = x$F...
# Take the above list and rbind it to create a single D...
# Also subset the result to eliminate the Freq column
DF <- subset(do.call("rbind", DF), select = -Freq)
# Now apply type.convert to the character coerced factor
# columns # to facilitate data type selection for ea...
DF <- as.data.frame(lapply(DF,
function(x)
type.convert(as.character(x),
na.strings = na.strings,
as.is = as.is,
dec = dec)))
# Return data frame
DF
}
これを応用したのだと思う関数が[[NCStatsパッケージ:http://...
> source("http://www.rforge.net/NCStats/InstallNCStats.R")
> library(NCStats)
> ?NCStats
> expandTable
function (x, var.names = NULL, ...)
{
x <- as.data.frame.table(x)
df <- sapply(1:nrow(x), function(i) x[rep(i, each = x...
"Freq"]), ], simplify = FALSE)
df <- subset(do.call("rbind", df), select = -Freq)
for (i in 1:ncol(df)) {
df[[i]] <- type.convert(as.character(df[[i]]), ...)
}
rownames(df) <- NULL
if (!is.null(var.names)) {
if (length(var.names) < dim(df)[2])
stop("Too few var.names given.")
else if (length(var.names) > dim(df)[2])
stop("Too many var.names given.")
else names(df) <- var.names
}
df
}
<environment: namespace:NCStats>
終了行:
[[Rの備忘録]]
古い記事だがhttp://tolstoy.newcastle.edu.au/R/e2/help/06/...
expand.dft <- function(x, na.strings = "NA", as.is = FAL...
# Take each row in the source data frame table and repl...
# using the Freq value
DF <- sapply(1:nrow(x), function(i) x[rep(i, each = x$F...
# Take the above list and rbind it to create a single D...
# Also subset the result to eliminate the Freq column
DF <- subset(do.call("rbind", DF), select = -Freq)
# Now apply type.convert to the character coerced factor
# columns # to facilitate data type selection for ea...
DF <- as.data.frame(lapply(DF,
function(x)
type.convert(as.character(x),
na.strings = na.strings,
as.is = as.is,
dec = dec)))
# Return data frame
DF
}
これを応用したのだと思う関数が[[NCStatsパッケージ:http://...
> source("http://www.rforge.net/NCStats/InstallNCStats.R")
> library(NCStats)
> ?NCStats
> expandTable
function (x, var.names = NULL, ...)
{
x <- as.data.frame.table(x)
df <- sapply(1:nrow(x), function(i) x[rep(i, each = x...
"Freq"]), ], simplify = FALSE)
df <- subset(do.call("rbind", df), select = -Freq)
for (i in 1:ncol(df)) {
df[[i]] <- type.convert(as.character(df[[i]]), ...)
}
rownames(df) <- NULL
if (!is.null(var.names)) {
if (length(var.names) < dim(df)[2])
stop("Too few var.names given.")
else if (length(var.names) > dim(df)[2])
stop("Too many var.names given.")
else names(df) <- var.names
}
df
}
<environment: namespace:NCStats>
ページ名: