Displaying 20 results from an estimated 2000 matches similar to: "best way to aggregate / rearrange data.frame with different data types"
2013 Jan 11
3
aggregate data.frame based on column class
Hi,
When using the aggregate function to aggregate a data.frame by one or more grouping variables I often have the problem, that I want the mean for some numeric variables but the unique value for factor variables.
So for example in this data-frame:
data <- data.frame(x = rnorm(10,1,2), group = c(rep(1,5), rep(2,5)), gender =c(rep('m',5), rep('f',5)))
aggregate(data,
2010 Jul 21
2
Variance of the prediction in the linear regression model (Theory and programming)
Hi, folks,
Here are the codes:
##############
y=1:10
x=c(1:9,1)
lin=lm(log(y)~x) ### log(y) is following Normal distribution
x=5:14
prediction=predict(lin,newdata=x) ##prediction=predict(lin)
###############
1. The codes do not work, and give the error message: Error in
eval(predvars, data, env) :
numeric 'envir' arg not of length one. But if I use the code after the
pound sign, it
2008 Apr 01
1
set the lower bound of normal distribution to 0 ?
Tom Cohen <tom.cohen78@yahoo.se> skrev: Thanks Prof Brian for your suggestion.
I should know that for right-skewed data,
one should generate the samples from a lognormal.
My problem is that x and y are two instruments that were thought to
be measured the same thing but somehow show a wide confidence interval
of the difference between the two intruments.This may be true that
these
2009 Sep 08
2
Very basic question regarding plot.Design...
Hello ALL!
I have a problem to plot factor (lets say gender) as a line, or at least
both line and point, from ols model:
ols1 <- ols(Y ~ gender, data=dat, x=T, y=T)
plot(ols1, gender=NA, xlab="gender", ylab="Y",
ylim=c(5,30), conf.int=FALSE)
If I convert gender into discrete numeric predictor, and use
forceLines=TRUE, plot is not nice and true, since it shows values
2008 Nov 17
5
how to calculate another vector based on the data from a combination of two factors
Hi,
I have a data set similar to the following
State Gender Quantity
TX Male 1
NY Female 2
TX Male 3
NY Female 4
I need to calculate cumulative sum of the quantity by State and Gender. The
expected output is
State Gender Quantity CumQuantity
TX Male 1 1
TX Male 3 4
NY Female 2 2
NY Female 4 6
I highly appreciate if someone can give me some hints on solving that in R.
Hao
--
View this
2008 Dec 03
2
changing colnames in dataframes
dear all,
I'm building new dataframes from bigger one's using e.g. columns F76, F83,
F90:
JJ<-data.frame( c( as.character(rep( gender,3))) , c( F76,6- F83, F90) )
Looking into JJ one has:
c.as.character.rep.gender..8...
c.6...F73..F78..F79..F82..6...F84..F94..F106..F109
1 w 2
2 w
2005 Feb 28
5
Using session data in model
Hi,
I want to use my some session data when I validate som data in the
model. The specific problem I have is that I present different forms
data based on gender, and then dependent of the gender, there''s
different fields that needs validation. I''m wondering what''s the
preffered way of doing this. The session data is not present in the
model, i.e:
class Myclass
2001 Oct 16
4
two way ANOVA with unequal sample sizes
Hi,
I am trying a two way anova with unequal sample sizes but results are not
as expected:
I take the example from Applied Linear Statistical Models (Neter et al.
pp889-897, 1996)
growth rate gender bone development
1.4 1 1
2.4 1 1
2.2 1 1
2.4 1 2
2.1 2 1
1.7 2 1
2.5 2 2
1.8 2 2
2 2 2
0.7 3 1
1.1 3 1
0.5 3 2
0.9 3 2
1.3 3 2
expected results are
2006 Nov 25
3
Multiple Conditional Tranformations
Greetings,
I'm learning R and I'm stuck on a basic concept: how to specify a
logical condition once and then perform multiple transformations under
that condition. The program below is simplified to demonstrate the goal.
Its results are exactly what I want, but I would like to check the
logical state of gender only once and create both (or any number of)
scores at once.
2005 Apr 19
1
How to make combination data
Dear R-user,
I have a data like this below,
age <- c("young","mid","old")
married <- c("no","yes")
income <- c("low","high","medium")
gender <- c("female","male")
I want to make some of combination data like these,
age.income.dat <- expand.grid(age,
2006 Feb 15
1
no convergence using lme
Hi. I was wondering if anyone might have some suggestions about how I can
overcome a problem of "iteration limit reached without convergence" when
fitting a mixed effects model.
In this study:
Outcome is a measure of heart action
Age is continuous (in weeks)
Gender is Male or Female (0 or 1)
Genotype is Wild type or knockout (0 or 1)
Animal is the Animal ID as a factor
2006 Jun 04
1
Nested and repeated effects together?
Dear R people,
I am having a problem with modeling the following SAS code in R:
Class ID Gr Hemi Region Gender
Model Y = Gr Region Hemi Gender Gr*Hemi Gr*Region Hemi*Region
Gender*Region Gender*Hemi Gr*Hemi*Region Gender*Hemi*Region
Gr*Gender*Hemi*Region
Random Intercept Region Hemi /Subject = ID (Gr Gender)
I.e., ID is a random effect nested in Gr and Gender, leading to
ID-specific
2006 Nov 05
3
struggling to plot subgroups
Hi Folks,
I have data that looks like this:
freq gender xBar
1000 m 2.32
1000 f 3.22
2000 m 4.32
2000 f 4.53
3000 m 3.21
3000 f 3.44
4000 m 4.11
4000 f 3.99
I want to plot two lines (with symbols) for the two groups "m" and
"f". I have tried the following:
plot(xBar[gender=="m"]~freq[gender=="f"]) followed by
2013 Jan 31
2
Help with multiple barplots
Hello: I need to create a six barplots from data that looks pretty close to what appears below. There are two grouping variables (age and gender) and three dependent variables for each grouping variables. I'm not really familiar with trellis graphics, perhaps there is something that can do what I need there, i don't know.
The thing is: I *need* these to appear on one row, with some way
2013 Apr 18
6
count each answer category in each column
Hey,
Is it possible that R can calculate each options under each column and
return a summary table?
Suppose I have a table like this:
Gender Age Rate
Female 0-10 Good
Male 0-10 Good
Female 11-20 Bad
Male 11-20 Bad
Male >20 N/A
I want to have a summary table including the information that how many
answers in each category, sth like this:
X
2006 Mar 02
5
Two foreign keys on the same column?
Let''s say I have three hypothetical MySQL tables:
? people, with columns id, gender, and source_id
belongs_to :boys and :girls
? boys, with columns id and name
has_many :people
? girls, with columns id and name
has_many :people
The gender column in people specifies which of the two source tables the
source_id refers to. For example, if we have values:
1, boy, 1
in people,
2013 Jan 04
2
"By" function Frame Conversion (with Multiple Indices)
Hello,
I have the following dataset. Please note that there are missing values on
records 4 and 5:
id,age,weight,height,gender
1,22,180,72,m
2,13,100,67,f
3,5,40,40,f
4,6,42,,f
5,12,98,66,
6,50,255,60,m
I'm using the "By" function like this:
list1 <- by(dataset[c("weight", "height")],
dataset[c("age", "gender")],
2010 Jan 21
1
Simple effects with Design / rms ols() function
Hi everyone,
I'm having some difficulty getting "simple effects" for the ols()
function in the rms package. The example below illustrates my
difficulty -- I'll be grateful for any help.
#make up some data
exD <- structure(list(Gender = structure(c(1L, 2L, 1L, 2L, 1L, 1L, 1L,
2L, 1L, 2L, 2L, 2L, 1L, 2L), .Label = c("F", "M"), class = "factor"),
2011 Jan 23
2
Creating subsets of a matrix
Hello,
Say I have 2 columns, bmi and gender, the first being all the values and the
second being male or female. How would I subset this into males only and
females only? I have searched these fora and read endlessly about select[]
and split() functions but to no avail. Also the table is not ordered.
bmi gender -> bmi gender + bmi gender
1 24.78 male
2010 Mar 06
2
Plot interaction in multilevel model
I am trying to plot an interaction in a multilevel model. Here is some
sample data. In the following example, it is longitudinal (i.e., repeated
measures), so the outcome, score (at each of the three time points), is
nested within the individual. I am interested in the interaction between
gender and happiness predicting score.
id <- c(1,1,1,2,2,2,3,3,3)
age <-