Displaying 20 results from an estimated 200 matches similar to: "tapply changing order of factor levels?"
2011 Apr 07
1
Assigning a larger number of levels to a factor that has fewer levels
Hello!
I have larger and a smaller data frame with 1 factor in each - it's
the same factor:
large.frame<-data.frame(myfactor=LETTERS[1:10])
small.frame<-data.frame(myfactor=LETTERS[c(9,7,5,3,1)])
levels(large.frame$myfactor)
levels(small.frame$myfactor)
table(large.frame$myfactor)
table(small.frame$myfactor)
myfactor has 10 levels in large.frame and 5 levels in small.frame. All
5
2011 Nov 04
2
Efficiency of factor objects
R factors are the natural way to represent factors -- and should be
efficient since they use small integers. But in fact, for many (but
not all) operations, R factors are considerably slower than integers,
or even character strings. This appears to be because whenever a
factor vector is subsetted, the entire levels vector is copied. For
example:
> i1 <- sample(1e4,1e6,replace=T)
> c1
2012 Mar 28
1
discrepancy between paired t test and glht on lme models
Hi folks,
I am working with repeated measures data and I ran into issues where the
paired t-test results did not match those obtained by employing glht()
contrasts on a lme model. While the lme model itself appears to be fine,
there seems to be some discrepancy with using glht() on the lme model
(unless I am missing something here). I was wondering if someone could
help identify the issue. On
2012 Jan 18
1
drop rare factors
I have a data frame with some factor columns.
I want to drop the rows with rare factor values
(and remove the factor values from the factors).
E.g., frame$MyFactor takes values
A 1,000 times,
B 2,000 times,
C 30 times and
D 4 times.
I want to remove all rows which assume rare values (<1%), i.e., C and D.
i.e.,
frame <- frame[[! (frame$MyFactor %in% c("A","B"))]]
except
2010 Jul 05
2
repeated measures with missing data
Dear R help group, I am teaching myself linear mixed models with missing data since I would like to analyze a stats design with these kind of models. The textbook example is for the procedure "proc MIXED" in SAS, but I would like to know if there is an equivalent in R. This example only includes two time-measurements across subjects (a t-test "with missing values"), but I
2012 Nov 24
1
Adding a new variable to each element of a list
Hello,
I have a list of data with multiple elements, and each element in the list
has multiple variables in it. Here's an example:
### Make the fake data
dv <- c(1,3,4,2,2,3,2,5,6,3,4,4,3,5,6)
subject <- factor(c("s1","s1","s1","s2","s2","s2","s3","s3","s3",
2003 Oct 02
3
indexing a vector
Dear All:
I'd like to know how to sort and then index a vector of floats by several
levels in R.
For example
>x<-rnorm(100)
> MyLevels<-quantile(x,probs=c(0,.5,1))
> MyLevels
0% 50% 100%
-2.11978442 -0.03770613 2.00186397
next i want to replace each x[i] in x by 1,2,3 or 4 depending on which
quantile that x[i] falls. How do I do that in a
2009 May 05
2
Can't build termstrc package from source
Hi,
I'm trying to build the termstrc 1.1 package from its source on R 2.7.2 on
Windows XP. However instead of building the package it just zips the entire
source into a .tar.gz file.
This is the first time I'm trying to build an R package from source. I
installed the R toolset for Windows and set RTools as well as Perl & MinGW
directories in the path.
Anybody tried this out? Any file
2017 Sep 08
2
quote()/eval() question
Dear list,
For a reason it would take me long to explain, I need to do something along
the lines of what's shown below -- i.e., create an object from
dplyr::summarise, and then evaluate it on a data frame.
I know I could directly do:
df %>% dplyr::summarise(x1_mean = mean(x1))
but this is not what I'm looking for.
library(dplyr)
df <- data.frame(x1 = rnorm(100), x2 =
2006 Apr 29
1
splitting and saving a large dataframe
Hi,
I searched for this in the mailing list, but found no results.
I have a large dataframe ( dim(mydata)= 1297059 16, object.size(mydata=
145280576) ) , and I want to perform some calculations which can be done by
a factor's levels, say, mydata$myfactor. So what I want is to split this
dataframe into nlevels(mydata$myfactor) = 80 levels. But I must do this
efficiently, that is, I
2011 Mar 30
2
summing values by week - based on daily dates - but with some dates missing
Dear everybody,
I have the following challenge. I have a data set with 2 subgroups,
dates (days), and corresponding values (see example code below).
Within each subgroup: I need to aggregate (sum) the values by week -
for weeks that start on a Monday (for example, 2008-12-29 was a
Monday).
I find it difficult because I have missing dates in my data - so that
sometimes I don't even have the
2012 Feb 22
1
xtable prcomp
Hi, I need to export to LaTex the summary of a PCA. So:
myPCA <- prcomp(myDF)
mySummary <- summary(myPCA)
#
print(xtable(mySummary))
How can I export to LaTeX not all the summary but only the first nPCs??
Best
Riccardo
2009 Mar 03
1
repeated measures anova, sphericity, epsilon, etc
I have 3 questions (below).
Background: I am teaching an introductory statistics course in which we are
covering (among other things) repeated measures anova. This time around
teaching it, we are using R for all of our computations. We are starting by
covering the univariate approach to repeated measures anova.
Doing a basic repeated measures anova (univariate approach) using aov()
seems
2007 Jun 08
1
How to make a table of a desired dimension
Hi ComRades,
I want to make a matrix of frequencies from vectors of a continuous
variable spanning different values. For example this code
x<-c(runif(100,10,40),runif(100,43,55))
y<-c(runif(100,7,35),runif(100,37,50))
z<-c(runif(100,10,42),runif(100,45,52))
a<-table(ceiling(x))
b<-table(ceiling(y))
c<-table(ceiling(z))
a
b
c
will give me three tables that start and end at
2015 Jul 21
2
glm com etiquetas en las variables
Hola:
Si aún hay alguien que no está de vacaciones, igual me pueden ayudar.
Quiero ajustar unos modelos:
REG_LOG <- glm (low ~ X, family = "binomial", data = DATOS)
Ejemplo:
library(MASS)
data(birthwt, package="MASS")
birthwt$low <- factor(birthwt$low)
birthwt$race <- factor(birthwt$smoke)
REG_LOG <- glm (low ~ smoke, family =
2003 Jun 04
2
convert factor to numeric
Hi R-experts!
Every once in a while I need to convert a factor to a vector of numeric
values. as.numeric(myfactor) of course returns a nice numeric vector of
the indexes of the levels which is usually not what I had in mind:
> v <- c(25, 3.78, 16.5, 37, 109)
> f <- factor(v)
> f
[1] 25 3.78 16.5 37 109
Levels: 3.78 16.5 25 37 109
> as.numeric(f)
[1] 3 1 2 4 5
>
What I
2009 Mar 20
1
How to use termstrc functions?
Hi,
I'm trying to use the package termstrc. However I cannot figure out
how to invoke helper functions like create_cashflows_matrix &
create_maturities_matrix. Even when I try to invoke those with the
data supplied with the package (say, corpbonds), it throws error
saying "Error in as.vector(x, mode) : invalid 'mode' argument". Can
anybody provide some working example
2006 Jun 07
2
o2cb_ctl: internal logic failure while creating node
Hi,
I am getting following tyoe of error while trying to configure node using ocfs2
o2cb_ctl: internal logic failure while creating node
My Kernel version is 2.6.9-22.ELsmp
Rpm which i use are
ocfs2-2.6.9-22.ELsmp-1.0.7-1.i686.rpm
ocfs2console-1.0.3-1.i386.rpm
ocfs2-tools-1.0.3-1.i386.rpm
after that I gave command
ocfs2console
Select Cluster ? Configure Nodes
Click on Add and enter the Name
2006 Jul 08
1
Summary Statistics for data.frame
I apologize for my constant questions but I am new to R and trying to
gain an appreciation for its capabilities. The following task is easy
in Excel and I was hoping somebody could give me a quick explanation
for how it can be acheived in R so I can avoid having to switch
between the two applications.
How do I find the Summary Statistics in one Vector of the dataframe by
levels in another of the
2006 Jul 11
8
Stop updated_at from auto updating?
Hi
Is there any way to temporarily stop the updated_at field from being
updated when a record is modified with ActiveRecord?
I have a date field which is keeping track of when the record data was
last checked by my application and my app manually updates it, of course
when I do this the updated_at field is also touched making it fairly
useless for finding out when the actual data was changed