Displaying 20 results from an estimated 200 matches similar to: "Modifying values outside a function using "apply"."
2012 May 21
2
Problem with function
Hi,
I'm new to R, so apologies in advance for the triviality of this question,
but I was wondering if anyone could tell me why this function doesn't return
the expected output, i.e. a matrix containing two columns from a large data
frame called 'finalTable'? Oddly, the statement between the curly brackets
works if run with 'thisCol' and 'thatCol' already defined.
2008 Dec 04
2
How to optimize this codes ?
How to optimize the for-loop to be reasonably fast for sample.size=100000000 ? You may want to change sample.size=1000 to have an idea what I am achieving.
set.seed(143)
A <- matrix(sample(0:1, sample.size, TRUE), ncol=10, dimnames=list(NULL, LETTERS[1:10]))
B <- list()
for(i in 1:10) {
B[[i]] <- apply(combn(LETTERS[1:10], i), 2, function(x) { sum(apply(data.frame(A[,x]), 1,
2004 Aug 03
3
basic questions: any place for them
Hi
I have two basic questions, and here they go, but I was wondering as
well where can I ask these basic questions without bothering you
people
I've used Splus and now I'm using R and there's some functions that I
can't simply find
one:
sort.col
that allows data.frames to be sort by a given col
(I saw the funtion sort but that's for vectors. and I can't believe I
2009 Sep 03
1
Output from as.windrose() in oce package baffles me
I'm having trouble understanding the output from as.windrose(). For one
thing, data on a boundary between sectors seem to be left out of the
counts. I assume that explains the missing point in the output below
(angle 45). Shouldn't one side of each sector interval be open, to
include values such as my 45 in the example? Also, why does the angle
180 in my input apparently not result in
2010 Apr 22
1
Why does 'apply(.., 1, .., ..)' transpose result
I am sorry if this is documented in apply's dcumentation or completely
obvious, I could not find or work it out.
Given an matricies Q: 2x3, R:1x3 and S:1x2
apply(Q, 1, '-', R) is 3x2 and apply(Q, 2, '-', S) is 2x3
Why?
cheers
Worik
> Q
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 10 11 12
> R
[1] 1 4 7
> S
[1] 1 4
> apply(Q, 1, '-', R)
[,1]
2012 Mar 13
0
111 FIXMEs in main/src
Hi,
We sometimes see offers to contribute, asking what needs to be done. If
they know C, how about the 111 FIXMEs? But which ones would be most
useful to fix? Which are difficult and which are easy? Does R-core have
a process to list and prioritise the FIXMEs?
~/R/Rtrunk/src/main$ grep "[^/]FIXME" * | wc -l
111
~/R/Rtrunk/src/main$ grep -A 1 "[^/]FIXME" *
arithmetic.c:/*
2010 Jun 16
5
t-test problem
I have two pairs of related vectors
x1,y1
and
x2,y2
I wish to do a test for differences in means of x1 and y1, ditto x2 and y2.
I am getting odd results. I am not sure I am using 'pt' properly...
I have not included the raw vectors as they are long. I am interested if I
am using R properly...
> c(length(x1), length(y1), length(x2), length(y2))
[1] 3436 1619 2677 2378
First
2011 Nov 11
3
Why does length("") == 1?
It seems obvious to me that the empty string "" is length 0.
cheers
Worik
[[alternative HTML version deleted]]
2009 Sep 24
2
Date formats in as.Date
I have trouble with this:
as.Date("Sep-1981", format="%b-%Y")
Returns "NA"
>From documentation for strftime
'%b' Abbreviated month name in the current locale. (Also matches
full name on input.)
'%Y' Year with century.
What am I doing wrong?
cheers
Worik
[[alternative HTML version deleted]]
2012 Nov 30
3
Line numbers with errors and warnings?
Is it possible to get a line number with an error report?
I have a long script and an error:
Error in `[.xts`(x, xsubset) : subscript out of bounds
It would be very helpful, and save a lot of time, if there was some
indication in the error message which line the error was.
I can find it using binary search but that is a painful process.
cheers
Worik
[[alternative HTML version deleted]]
2011 Dec 18
1
Looking for package 'rgp'
I am interested in the package 'rgp'
But....
> install.packages("rgp")
Installing package(s) into ‘/home/worik/R/x86_64-pc-linux-gnu-library/2.12’
(as ‘lib’ is unspecified)
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘rgp’ is not available
It is in cran: http://cran.r-project.org/web/packages/rgp/index.html
How do I install it?
2012 Nov 12
1
System problem: Sys.time() returns GMT, says NZDT
When I say:
> Sys.time()
[1] "2012-11-12 21:30:14 NZDT"
>
But that is not what my clock on the wall and my system say. Cannot show
you my clock but...
worik@lemy:/tmp$ date
Tue Nov 13 10:32:20 NZDT 2012
Sys.time() is returning GMT
$version.string
[1] "R version 2.14.1 (2011-12-22)"
> Sys.timezone()
[1] "NZDT"
>
I'm a little lost!
Worik
2012 Oct 09
4
Modern Symbolic debugger for R programmes?
I think I am whistling in the wind, but is there a modern symbolic
debugger for R programmes?
I am working through some one else's code, thousands of lines, that
has the occasional bug in it, and a lot in my understanding of it.
I cannot make setBreakpoint or findLineNum work. I get "No source
refs found.". I am starting to loose my mind!
A debugger where I could set
2011 May 08
2
Pretty printing numbers
Friends
I am trying to format a number to a string so 2189.745 goes to "2,189.35"
and 309283.929 goes to "309,283.93"
I have tried to use formatC(X, big.mark=",",drop0trailing=FALSE, format="f")
but it does not get the number of decimals correct. Specifying digits does
not work as that is significant digits. I could use a switch statement
switching on
2012 Mar 25
2
Weird POSIXct behaviour
Friends
I have an xts that I wish to access.
Browse[2]> DATA.ba[[p]]["2012-03-20 00:59:57","bid"]
bid
2012-03-20 00:59:57 1.4993
So far so good.
Now putting the index into a variable:
Browse[2]> Time
[1] "2012-03-20 00:59:57 NZDT"
Browse[2]> DATA.ba[[p]][Time, "bid"]
bid
Where has it gone?
Looking closer....
2010 Jun 08
2
Logical vector question
If I create a vector thusly
> v1 <- runif(20, min=0, max=1)
> v1
[1] 0.9754443 0.6306228 0.3238158 0.3175769 0.6791534 0.6956507 0.3840803
[8] 0.1421328 0.8592398 0.4388306 0.9472040 0.4727435 0.5645302 0.7391616
[15] 0.6116199 0.2727754 0.2657867 0.5261744 0.8764804 0.2032126
And I want to create a logical vector the same length that is true if v1<.3
or v1 > .7 how do I do it
2011 Sep 13
1
Getting Rcpp SEXP data in C++
Friends
I am looking at Rcpp and I am a bit stuck on a simple matter.
(I am calling R from c++, if there is a better way...)
Given this simple example using the TTR package and the SMA function which
returns a simple moving average....
Rcpp::NumericVector rv;
for(int i = 0; i < 100; i++){
rv.push_back(rand());
}
Rcpp::Environment TTR("package:TTR");
2010 Mar 18
1
Locating an error
I have a large programme that after running half an hour or so fails with an
error
Error in x[value] <- NA : only 0's may be mixed with negative subscripts
How can I find out where that error occurs?
If I have to do a binary search using error messages it will take a long
time! Is there some way I can generate a stack trace?
cheers
Worik
[[alternative HTML version deleted]]
2008 Apr 23
2
Incrementing Dates
How can I increment the value of a Date class?
I want to add a day, month or year to a date.
cheers
Worik
[[alternative HTML version deleted]]
2009 Sep 01
2
Is this a bug?
This programme
for(T in 1:3){
for(j in 1:(5-1)){
for(k in (j+1):5){
for(l in (j+2):5){
print(paste("1 JKL:", j,k,l,sep=" "))
}
}
}
}
Prints out (among other things)
[1] "1 JKL: 4 5 6"
That is for(l in (j+2):5) sets l to 6 one more than the upper limit.
cheers
Worik
[[alternative HTML version deleted]]