similar to: function to include factors in summary data frame

Displaying 20 results from an estimated 20000 matches similar to: "function to include factors in summary data frame"

2013 Jun 10
1
modify and append new rows to a data.frame using ddply
Hi, I have a data.frame that contains a variable act which records the duration (in seconds) of two states (wet-dry) for several individuals (identified by Ring) over a period of time. Since I want to work with daytime (i.e. from sunrise till sunset) and night time (i.e. from sunset till next sunrise), I have to split act from time[i] till sunset and from sunset until time[i+1], and from time[k]
2011 Feb 25
1
data.frame operations
Hi All, I've been doing circles with this all morning, although I'm sure there's a simple solution. I have a data.frame "pop" as follows: > pop ind xloc yloc gonad 1 1 5 2 12 2 1 5 4 25 3 1 3 3 30 4 1 5 4 10 5 1 1 4 08 . . . . . 10 1 1 4 11 And I need the following steps: 1. Sum
2011 Oct 25
2
extract data for specific levels factor
Dear all, I'm trying to analyze data with the following structure: ind cat tx age 40.2 por fol peq vh 35 41.9 por fol med vh 35 68.9 por fol preov vh 35 71.5 por fol peq ser 37 67.5 por fol med ser 37 76.9 por fol preov ser 37 78.7 por fol peq otr 37 78.3 por fol med otr 37 82.1 por fol
2009 Aug 05
2
using ddply but preserving some of the outside data
I have a bit of a quandy. I'm working with a data set for which I have sampled sites at a variety of dates. I want to use this data, and get a running average of the sampled values for the current and previous date. I originally thought something like ddply would be ideal for this, however, I cannot break up my data by date, and then apply a function that requires information
2011 Apr 27
3
MASS fitdistr with plyr or data.table?
I am trying to extract the shape and scale parameters of a wind speed distribution for different sites. I can do this in a clunky way, but I was hoping to find a way using data.table or plyr. However, when I try I am met with the following: set.seed(144) weib.dist<-rweibull(10000,shape=3,scale=8) weib.test<-data.table(cbind(1:10,weib.dist))
2009 Nov 16
8
extracting the last row of each group in a data frame
Hi, I would like to extract the last row of each group in a data frame. The data frame is as follows Name Value A 1 A 2 A 3 B 4 B 8 C 2 D 3 I would like to get a data frame as Name Value A 3 B 8 C 2 D 3 Thank you for your suggestions in advance Jeff
2009 Jun 25
4
Using by() and stacking back sub-data frames to one data frame
Dear all, I have a code where I subset a data frame to match entries within levels of an factor (actually, the full script uses three difference factors do do that). I'm very happy with the precision with which I can work with R, but since I loop over factor levels, and the data frame is big, the process is slow. So I've been trying to speed up the process using by(), but I got stuck at
2011 Feb 21
3
Subset according to groups NA proportion within specific variables
Dear R-List, I have a dataframe with one grouping variable (x) and three response variables (y,z,w). df<-data.frame(x=c(rep(1,3),rep(2,4),rep(3,5)),y=rnorm(12),z=c(3,4,5,NA,NA,NA,NA,1,2,1,2,1),w=c(1,2,3,3,4,3,5,NA,5,NA,7,8)) >df      x            y            z     w      1      0.29306106  3      1      1      0.54797780  4      2      1     -1.38365548  5      3      2     -0.20407986
2010 Jan 20
5
standardizing one variable by dividing each value by the mean - but within levels of a factor
Hello! I have a data frame with a factor and a numeric variable: x<-data.frame(factor=c("b","b","d","d","e","e"),values=c(1,2,10,20,100,200)) For each level of "factor" - I would like to divide each value of "values" by the mean of "values" that corresponds to the level of "factor" In other
2010 Sep 06
3
Aggregate certain rows in a matrix
Hi, I have a matrix that looks like this a <- c(1,1,1,1,2,2,3,3,3,3) b <- c(2,2,2,3,4,4,4,5,5,6) c <- c(1,2,3,4,5,6,7,8,9,10) M <- matrix(nr=10,nc=3) M[,1] <- a M[,2] <- b M[,3] <- c > M [,1] [,2] [,3] [1,] 1 2 1 [2,] 1 2 2 [3,] 1 2 3 [4,] 1 3 4 [5,] 2 4 5 [6,] 2 4 6 [7,] 3 4 7
2011 Feb 28
2
converting the string columns in a data.frame to factors?
Dear All, I'm not sure if I understand the parameter stringsAsFactors correctly. I'm trying to convert the string columns in aframe1 to factors. But it seems stringsAsFactors=T in as.data.frame() doesn't do anything. Could anybody let know what is the correct way to converting strings to factors? > aframe1=data.frame(x=LETTERS[1:10], y=LETTERS[1:10], stringsAsFactors=F) >
2012 Aug 17
3
Apply a function according to factor levels.
Dear all, I have a question on applying a function to the data according to factor levels. For example, for the data below, what is the best way to apply a function to "values" according to different levels of "samples" (1,2,3,4,5)? values ind sample 1 0.03325 1 1 2 0.03305 1 1 3 0.03185 1 1 4 0.03515 1 1 5 0.03375 1 1 6 0.01180
2010 Feb 08
7
data frames; matching/merging
Hi all, I'm feeling a little guilty to ask this question, since I've written a solution using a rather clunky for loop that gets the job done. But I'm convinced there must be a faster (and probably more elegant) way to accomplish what I'm looking to do (perhaps using the "merge" function?). I figured somebody out there might've already figured this out: I have
2012 Dec 02
2
Change case of factor in data frame
I am trying to write a function to change the case of all of the text in a data frame to lower case. I do not have foreknowledge of the data frame names or the data types of each column. It seems that if one references the data frame by index, then it returns class "data.frame" but if it is referenced by name, it returns class "factor" or whatever the column actually is:
2009 Jul 08
1
nested model with random factors
I am really having trouble with getting the right syntax for my model. Here is a truncated version of my data: > data Ind Treatment Order Date PC1 1 PER14 SC 3rd 4-May-09 0.5704611 2 PER14 SH 1st 26-Apr-09 0.5329025 3 PER14 AC 2nd 29-Apr-09 2.1392279 4 PER25 SC 2nd 29-Apr-09 -0.2083382 5 PER25 SH 3rd 3-May-09 3.7818356 6
2006 Jun 16
1
Assignemt problem ,,,,,,,,,,,,,,,
  Hello list, i have a very simple question about matrix assignment. i did like this. res<-1:30 dim(res)<-c(5,6) ind<-1:6 now i want to assign the value of this variable ind to first coloumn in matrix res. like res[,1]<-ind but this code is giving error , Actualy i have a for loop and value of ind variable is changing every time ,,total 6 times,,i want to assign every vlaue
