How can I align the two ggplots in the following function so that the x-axis is corresponding between the table and the graph ? As it is now the interval between the "ticks" is less in the table. Any ideas?
//M
Edit: Forgot to give credit to the learnr website for the table plotting method....
function ggkm:
ggkm<-function(time,event...
Hi all,
I´d like to count the number of changes of binary factor variable. This variable can change from time to time back and forth multiple times for every user id. Now I´d like to count he number of changes per user id to this variable over a given timespan.
The data is sorted by id,year,month,myfactor. I tried this in MySQL but ha...
I have some data that looks like this:
df <- data.frame(time=1:6, a=c(100, 90, 91, 92, 91, 91.5), b=c(99.9, 90.3, 90.9, 91.8, 92, 91.5), c=c(100.3, 88.5, 90.5, 91.5, 91, 91.3))
df <- data.frame(df, mean=apply(df[,2:4], 1, mean))
> df
time a b c mean
1 1 100.0 99.9 100.3 100.06667
2 2 90.0 90.3 88.5 89.60000
3 ...
I'm using the bystat function from the Hmisc package in R. How can I extract attribute values and place them into variables. For example, I want to calculate mean and SD for variable aaf and put them in a dataframe or matrix.
t <- with(d.aaf,bystats(y=aaf,plot_bid,fun=function(x) {
c(Mean = round(mean(x),digits=2),SD = round(sd(...
I have a data set with some null values in one field. When I try to run a linear regression, it treats the integers in the field as category indicators, not numbers.
E.g., for a field that contains no null values...
summary(lm(rank ~ num_ays, data=a)),
Returns:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Int...
Is it possible to update a dataset in a local, installed package?
A package that I maintain has a dataset based on periodically-updated data. I would like to update the local version of my dataset and save the changes back to the package such that next time I load the data, i.e. data(xxx), the updated version of the dataset will load.
...
Hi All,
I am busy writing a package for a customer with little knowledge about R. Given their complex data structure, I need to set up a "data base" within R containing tons of information obtained from a set of spreadsheets they get from another company. As they can't install SQL or so on their computers (ICT has some power control iss...
as title, I am working on some gregexpr in R now, I need to search for something start with a dot, so I need to use "." (without quote), but R keep saying that it is an unrecognized escape. What can I do?
Thanks!
...
op <- options(warn=0) #although doesn't work for any value of warn
assign("last.warning", NULL, envir = baseenv())
thisDoesntWork<- function() {
warning("HEY, this is definitely a warning!")
cat(paste("number of warnings:",length(warnings())))
}
>thisDoesntWork()
Warning in thisDoesntWork() : HEY, this is definitely a warning!
numb...
I wonder if there is a better way to put two data.frames into one, treating the rownames as if it was a column and then merge by this column with some other data.frame. I know I could do the following
df1$rn <- row(df1)
all <- merge(df1,df2, by.x="rn", by.y="some_column")
I mean this produces redundant data (rownames as column) whi...
Hi, I'm trying to transform a 3D array into a matrix. I want the third dimension of the array to form the first row in the matrix, and this third dimension should be read by row (i.e., row 1, then row 2 etc... of dimension 3 should make up the first row of the matrix). I've given an example below, where the array has dimensions of 4, 3, ...
I have a dummy list here:
> x <- c("a", "b", "c")
> y <- c("d", "e", "f")
> z <- list(x,y)
> z
[[1]]
[1] "a" "b" "c"
[[2]]
[1] "d" "e" "f"
If I want to assign another variable (e.g. w) to hold the last item (i.e. "c", "f") of all vectors (i.e. x, y) inside the list (i.e. z), how can I do that?
Thanks!
...
Let's presuppose that you have R running with root/admin privileges. What R calls do you consider harmful, apart from system() and file.*()?
This is a platform-specific question, I'm running Linux, so I'm interested in Linux-specific security leaks. I will understand if you block discussions about R, since this post can easily emerge in...
Dear Stackoverflow users,
I'm trying to perform GLM (Generalized linear model) repeatedly within a python script (within a loop).
1- I tried to use Stats within Scipy glm function but description is quite inexistant and I think I did not use it well --> error message "ValueError: only ttest_ind implemented". I searched within stats.py f...
I'm using geom_density to plot densities with very thin tails. I want to restrict the y-axis range (so the top of the distribution will be off screen and the tail is more clearly visible) but it's throwing away data that is off-screen when it calculate the density, rather than just not showing what is off screen.
E.g.
This plots the f...
Given a series of randomly generated data how can I figure out how random it actually is? Is R-lang a good tool for this matlab? What other questions can can these tools answer about randomly generated data? Is there another tool better for this?
...
I need to read a data frame from a file containing NULL values. Here's an example file:
charCol floatCol intCol
a 1.5 10
b NULL 3
c 3.9 NULL
d -3.4 4
I read this file into a data frame:
> df <- read.table('example.dat', header=TRUE)
But "NULL" entries are not interpreted by R as NULL:
> i...
Hi,
I have two tables. Both are read using the read.table() function.
Table 1
A B C
S1 1 1 0
S2 2 0 NA
S3 0 2 1
Table 2
Pa Pb Pc
G1 0.12 0.65 0.001
G2 0.34 0.82 0.03
G3 0.2 0.64 0.87
I need to iterate over both tables. Specifically, I need to iterate over table one column-wise an...
Hi, I'm relatively new to R, and was wondering the most efficient way to iteratively construct a dataframe (one row at a time, the number of iterations "n" and the length of each row "l" are known beforehand).
Create empty dataframe, add a row each iteration
Preallocate n x l dataframe, modify a row each iteration
Preallocate n x l mat...
I have 13 matrices of various dimensions that i'd like to use in pairwise matrix correlations with a custom function (that calculates the Rv coefficient). The function takes two arguments (matrix1, matrix2) and produces a scalar (basically a multivariate r value). I'd like to run the function on all possible pairs of matrices (so 78 corr...