I have a vector x, that I would like to sort based on the order of values in vector y. The two vectors are not of the same length.
x <- c(2, 2, 3, 4, 1, 4, 4, 3, 3)
y <- c(4, 2, 1, 3)
The expected result would be:
[1] 4 4 4 2 2 1 3 3 3
...
hi all,
i'd like to create a zip archive from within R, and need maximal cross-platform compatibility, so I would prefer not to use a system("zip") command.
Within utils there's zip.file.extract (aka unzip), which uses [a lot of] c code, derived from zlib 1.1.3 within a file called dounzip.c I couldn't find any similar capabilities for ...
This may be a naive question, but I was wondering if there's a better way than using text() to adding text to a plot. Note, I'm also using layout() as well. Specifically, I have a section of a plot where I would like to add some text with headings followed by regular text.
text() is fine it seems for simple annotations, but to get th...
I have some data for which, at one level of a factor, there is a significant correlation. At the other level, there is none. Plotting these side-by-side is simple. Adding a line to both of them with stat_smooth, also straightforward. However, I do not want the line or its fill displayed in one of the two facets. Is there a simple wa...
Hi Everyone,
I am simply looking for a good tutorial that will walk me through how to create a SOM in R. I am reading Kohonen and Kaski's paper on using the maps to identify the structure of Welfare, and want to try the technique my self.
I think many of the examples in R have a lot to be desired. I have looked on the web and didn't ...
I have a large dataset (202k points). I know that there are 8 values over 0.5. I want to subset on those rows.
How do I find/return a list the row numbers where the values are > 0.5?
probably pretty basic, sorry.
thx.
...
What are the better options to convert a non-decreasing seq of occurrence times to a 0-1 seq? Thanks.
d<-c(3,5,9,12,15);
c(rep(0,d[1]-1),1,unlist(rbind(mapply(rep,0,diff(d)-1),1)))
...
I want to output a dataframe using R2HTML, and remove scientific notation. Ideas?
...
i'm outputting a dataframe to html via xtable now (tip to Shane, little nicer than r2html). I want to add commas to numbers in a couple columns of the table. I figured before i did my own paste hack I'd check if there is a built in way to do this. Anyone.
...
OK, so I'm trying to use S4 classes to build a very complex object, with slots including a half-dozen matrices, a few lists, and probably a kitchen sink or two in there. The object is initialized by referring to and unpacking a configuration object which I've already defined. It's easy enough to define the class with setClass(), but I'm ...
R: What's the best way to simulate an arbitrary univariate random variate if only its probability/density function is available?
...
I have installed rapache and i am trying to fit a linear model inside the R script file. I have configured the RFileHandler in the http.conf. When i am trying to invoke the summary(model) it is giving me a segment fault error ( i see this in the apache log file). I am guessing that it is trying to print to the console and that is why it ...
How does one "throw" an error in R? I have a function that takes a data frame and some column names and does stuff with them. If the columns don't exist, I want the function to stop and to stop all functions depending on it.
I have looked at "recover" and "browse" and "traceback" but, well, they seemed to be close but not what I am l...
Is there a way to have an R Device (postscript would be great) write the output into a variable instead of a file?
For example I know this:
postscript(file="|cat")
plot(1:10)
dev.off()
Will send the postscript text to STDOUT. How can I get that text into a variable within R?
...
I've been using debug() more often now, but sometimes I wonder which functions have been flagged for debugging. I know that you can use isdebugged() to find out if a particular function is flagged. But is there a way for R to list all the functions that are being debugged?
...
The systems I work with have GCC 4.5 (experimental) in /usr/local/bin/gcc which has proven to be problematic for some R packages. I would like to instead use system GCC in /usr/bin/gcc.
I have tried setting CC and CXX in the Bash configuration files (.bashrc, .bash_profile etc.) as well as on the command line, but although Bash recogniz...
I have a vector of integers between 0 and 5. I want to compute a histogram of counts. For example:
> y <- c(0,0,1,3,4,4)
> table(y)
y
0 1 3 4
2 1 1 2
However, I also want the results to include the fact that there are zero 2's and zero 5's, ie. I want the returned vector to have length 6. Can I use table() for this?
...
I am using the stats package R and would like to loop through column[x] in all the rows of a dataframe, operate on the data in each cell in the column with a function and pass the result to a new column (with the calculated result in the new column aligned with the data in column[x])
Two problems. 1) I can't get it to work and 2) loop...
How do I debug Rscripts that are run from the command line? I am currently using the getopt package to pass command line options. But when there's a bug, it is hard for me to: 1) see what exactly went wrong; 2) debug interactively in R (since the script expects command line options.)
Does anyone have example code and willing to share?
...
I have two vectors of integers, and for each element of the second vector I want to find the minumum distance to any element of the first vector - for example
obj1 <- seq(0, 1000, length.out=11)
obj2 <- 30:50
min_diff <- sapply(obj2, function(x) min(abs(obj1-x)))
min_diff
returns
[1] 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46...