Displaying 20 results from an estimated 10000 matches similar to: "Subsetting depth profiles based on maximum depth by group with plyr"
2013 Mar 22
3
Distance calculation
Hi Elisa,
I hope this is what you wanted.
dat1<-read.csv("peaks.csv",sep=",")
#Subset
dat2<-dat1[1:5,]
res1<-do.call(cbind,lapply(seq_len(nrow(dat2)),function(i) do.call(rbind,lapply(split(rbind(dat2[i,],dat2[-i,]),1:nrow(rbind(dat2[i,],dat2[-i,]))), function(x) {x1<-rbind(dat2[i,],x);
2013 Sep 02
1
R dataframe and looping help
HI,
You may try this:
dat1<- read.table(text="
CustID TripDate Store Bread Butter Milk Eggs
1 2-Jan-12 a 2 0 2 1
1 6-Jan-12 c 0 3 3 0
1 9-Jan-12 a 3 3 0 0
1 31-Mar-13 a 3 0 0 0
2 31-Aug-12 a 0 3 3 0
2 24-Sep-12 a 3 3 0 0
2 25-Sep-12 b 3 0 0 0
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat2<- dat1[,-c(1:3)]
res<- lapply(seq_len(ncol(dat2)),function(i)
2013 May 07
4
create unique ID for each group
Hey All,
I have a dataset(dat1) like this:
ObsNumber ID Weight
1 0001 12
2 0001 13
3 0001 14
4 0002 16
5 0002 17
And another dataset(dat2) like this:
ID Height
0001 3.2
0001 2.6
0001
2013 Apr 29
1
how to add new rows in a dataframe?
Hi,
dat1<- read.table(text="
id??????????????? t???????????????????? scores
2???????????????? 0??????????????????????? 1.2
2???????????????? 2???????????????????????? 2.3
2???????????????? 3??????????????????????? 3.6
2???????????????? 4??????????????????????? 5.6
2???????????????? 6??????????????????????? 7.8
3???????????????? 0??????????????????????? 1.6
3????????????????
2013 May 07
4
how to calculate the mean in a period of time?
Hi,
Your question is still not clear.
May be this helps:
dat2<- read.table(text="
patient_id????? t???????? scores
1????????????????????? 0??????????????? 1.6
1????????????????????? 1??????????????? 2.6
1????????????????????? 2???????????????? 2.2
1????????????????????? 3???????????????? 1.8
2????????????????????? 0????????????????? 2.3
2?????????????????????? 2???????????????? 2.5
2010 Mar 22
1
Replacing elements of list
Dear all,
I have following two list object, both are basically collection of matrices
:
dat1 <- matrix(rnorm(25*6), ncol=6)
dat1 <- split(dat1, seq(5,25,by=5))
dat1 <- lapply(dat1, matrix, ncol=6)
dat2 <- matrix(rnorm(25*4), ncol=4)
dat2 <- split(dat2, seq(5,25,by=5))
dat2 <- lapply(dat2, matrix, ncol=4)
Now I want to replace last 4 columns of each matrix at "dat1"
2012 Jul 01
2
list to dataframe conversion-testing for identical
HI R help,
I was trying to get identical data frame from a list using two methods.
#Suppose my list is:
listdat1<-list(rnorm(10,20),rep(LETTERS[1:2],5),rep(1:5,2))
#Creating dataframe using cbind
dat1<-data.frame(do.call("cbind",listdat1))
colnames(dat1)<-c("Var1","Var2","Var3")
#Second dataframe conversion
2010 Mar 30
2
Need help to split a given matrix is a "sequential" way
I need to split a given matrix in a sequential order. Let my matrix is :
> dat <- cbind(sample(c(100,200), 10, T), sample(c(50,100, 150, 180), 10,
> T), sample(seq(20, 200, by=20), 10, T)); dat
[,1] [,2] [,3]
[1,] 200 100 80
[2,] 100 180 80
[3,] 200 150 180
[4,] 200 50 140
[5,] 100 150 60
[6,] 100 50 60
[7,] 100 100 100
[8,] 200 150 100
[9,]
2008 Mar 25
2
Compare two data sets
I would like to compare two data sets saved as text files (example below) to determine if both sets are identical(or if dat2 is missing information that is included in dat1) and if they are not identical list what information is different between the two sets(ie output "a1", "a3" as the differing information). The overall purpose would be to remove "a1" and
2013 Jul 10
1
Kruskal.test
Hi,
Please dput() your example dataset.
dat1<- read.table(text="a?? a?? a?? a??? a??? b?? b??? b??? c??? c?? c??? c
2? 4??? 5?? 2??? 7??? 2?? 2??? 6??? 3??? 7?? 9??? 3
3? 3?? 4?? 1???? 6??? 8?? 1??? 3??? 5??? 2??? 6??? 3",sep="",header=FALSE,stringsAsFactors=FALSE)
library(reshape)
?dat2<-melt(as.data.frame(t(dat1)),id.var="V1")[,-2]
2008 May 11
1
Finding unmatched data between two dataframe using several factors
Hi R users
I am trying to find unmatched data from two dataframes. I would like to
find unmatched data based on several factors. For the following data:
dat1 <- data.frame(x = paste("A", 1:6, sep=""),
y = c("andy","bob","ciaran","dan", "eion",
"fred"))
dat1
dat2
2013 Jun 18
1
transform 3 numeric vectors empty of 0/1
Dear all,
Without a loop, I would like transform 3 numeric vectors empty of 0/1 of
same length
Vec1 : transform 1 to A and 0 to ""
Vec2 : transform 1 to B and 0 to ""
Vec3 : transform 1 to C and 0 to ""
to obtain only 1 vector Vec who is the paste of the 3 vectors (Ex : ABC,
BC, AC, AB,...)
Any idea ?
Thank you for your help
--
Michel ARNAUD
2009 Nov 21
3
"subset" or "condition" as argument to a function
Dear Rxperts!
I was wondering if it is possible to write a function which can take in
argument of a subset or condition.. Of course, I am aware of the alternate
methods like coplot, par.plot, xyplot etc... I am specifically interested in
using conditions/subsets with "plot"..
A simple fragmented example is shown here..
pltit <- function(y,x,dat,dat1,dat2,sbst) {
plot(y~x, data=dat,
2005 Dec 29
1
S4 classes: referencing slots with other slots
For those who suggest other ways to do this, I ALREADY HAVE ANOTHER
DESIGN SOLUTION, DESCRIBED AT THE END.
That being said, I want to know if it's possible to reference a slot
in an S4 class from another slot, i.e. I'd like to have the "self.*"
semantics of Python so that I can reuse a slot. That is, for various
reasons it would be nice to be able to do something like:
2012 Jun 07
3
conditional statement to replace values in dataframe with NA
Hello and thanks for helping.
#some data
L3 <- LETTERS[1:3]
dat1 <- data.frame(cbind(x=1, y=rep(1:3,2), fac=sample(L3, 6, replace=TRUE)))
#When x==1 and y==1 I want to replace the 1 values with NA
#I can select the rows I want:
dat2<-subset(dat1,x==1 & y==1)
#replace the 1 with NA
dat2$x<-rep(NA,nrow(dat2)
dat2$y<-rep(NA,nrow(dat2)
#select the other rows and rbind
2013 May 01
1
Multiple Paired T test from large Data Set with multiple pairs
Hi,
Assuming that your dataset is similar to the one below:
set.seed(25)
dat1<- data.frame(Algae.Mass=sample(40:50,10,replace=TRUE),Seagrass.Mass=sample(30:70,10,replace=TRUE),Terrestrial.Mass=sample(80:100,10,replace=TRUE),Other.Mass=sample(40:60,10,replace=TRUE),Site.X.Treatment=rep(c("ALA1A","ALA1U"),each=5),stringsAsFactors=FALSE)
library(reshape2)
2009 Sep 25
3
Problem on plotting TS using GGPLOT
Hi, I have following codes :
library(zoo); library(ggplot2); library(plyr)
dat <- rnorm(306); vv <- letters[1:6]; dat1 <- data.frame(dat, vv)
dat2 = zooreg(rnorm(51), as.yearmon(as.Date("2000-01-01")), frequency=12)
ggplot(dat1) +
geom_line(aes(y=dat, x=index(dat2), colour=vv), group=vv, size =
1.3)
However I got error while plotting them :
2007 Jun 23
2
Names of objects passed as ... to a function?
Dear list,
I have a function whose first argument is '...'. Each element of '...'
is a data frame, and there will be at least 2 data frames in '...'. The
function processes each of the data frames in '...' and returns a list,
whose components are the processed data frames. I would like to name the
components of this returned list with the names of the original data
2010 Oct 15
7
Problem with merging two zoo objects
Dear all, I have following 2 zoo objects. However when I try to merge those 2 objects into one, nothing is coming as intended. Please see below the objects as well as the merged object:
> dat11
V2 V3 V4 V5
2010-10-15 13:43:54 73.8 73.8 73.8 73.8
2010-10-15 13:44:15 73.8 73.8 73.8 73.8
2010-10-15 13:45:51 73.8 73.8 73.8 73.8
2010-10-15 13:46:21 73.8 73.8 73.8 73.8
2009 Aug 07
1
RMySQL - overwrite record, not table
Hi, useR-
In RMySQL, how do I overwrite records? (equivalent to "replace" query).
For example, suppose that dat2 is a newer data.frame than dat1.
con <- dbConnect(MySQL())
res <- dbWriteTable(con, "DBname", dat1, row.names=F, append=T, replace=T)
res <- dbWriteTable(con, "DBname", dat2, row.names=F, append=T, replace=T)
This would not update/replace the