Displaying 20 results from an estimated 6000 matches similar to: "Avoiding loops to detect number of coincidences"
2011 Jul 12
1
Creating a zero matrix when a condition doesn´t get it
Hi all,
I first create a matrix/data frame called "d2" if another matrix
accomplishes some restrictions "dacc2"
da2<-da1[colSums(dacc2)>9,]
da2<-da2[(da2[,13]=24),]
write.csv(da2, file =paste('hggi', i,'.csv',sep = ''))
The thing is if finally da2 cannot get/passs the filters, it cannot writte a
csv because there is no any true condition.
2008 Dec 09
2
Need help optimizing/vectorizing nested loops
Hi,
I'm analyzing a large number of large simulation datasets, and I've
isolated one of the bottlenecks. Any help in speeding it up would be
appreciated.
`dat` is a dataframe of samples from a regular grid. The first two
columns are the spatial coordinates of the samples, the remaining 20
columns are the abundances of species in each cell. I need to calculate
the species richness in
2013 Mar 18
2
Confirmatory factor analysis using the sem package. TLI CFI and RMSEA absent from model summary.
Hi R-help,
I am using the sem package to run confirmatory factor analysis (cfa) on some questionnaire data collected from 307 participants. I have been running R-2.15.3 in Windows in conjunction with R studio. The model I am using was developed from exploratory factor analysis of a separate dataset (n=439); it includes 18 items that load onto 3 factors. I have used the sem package documentation
2013 Mar 29
1
multiple plots and looping assistance requested (single plot)
HI Irucka,
Please check this:
temp<- structure(list(`:Bostoncitydata` = structure(list(Month = c(1L,
2L, 3L, NA), Data1 = c(1.5, 12.3, 11.4, NA), Data2 = c(9.1342,
12.31, 3.5, NA)), .Names = c("Month", "Data1", "Data2"), class = "data.frame", row.names = c(NA,
-4L)), `:Chicagocitydata` = structure(list(Month = c(1L, 2L,
3L, 4L, 5L, NA), Data1 = c(1.52,
2012 May 04
7
Breaking up a Row in R (transpose)
I have the following:
Time A1 A1 B1 B1 C1 C2
x y x y x y
0 5 6 6 7 7 9
1 3 4 4 3 9 9
2 5 2 6 4 7 4
I want to change it to the following:
0 1 2
x y x y x y
A1 5 6 3 4 5 2
B1
2009 Oct 09
1
Placing text in a ggplot
I am attempting to graph 12 months of temperatures, delineate the months with a vline and place the names of the months at the top of the graph.
So far I have gotten everything to work except the names, despite getting a similar graph to work yesterday the day before yesterday with Baptise A's help. Can anyone suggest what I am doing wrong. Data set is below code.
Thanks.
Code
2009 May 28
2
ggplot2 legend
Hi:
I need some help with the legend. I got 14 samples(Muestreo) and I
am trying to plot a smooth line for each sample. I am able to accomplish that but the problem is that the legend only displays every other sample. How can I force the legend to show all of my Muestreos? Thanks in advance.
fish_ByMuestreo <- structure(list(data = structure(list(SampleDate = structure(c(3L,
3L, 3L, 3L,
2008 Dec 02
1
ggplot2 facet_wrap problem
Hadley,
I don't know if I am doing something wrong or if it is ggplot please
see the two graphs at the bottom of the page (code).
melt.nut <- (structure(list(RiverMile = c(119L, 119L, 119L, 119L, 119L, 119L,
119L, 119L, 119L, 148L, 148L, 148L, 148L, 148L, 148L, 148L, 179L,
179L, 179L, 179L, 179L, 179L, 179L, 185L, 185L, 185L, 185L, 185L,
185L, 185L, 190L, 190L, 190L, 190L, 190L, 190L,
2011 Jun 24
4
ggplot2 month and year boxplot x axis order problem
Hi
I am very new to R, I am attempting to produce a monthly boxplot with the
following fish thermal telemetry data:
ID Temp Date.Time Month.Year Month Week Shortdate
1 1734 4.4140 04/05/2010 11:56 05,2010 May 19 04/05/2010
2 1734 4.1002 04/05/2010 12:06 05,2010 May 19 04/05/2010
3 1734 3.9433 04/05/2010 12:09 05,2010 May 19 04/05/2010
4 1734 3.6295
2012 Aug 06
5
sapply() and by()
Hello everyone,
I have a dataset with 5 colums (4 colums with thresholds of weather
stations and one with month - data of 5 years). Now I would like to
calculate the average for each month.
I tried this unsuccessfully:
lf.med <- sapply(LF[,1:4],mean,LF[,5])
Error in mean.default(X[[1L]], ...) :
'trim' must be numeric and have length 1
With
lf.med <- by(LF[,1:4],LF[,5],mean)
2011 Jun 09
1
lattice plot query
Dear R Group
I have the following data for which I am trying to create subject wise
lattice plot for a given attribute and product .
though the lattice plot is generated, for some reasons that i dont
understand in each plot the subject panels take a random order, I would
rather want all the plots to display the subject order in the same order
as how i have ordered this particular factor level.
2011 Jun 13
1
Heatmap in R and/or ggplot2
I have a dataframe df with columns x, y, and height. I want to create a
heatmap-like plot that creates a grid of x by y, and then color codes the
grid depending on the value of height.
Is there a ggplot2 object to do this? I'm able to easily do this in Excel
with pivot tables and conditional formatting so I'm including an image that
is close to the output I want. I want to be able to
2012 Nov 14
2
indexing for Wilcoxon test (take 2)
Hi everyone,
I've been asked to run a number of Wilcoxon tests on some behavioral data
(below is a sample). They want me to compare each trial to the first
trial, considered the control trial. I know I can use brackets to index and
select, for example, trial 1 vs. trial 4 (not exactly sure how to set that
up either) but it would save me a ton of time if there was a way to do all
the
2017 Jul 22
1
3-day moving average for block maxima
Dear r-users,
I would like to construct 3-day moving average for block maxima series.
I tried this:
bmthree <- lapply(split(dt, dt$Year), function(x) max(sapply(1:(nrow(x)-2),
function(i) with(x, mean(Amount[i:(i+2)],na.rm=TRUE)))))
bmthree
and got the following output.
$`1971`
[1] 70.81667
$`1972`
[1] 68.94553
$`1973`
[1] 102.7236
$`1974`
[1] 73.6625
$`1975`
[1]
2010 Feb 28
1
ggplot 'annotate problem' again.
I had a problem annotating a graph last year ( see http://n4.nabble.com/Putting-names-on-a-ggplot-td907158.html#a907158 for the discussion)
Stefan (smu) provided a solution using annotate(). However I apparently did not update the graph file and,now, when I go back to the thread and try to use Stefan's solution it does not seem to work although I am sure that it did then.
The problem
2009 Nov 26
1
lattice --- different properties of lines corresponding to type=c("l", "a") respectively
I think the subject says it all. I want to make a simple lattice plot,
using xyplot with the
argument type=c("l","a").
The problem then is that in the resulting plot it is
difficult/impossible to see which plot corresponds to the average
and which to the individual profiles. I triedthings like extra
arguments lwd=c(1,3) or col=c("blue","red")
hoping
2008 Aug 26
1
processing subset lists and then plot(density())
d <- structure(list(Site = structure(c(8L, 12L, 7L, 6L, 11L, 5L, 10L,
4L, 3L, 2L, 1L, 9L, 8L, 12L, 7L, 6L, 11L, 5L, 10L, 4L, 3L, 2L,
1L, 9L, 8L, 12L, 7L, 6L, 11L, 5L, 10L, 4L, 3L, 2L, 1L, 9L, 8L,
12L, 7L, 6L, 11L, 5L, 10L, 4L, 3L, 2L, 1L, 9L, 8L, 12L, 7L, 6L,
11L, 5L, 10L, 4L, 3L, 2L, 1L, 9L, 8L, 12L, 7L, 6L, 11L, 5L, 10L,
4L, 3L, 2L, 1L, 9L, 8L, 12L, 7L, 6L, 11L, 5L, 10L, 4L, 3L, 2L,
1L, 9L,
2013 Mar 01
7
Conditional Weighted Average (ddply or any other function)
Hello R community,
I am computing weighted average statistic by using ddply function:
My data set is:
N1 T1 S1 I1 C1 FY-4 ROE11 EPS11 MKT11
N1 T1 S1 I1 C1 FY-3 ROE12 EPS12 MKT12
N1 T1 S1 I1 C1 FY-2 ROE13 EPS13 MKT13
N1 T1 S1 I1 C1 FY-1 ROE14 EPS14 MKT14
N1 T1 S1 I1 C1 FY0 ROE15 EPS15 MKT15
N1 T1 S1 I1 C1 FY1 ROE16 EPS16 MKT16
N1 T1 S1 I1 C1 FY2 ROE17
2018 May 08
2
Bilateral matrix
I have data on current and previous location of individuals. I would like
to have a matrix with bilateral movement between locations. I would like
the final output to look like the second table below.
I have tried using crosstab() from the ecodist but I do not have another
variable to measure the flow. Ultimately I would like to compute the
probability of movement between cities (movement to
2010 Jul 12
1
What is the degrees of freedom in an nlme model
Dear all,
I want to do a F test, which involves calculation of the degrees of
freedom for the residuals. Now say, I have a nlme object "mod.nlme". I
have two questions
1.How do I extract the degrees of freedom?
2.How is this degrees of freedom calculated in an nlme model?
Thanks.
Jun Shen
Some sample code and data
=================================================================