Difference between revisions of "OpasnetUtils/Drafts"
From Testiwiki
m |
(→Answer: new version of fillna added) |
||
Line 49: | Line 49: | ||
} | } | ||
− | + | # fillna takes a data.frame and fills the cells with NA with each level in that column. | |
+ | # object is the data.frame, marginals is a vector of columns (either column names or positions) that are to be filled. | ||
+ | # This version of fillna accepts column positions (as the previous version) and also column names in marginals. | ||
− | cat("The following objects are stored: ograph\n") | + | fillna <- function (object, marginals) { |
+ | a <- dropall(object) | ||
+ | if(!is.numeric(marginals)) marginals <- match(marginals, colnames(object)) | ||
+ | for (i in marginals) { | ||
+ | a[[i]] <- as.factor(a[[i]]) | ||
+ | a1 <- a[!is.na(a[[i]]), ] | ||
+ | a2 <- a[is.na(a[[i]]), ][-i] | ||
+ | addition <- data.frame(A = levels(a[[i]])) | ||
+ | colnames(addition) <- colnames(a)[i] | ||
+ | a2 <- merge(addition, a2) | ||
+ | a <- rbind(a1, a2) | ||
+ | } | ||
+ | return(a) | ||
+ | } | ||
+ | |||
+ | objects.store(ograph, fillna) | ||
+ | |||
+ | cat("The following objects are stored: ograph, fillna\n") | ||
</rcode> | </rcode> |
Revision as of 10:28, 16 November 2013
This page is a method.
The page identifier is Op_en6007 |
---|
Moderator:Jouni (see all) |
Give your opinion to the peer rating of the content of this page. |
Upload data
|
Question
Which functions are so useful that they should be taken into OpasnetUtils package? This page contains draft function which will be included when they are good enough and found important.
Answer
See also
- OpasnetUtils/Ograph, a previous code, now depreciated.
References
Related files
<mfanonymousfilelist></mfanonymousfilelist>