Displaying 20 results from an estimated 5000 matches similar to: "counting subgroup sums within a data frame"
2010 Jul 20
1
define subgroups based on position in table
Dear list,
I have a data frame with one column (group) and want to add a second column (sub) with a serial number that says to which subgroup a cell belongs. A subgroup contains the consecutive rows of the same group. The number of a subgroup is based on its position in the table. The first subgroup of A's and B's should have nr A1 and B1, the second nr A2 and B2, etc.. I hope the
2009 Oct 22
2
How to find moving averages within each subgroup of a data frame
Dear all,
If I have the following data frame:
> set.seed(21)
> df1 <- data.frame(col1=c(rep('a',5), rep('b',5), rep('c',5)), col4=rnorm(1:15))
col1 col4
1 a 0.793013171
2 a 0.522251264
3 a 1.746222241
4 a -1.271336123
5 a 2.197389533
6 b 0.433130777
7 b -1.570199630
8 b -0.934905667
9 b 0.063493345
10 b
2012 Jan 20
3
error
Unable to resolve error in seq.default(which(text == "")[1] + 1,
length(text), 1):
wrong sign in 'by' argument
I am trying to run this code
get.msg <- function(path) {
con <- file(path, open = "rt", encoding = "latin1")
text <- readLines(con)
# The message always begins after the first full line break
msg <- text[seq(which(text ==
2009 Mar 10
2
perform subgroup meta-analysis and create forest plot displaying subgroups
Hello,
I'm using the rmeta package to perform a meta analysis using summary statistics rather than raw data, and would like to analyze the effects in three different subgroups of my data. Furthermore, I'd like to plot this on one forest plot, with corresponding summary weighted averages of the effects displayed beneath each subgroup.
I am able to generate the subgroup analyses by simply
2009 Feb 02
2
concatenating 2 text columns in a data.frame
Hi,
I'm trying to concatenate values from two columns in a data frame. For
example, I have the following data.frame:
C1 C2 C3 C4 C5
A B *F C* Q
G H *I J* T
K D *R S* E
P L *M N* O
I'd like to concatenate text from columns C3 and C4, to yield either a
list or vector, like so:
NewCol
FC
IJ
RS
MN
Is this feasible in R?
Thanks!
2012 Mar 29
3
How to get the most frequent value of the subgroup
Dear Members of the R-Help,
While using a R function - 'aggregate' that you developed, I become to have a question.
In that function,
> aggregate(x, by, FUN, ..., simplify = TRUE)
I was wondering about what type of FUN I should write if I want to get "the most frequent value of the subgroup" as a summary statistics of the subgroups.
I will appreciate if I can get
2007 Jan 25
0
Subgroup discovery in R
I would very much like to apply "subgroup discovery" techniques to some
of the data I am analyzing at this moment.
Subgroup discovery is an interesting approach and is quite well known in
the Data Mining community, though in essence it is a purely statistical
approach.
To read an introductory article see "Subgroup discovery and visualization
methods"
2010 Apr 14
5
Running cumulative sums in matrices
Dear R-helpers,
I have a huge data-set so need to avoid for loops as much as possible. Can someone think how I can compute the result in the following example (that uses a for-loop) using some version of apply instead (or any other similarly super-efficient function)?
example:
#Suppose a matrix:
m1=cbind(1:5,1:5,1:5)
#The aim is to create a new matrix with every column containing the
1999 Jan 18
0
Selecting a subgroup
I use the following function to select a subgroup from a data vector
(usually to calculate descriptive stats).
select.range<-function (groupvec, min, max, data)
{
if (nargs() > 3) {
min.cond <- groupvec >= min
max.cond <- groupvec < max
cond <- min.cond & max.cond
selected <- na.remove(ifelse(cond, data, NA))
2004 Apr 02
1
cumsum() by subgroup
I need to do a simple cumulative sum by group and add the result to the
data. I found an earlier thread in the help files with a few suggestions.
Somewhat, one of the suggestions does not work with "my data", and I don't
really understand why ?
The error am getting using the "my data" below is...
Error in data.frame(..., check.names = FALSE) :
arguments imply
2010 Mar 30
4
Code is too slow: mean-centering variables in a data frame by subgroup
Dear R-ers,
I have a large data frame (several thousands of rows and about 2.5
thousand columns). One variable ("group") is a grouping variable with
over 30 levels. And I have a lot of NAs.
For each variable, I need to divide each value by variable mean - by
subgroup. I have the code but it's way too slow - takes me about 1.5
hours.
Below is a data example and my code that is too
2009 Jun 24
1
lattice wireframe within a loop ???
Hi,
I have the following problem. Calling wireframe within a loop results
into an empty window(s)
#generate some data
temp = expand.grid(A = 1:3,B = 1:3)
temp = cbind(temp, y1 = rnorm(9))
temp = cbind(temp, y2 = runif(9))
#plot y1 and y2 in two different windows
for(i in 1:2)
{
wireframe(y1 ~ A*B, temp, shade =T)
windows()
wireframe(y2 ~ A*B, temp, shade =T)
}
#However, calling it twice
2009 Jul 17
2
how to evaluate character vector within pnorm()
Hi,
I'm trying to evaluate a character vector within pnorm. I have a vector
with values and names
x = c(2,3)
names(x) = c("mean", "sd")
so that i tried the following
temp = paste(names(x), x, sep = "=")
#gives
#> temp
#[1] "mean=2" "sd=3"
#Problem is that both values 2 and 3 are taken as values for the mean
argument in pnorm
pnorm(0,
2009 Jan 03
1
how specify lme() with multiple within-subject factors?
I have some questions about the use of lme().
Below, I constructed a minimal dataset to explain what difficulties I
experience:
# two participants
subj <- factor(c(1, 1, 1, 1, 2, 2, 2, 2))
# within-subjects factor Word Type
wtype <- factor(c("nw", "w", "nw", "w", "nw", "w", "nw", "w"))
# within-subjects factor
2008 Sep 15
1
randomly sample within clustered data?
Dear useRs,
What is an efficient way to randomly sample from clustered data such
that I get equal representation from each cluster? For example, let's
say I want to randomly sample two cases from each cluster created by the
"id" variable in the following data frame:
> id<-c(rep("100", 4),rep("101", 3), rep("102", 6), rep("103",
2013 Jan 28
1
incorrect import?
Dear all,
I'm not getting what I'm doing wrong. The line below from my read.fsa.bin function throws an error when just loading my AFLP package and disappears when I load the zoo package as well.
#the line that throws the error
Index <- which(Peak == rollmax(Peak, k = 1 + 2 * floor((min(diff(SizeStandard)) * Fs - 1) / 2), fill = -Inf))
#the error
Error in UseMethod("rollmax")
2019 Sep 06
2
Cryptic error message from namespaceExport
Dear all,
Today I got this error message (R 3.6.1) when installing my package:
Error: package or namespace load failed for ?inlatools? in
namespaceExport(ns, exports):
undefined exports: .__C__inla
My package was using setOldClass("inla") and exported the "inla" class via
the NAMESPACE. It imports functions from the INLA package. Older versions
of the INLA package did not
2011 Jul 28
0
_: how to replace values in x by means in subgroups created in ...(not loops)
Re:_: how to replace values in x by means in subgroups created in ...(not loops)
Thanks, below some code and reply:
#_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_#
#-------------------------------------------------------
# my slow function with loops:
# replace_x_by_locallyMean_x_4_0s_in_y.f(x,y)
#-------------------------------------------------------
2014 Dec 09
2
UTF8 markdown vignette
Dear all,
I'm trying to use a Markdown vignette with UTF-8 encoding. It compiles well when knitting the vignette in RStudio, but it fails to recognize the UTF-8 settings when building the source package. Can someone point out what I'm doing wrong? I tried to put the relevant information below.
Best regards,
Thierry
Details:
Using 64-bit R 3.1.2 with encoding = "native.enc"
2010 Oct 08
2
Count values in a dataframe with respect to groups
Dear all,
I am looking for a function to count values belonging to a class within a dataframe (and ignore NAs).
grp = c(1,1,1, 1,2, 2,2)
val = c(2,1,5,NA,3,NA,1)
dta = data.frame(grp=grp, val=val)
The result should look like:
grp count
1 3
2 2
At the moment, I am trying to find a function for FUN in aggregate, but with no success. Can anybody help me?
Thanks in advance.
Marcus