Displaying 20 results from an estimated 5000 matches similar to: "sapply( ) a loop function"
2011 Jul 21
1
Select Random Rows from a dataframe
Hi all,
I have a dataframe of behavioral observations from 360 fish, each with 241 observation points(rows), which looks like this:
> head(d)
fish treatment tank trial video tid pid ang.chg abs.ac t len vel d2p x y
1 1 3 1 1 1 1 1 NA NA 0.0 0.000 NA NA 5.169 9.617
2
2011 Jul 22
1
applying a loop to multiple dataframes
Hello again R-folks,
I'm trying to apply a loop to multiple data frames and then organize the data in a manageable form. I have the code for my loop figured out (thanks to help from this list)...it runs up to 2000 iterations of a "while" loop until it finds a 40-row "d2p" column sum >5
n<-nrow(dsub.f1)
test<-0
for(k in 1:2001){
if(k>2000){
break} #stops
2011 Nov 07
1
Accessing ENVSXP and CLOSXP while processing parsed R code
Hello Guys,
Following up my earlier mail where I am trying to write an alternative
front-end for R, I had a question about accessing the closures and
environments in R code.
Here's the function taken and modified a little from "*Lexical Scope and
Statistical Computing*"
=====================================================================
f<-function(){
2003 Jun 06
2
little manipulation on data frame
Dear all,
I have data like 3 coulmns and many rows. Each entry
is less than 10.
Example
x y z
1 5 3 2
2 3 7 8
3 8 9 5
4 5 4 6
--------------------------
---------------------------
I have to sum entries of each coulmn (seperately) till
it be 10. This i have to start for each row. And I
want to assign no. of rows needed including that row
too(it to be 10 or 10+, the moment it exceeds 10, i
2007 Apr 18
1
Gentleman and Ihaka , 2000 paper question
In their paper, "Lexical Scope and Statistical Computing", the authors (
Gentleman and Ihaka ) go to great length explaining why R's use of
lexical scoping creates advantages when doing statistical computations.
If anyone has or is familiar with this paper, could they provide the
main program code for how the "newton" function would be called in their
example on page 500
2009 Aug 30
2
aggregating irregular time series
Hi,
I have a couple of aggregation operations that I don't know how to
accomplish. Let me give an example. I have the following irregular
time series
time x
10:00:00.021 20
10:00:00.224 20
10:00:01.002 19
10:00:02:948 20
1) For each entry time, I'd like to get sum of x for the next 2
seconds
2006 Oct 30
2
how to set debug breaks
Hi,
I am new in R and have some frustrations as how to set debug breaks during
emacs R debug. I use debug () as where or which function to debug. But
during the debug, e.g., I have a for loop at the beginning of the function
code and want the code execution to jump through that for loop and set a
break after that. How to do that? Is there a web site detailing the syntax
of the debugging of R?
2004 Mar 01
6
How to plot Histogram with frequence overlaid by distribution curve
Hi,
I am facing the problem that I want to plot a histogram chart set
freq to true and overlay with normal or weibull or exponential distribution
curve.
The sample code is shown as below:
>samp<-c(-8.2262,-8.2262,-8.2262,-8.20209,-8.09294,-8.07321,-8.07321,
-8.07321,-8.07175,-8.04948,-8.04948,-8.04948,-8.03848,-8.03848,
2011 Mar 17
3
Beginner question: How to replace part of a filename in read.csv?
I would like to use samp as a part of a filename that I can change. My source
files are .csv files with date as the file name, and I would like to be able
to type in the date (later perhaps automate this using list.files) and then
read the csv and write the pdf automatically. I have tried different
combinations with "" and () around samp, but I keep getting the error
"object
2012 Sep 20
3
lattice dotplot reorder contiguous levels
my reproducible example
test<-structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L), .Label = c("A",
"B", "C", "D", "E"), class = "factor"),
2011 Sep 06
2
Generalizing call to function
Hello guys,
I would like to ask for help to understand what is going on in
"func2". My plan is to generalize "func1", so that are expected same
results in "func2" as in "func1". Executing "func1" returns...
0.25 with absolute error < 8.4e-05
But for "func2" I get...
Error in dpois(1, 0.1, 23.3065168689948, 0.000429064542600244,
2003 Apr 08
3
density ranges for uniform law
Hello,
I would have some details and explanations about the results I get.
In fact, I start with a uniform sample between -1 and 1, and then plot its
density.
My problem is that the density ranges are much more longer than I expected :
samp <- runif(10000,-1,1)
plot(density(samp))
Instead of varying between -1 and 1, the density varies between approximaly
-1.5 and 1.5
Could someone explain
2004 Mar 09
2
maxima
Dear all,
suppose I have a bi-variate function f(x,y), I want to find the maxima. I
define x and y vector, and get matrix z=f(x,y). how can I get which (x0,y0)
makes z become the maxima?
I can do two loops to get the x0 and y0, but I think there may exist a
function to do this.
2017 Nov 12
2
create waveform sawtooth
My tuneR sawtooth wave function generator is broken.
When I use the sine function, I get exactly what I expect: a sine wave whose frequency is defined by the freq parameter. In particular, higher frequencies have shorter wavelengths (more cycles per second means shorter waves). When I create a sawtooth wave, the opposite seems to occur: higher frequencies result in longer waves. But that?s not
2009 Feb 24
2
lmer, estimation of p-values and mcmcsamp
(To the list moderator: I just subscribed to the list. Apologies for not
having done so longer before trying to post.)
Hi all,
I am currently using lmer to analyze data from an experiment with a
single fixed factor (treatment, 6 levels) and a single random factor
(block). I've been trying to follow the online guidance for estimating
p-values for parameter estimates on these and other
2011 Mar 18
3
exploring dist()
Hello, everybody,
I hope somebody could help me with a dist() function.
I have a data frame of size 2*4087 (col*row), where col corresponds to the
treatment and rows are
species, values are Hellinger distances, I should reconstruct a distance
matrix
with a dist() function. I know that "euclidean" method should be used.
When I type:
dist(dframe,"euclidean")
it gives me a
2000 Feb 24
2
(-1 as index) OR (envelope for QQ)
I'm new to R (and to S) and am wondering about code from pages 72 and
83 of MASS (Venables+Ripley, 3rd edition), to draw an envelope on a QQ
plot. Copying from the book, I've got:
#... code whose gist is "a.fit <- nls(..."
num.points <- length(resid(a.fit))
qqnorm(residuals(a.fit)) # illustrate data-model residuals
qqline(residuals(a.fit))
samp <-
2017 Nov 12
0
create waveform sawtooth
Ccing the maintainer if the tuneR package.
Looks to me like sawtooth (and square) don't behave as expected when using xunit="samples". Workaround is to use xunit="time" instead:
sawtooth(110,duration=1/100,samp.rate=sample_rate,xunit="time")
I looked at the code but found it to be opaque.
--
Sent from my phone. Please excuse my brevity.
On November 12, 2017
2010 Jul 08
1
Time value not sorting properly
I have a dataframe of animal locations that I need to have in incremental
order so that I can calculate the distance traveled between each time step.
However, I have identified a few values that don't seem to sort properly.
For instance, the last value in the table below should be the first value
after sorting, since its time value is '00:01:35'. But, for some reason, it
seems to be
2011 Feb 10
3
Finding length of unique numbers in a vector
Hello there, would you please look into my codes? Here I have following:
> set.seed(100)
> samp <- sample(c(1,-1,0), 20, replace=T); samp
[1] 1 1 -1 1 -1 -1 0 -1 -1 1 -1 0 1 -1 0 0 1 -1 -1 0
Here I want to calculate the length of each unique number for above vector.
How can I do that?
Thanks in advance
[[alternative HTML version deleted]]