Displaying 18 results from an estimated 18 matches for "numcolwise".
2011 May 11
3
ddply with mean and max...
I'm trying to use ddply to compute summary statistics for many variables
splitting on the variable site. however, it seems to work fine for mean() but
if i use max() or min() things fall apart. whats going on?
test.set<-data.frame(site=1:10,x=.Random.seed[1:100],y=rnorm(100))
means<-ddply(test.set,.(site),mean)
means
site x y
1 1 -97459496 -0.14826303
2
2010 Apr 21
2
Sparseby Problems
I've got a problem with the sparseby command (reshape library), and I have
reached the peak of my R knowledge (it isn't really that high).
I have a small data frame of 23 rows and 15 columns, here is a subset, the
first four columns are factors and the rest are numeric (only one, line54 is
provided).
bearID YEAR Season SEX line54
5 1900 8 3 0 16.3923519
11 2270
2010 Jan 04
4
function in aggregate applied to specific columns only
I want to use aggregate with the mean function on specific columns
gender <- factor(c("m", "m", "f", "f", "m"))
student <- c(0001, 0002, 0003, 0003, 0001)
score <- c(50, 60, 70, 65, 60)
basicSub <- data.frame(student, gender, score)
basicSubMean <- aggregate(basicSub, by=list(basicSub$student), FUN=mean, na.rm=TRUE)
This
2013 Oct 14
1
R Help-how to use sapply w/tapply
...oid using images to show dataset. Also, please read the posting guide esp. regarding home work, assignments etc.)
res <- sapply(Gene[,-1],function(x) tapply(x,list(Gene$Genotype),mean))
#or
res2 <-? aggregate(.~Genotype, data=Gene,mean)
#or
library(plyr)
?res3 <- ddply(Gene,.(Genotype),numcolwise(mean))
identical(res2,res3)
#[1] TRUE
resNew <- data.frame(Genotype=rownames(res),res,stringsAsFactors=FALSE)
?attr(resNew,"row.names") <- attr(res2,"row.names")
?identical(resNew,res2)
#[1] TRUE
A.K.
So I'm having a problem with the part b of the assignment....
2011 Oct 12
3
Applying function to only numeric variable (plyr package?)
My data frame consists of character variables, factors, and proportions,
something like
c1 <- c("A", "B", "C", "C")
c2 <- factor(c(1, 1, 2, 2), labels = c("Y","N"))
x <- c(0.5234, 0.6919, 0.2307, 0.1160)
y <- c(0.9251, 0.7616, 0.3624, 0.4462)
df <- data.frame(c1, c2, x, y)
pct <- function(x) round(100*x, 1)
I want to
2008 Dec 16
3
Check if data frame column is numeric
Hi R-users,
I want to apply a function to each column of a data frame that is numeric.
Thus I tried to check it for each column first:
> apply(df, 2, function(x) is.numeric(x))
A60 A64 A66a A67 A71 A75a A80
A85 A91 A95 A96 A97 A98 A99
FALSE FALSE FALSE FALSE FALSE FALSE FALSE
FALSE
2010 Mar 23
2
Adding matrix rows that have the same name?
Does anyone know if there is an R function that will take a matrix like this
jim 1 0 0 0 0 0
jim 0 1 0 0 0 0
jim 0 0 1 0 0 0
bob 1 0 0 0 0 0
bob 0 0 1 0 0 0
harry 0 0 1 0 0 0
harry 0 0 0 1 0 0
harry 0 0 0 0 1 0
harry 0 0 0 0 0 1
and make it like this? (that is, add together rows that have the same name?)
jim 1 1 1 0 0 0
bob
2013 Oct 29
0
Mean error
...:2])
?identical(res1,res2)
#[1] TRUE
# Also if you need to find means for each group ("Ungrazed vs. "Grazed")
by(mydata[,-3],mydata[,3],colMeans)
#or if column names are "V1", "V2", "V3"
aggregate(.~V3,mydata,mean)
#or
library(plyr)
?ddply(mydata,.(V3),numcolwise(mean))
A.K.
I have a data set with two columns of data that I want to find the mean of. ?
1 ? 6.225 ?59.77 Ungrazed
2 ? 6.487 ?60.98 Ungrazed
3 ? 4.919 ?14.73 Ungrazed
4 ? 5.130 ?19.28 Ungrazed
5 ? 5.417 ?34.25 Ungrazed
6 ? 5.359 ?35.53 Ungrazed
7 ? 7.614 ?87.73 Ungrazed
8 ? 6.352 ?63.2...
2013 Sep 09
0
Duplicated genes
...values.? You didn't provide information on how to select those unique genes.? Here, the first row of every duplicated gene will be selected and others are removed.
>
>But suppose, you want to get the mean values of those rows.
>library(plyr)
>?res<-ddply(dat1[,c(1,6:32)],.(gene), numcolwise(mean,na.rm=TRUE))
>dim(res)
>#[1] 639? 28
>
>A.K.
>
>
>
>
>
>
>
>________________________________
>From: Vivek Das <vd4mmind at gmail.com>
>To: arun <smartpink111 at yahoo.com>
>Sent: Monday, September 9, 2013 1:35 PM
>Subject: Urgent help...
2011 May 24
4
Sumarizar medidas repetidas
Hola
¿Alguno tiene un código para sumarizar medidas?
my.df <- data.frame( "ID" = c( rep("A", 3 ), rep("B",2),"C", rep("D",3) ),
"Obs.1" = rnorm( 9,0,1 ), "Obs.2" = rnorm( 9,0,3 ) )
Algo que quede mas bonito que esto:
by( my.df, my.df$ID, mean )
Gracias un saludo!
--
Patricia García González
[[alternative HTML
2008 Nov 03
4
How do you apply a function to each variable in a data frame?
I want to apply a more complicated function than what I use in my example,
but the idea is the same:
Suppose you have a data frame named x and you want to a function applied to
each variable, we'll just use the quantile function for this example. I'm
trying all sorts of apply functions, but not having luck. My best guess
would be:
sapply(x, FUN=quantile)
--
View this message in
2013 Feb 16
6
Extracting Numeric Columns from Data Fram
Hello,
I've got a data frame with a mix of numeric, integer and factor columns.
I'd like to pull out (or just operate only on) the numeric/integer columns.
Every thing I've found in searches is about how to subset by rows,
or how to operate assuming you have the column names. I'd like to pull
by type.
Thanks!
Barry
[[alternative HTML version deleted]]
2009 Jun 23
4
Apply as.factor (or as.numeric etc) to multiple columns
Hi R-helpers,
I have a dataframe with 60columns and I would like to convert several
columns to factor, others to numeric, and yet others to dates. Rather
than having 60 lines like this:
data$Var1<-as.factor(data$Var1)
I wonder if it's possible to write one line of code (per data type,
e.g. factor) that would apply a function (e.g., as.factor) to several
(non-contiguous) columns. So, I
2011 Jan 14
4
test
Hi, i have that table
Thesis Day A B C
1 0 83.43 90.15 22.97
1 0 85.50 94.97 16.62
1 0 83.36 95.38 20.70
1 0 84.47 92.16 23.58
1 0 83.98 95.33 19.39
1 0 82.86 93.78 24.55
1 0 83.39 92.67 19.56
1 0 85.17 95.24 17.95
1 0 81.62 93.32 28.49
1 0 82.99 92.85 19.73
1 0 81.11 95.67 27.20
1 0 83.39 94.69 16.51
1 0 79.56 89.87 30.39
1 0 80.54 93.32 21.76
1 0 82.11 92.58 22.17
1 14 85.65 94.00 19.19
1 14
2013 Apr 19
5
how to subtotal by rows
Dear R-users,
I have a dataset as like below, and I want to subtotal the values of rice,wheat and maize by year for each fid.
fid year rice wheat maize
------------------------------------------------
1 1995 5 NA NA
1 1995 NA 3 NA
1 1995 NA NA 2
1 1996 4 NA NA
1
2013 Oct 27
2
Heteroscedasticity and mgcv.
I have a two part question one about statistical theory and the other
about implementations in R. Thank you for all help in advance.
(1) Am I correct in understanding that Heteroscedasticity is a problem for
Generalized Additive Models as it is for standard linear models? I am
asking particularly about the GAMs as implemented in the mgcv package.
Based upon my online search it seems that some
2010 Mar 24
0
R-help ordinal regression
...gt; > str(m)
> 'data.frame':???9 obs. of? 7
> variables:
> $ V1: Factor w/ 3 levels "bob","harry",..: 3 3 3 1 1 2 2 2
> 2
> $ V2: int? 1 0 0 1 0 0 0 0 0
> <V3 through V7 are also numeric>
>
> library(plyr)
> ddply(m, "V1", numcolwise(sum))
> ? ???V1 V2 V3 V4 V5 V6 V7
> 1???bob? 1? 0? 1?
> 0? 0? 0
> 2 harry? 0? 0? 1? 1? 1? 1
> 3???jim? 1? 1? 1?
> 0? 0? 0
>
> ddply() takes a data frame as input and outputs a data
> frame. "V1" specifies
> the (categorical) variable over which reductions ar...
2010 Jul 26
1
After writing data in MMF using SEXP structure, can i reference in R?
...> ddply( x, .(GENEID), function(df)
> {with(as.integer(c(col1=any(col1), col2=any(col2), col3=any(col3),
col4=any(col4))))}
> )
You can do this a little more succinctly with colwise:
any_1 <- function(x) as.integer(any(x))
ddply(x, "GENEID", numcolwise(any_1))
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
[80]http://had.co.nz/
------------------------------
Message: 10
Date: Sat, 24 Jul 2010 08:55:01 -0500
From: Frank E Harrell Jr <[81]f.harr...