2011 Apr 28
1
Extract complete rows by group and maximum
Hi I'm trying to extract complete rows from a dataframe by group based on the maximum in a column within that group. Thus I have a dataframe: cvd_basestudy ... es_time ... _____________ study1 ... 0.3091667 study2 ... 0.3091667 study2 ... 0.2625000 study3 ... 0.3033333 study3 ... 0.2625000 __________ etc I can extract the basestudy and the max(es_time)
2009 Sep 06
1
struggling with "split" function
I am very sorry for such a simple question, but I am struggling with "split". I have the following data frame: x<-data.frame(A=c(NA,NA,NA,NA,"split",NA,NA,NA,NA,"split",NA,NA,NA,NA,"split",NA,NA,NA,NA),
2010 Apr 14
6
sum specific rows in a data frame
I have a data frame called "pose": DESCRIPTION QUANITY CLOSING.PRICE 1 WHEAT May/10 1 467.75 2 WHEAT May/10 2 467.75 3 WHEAT May/10 1 467.75 4 WHEAT May/10 1 467.75 5 COTTON NO.2 May/10 1 78.13 6 COTTON NO.2 May/10 3 78.13 7 COTTON NO.2 May/10 1 78.13
2011 Jul 27
2
Writing a summary file in R
Hello, I have an input file: http://r.789695.n4.nabble.com/file/n3700031/testOut.txt testOut.txt where col 1 is chromosome, column2 is start of region, column 3 is end of region, column 4 and 5 is base position, column 6 is total reads, column 7 is methylation data, and column 8 is the strand. I would like a summary output file such as: