Displaying 20 results from an estimated 6000 matches similar to: "Remove columns from dataframe based on their statistics"
2012 Jun 08
4
Sort 1-column dataframe with rownames
Hi,
I have a 1-column dataframe with rownames and I want to sort it
based on the single column. The typical procedure that is recommended
in diverse posts is to use order in the index. But that "destroys" my
dataframe structure. Probabaly it is a very simple solution. Here is a
short reproducable example:
x <- c(1,3,51,2,34,44,12,33,2,8)
df <- data.frame(x)
rownames(df) <-
2012 Mar 08
1
Save/Load function()-result to file in a loop
Hi,
I am looking for a way to save the result of a function, e.g the lm()-function to a file and reload it afterwards again. I'd like to do that in order to minimize the used memory when running the function in a loop. The actual function I want to store is the evaluate() from the dismo package.
I tried it with save() and load() but I am not sure if that is the way I should do it as I
2012 May 04
1
Generate strings from multiple variables
Hi,
it is easiest to explain what I want to do by an example:
lets assume there are two factors/variables:
A <- c(1,2,3)
B <- c(1,3,3)
Now I would like to generate a list of strings that should look like
("A1_B1","A1_B2","A2_B1","A2_B2"). So actually the string
contains all possible combinations of A and B (separated by _). This should
be also
2011 Dec 06
5
Argument validation within functions
Hi,
I just started with writing functions in R and so some questions popped up.
I provide some values as argument to my function such as:
function(a,b,c){}
Now i want that the function first checks if the arguments are valid for the function. E.g argument "a" has to be a number in the range 0-1. How can that easily done?
So far I have:
a <- as.numeric(a)
if(0 <= a &&
2012 Jun 01
1
Redefine multiple columns (using grep) as factor variables
Hi,
I have a dataframe with around 100 columns. Now I want
to redefine some of the columns as factors (using as.factor).
Luckily all the names of the columns I want to redefine start with
"crast". Thus I thought I can use grep() for that purpose...
...I found an example for redefining a single column as factor
but that is not working with multiple columns I get from grep()...
what I
2011 Aug 15
2
Extracting information from lm results (multiple model runs)
Just to inform:
I posted that before in R-sig-ecology but as it might be interesting also for other useRs, I post it also to the general r-user list:
Hello Alexandre,
thank you very much. I also found another way to extract summarizing information from lm results over e.g. 1000 repeated model runs:
results2 <- t(as.data.frame(results))
summary(results2)
Although some questions popped up in
2011 Nov 24
2
dataframe indexing by number of cases per group
Hello,
assume we have following dataframe:
group <-c(rep("A",5),rep("B",6),rep("C",4))
x <- c(runif(5,1,5),runif(6,1,10),runif(4,2,15))
df <- data.frame(group,x)
Now I want to select all cases (rows) for those groups
which have more or equal 5 cases (so I want to select
all cases of group A and B).
How can I use the indexing for such questions?
df[??]...
2012 Jun 11
2
question about changing certificate
Good day!
I'm having trouble changing certificate/keys for my dovecot(version 1.2.9).
When I set up the server (unbuntu lts 10.4.4) I did it with a self-signed certificate. I can't remember exactly what I did, just that I followed the wiki and it worked fine =)
Now I have to change the certificate because a friend bought an official one (from thawte) and I'm a bit stumped.
As dovecot
2012 Apr 02
1
Unwanted page break in Rd2pdf
Hi,
I want to create a pdf of my Man-pages from my package.
Therefore I run in the terminal Rd2pdf on the package and
a pdf of all the pages is created.
After the titlepage there is the general package page, which includes
"Description" and "Details" etc. Unfortunately after the Subtitle "Details" there is a pagebreak (and 3/4 white page) which I did not set
2012 May 02
1
Two ecdf with log-scales
Hi,
i want to plot empirical cumulative density functions for two variables in
one plot. For better visualizing the differences in the two cumulative curves I'd like to log-scale the axis.
So far I found 3 possible functions to plot ecdf:
1) ecdf() from the package 'stats'. I don't know how to successfully set the log.scales? Combining two plots is not a problem:
plot(ecdf(x1))
2012 May 04
1
Absolute cumulative curve with ecdf/stepfun?
Hi,
I have two variables ranging both from 0 to 1 (n=500 each).
Now I am interested in plotting them both in one plot (using ggplot2).
So far I used ecdf() (from an example I found with google) to get
values for the cumulatice distribution function which gives a relative
curve. I also want to do the same plot but using absolute cumulative
values instead of relative. Can that be done with ecdf or
2012 Feb 03
2
Assigning objects to variable and variable to list in a for loop
Hello,
I want to use a for loop for repeadely calculating
a maxent model (package dismo, function maxent()) which
creates an object of the class maxent (S4).
I want to collect all the resulting object in a list.
I tried to simplify my for loop to explain what I want.
There are two problems/questions:
1) How can I create the new variables in the loop (using paste) and assign the objects
2) How
2012 Apr 02
1
Make package out of own function
Hello,
I already posted that on stackoverflow[1], but although it's crossposting,
I think this question can probably easier to be answered by other R-users on this list, which maintain packages etc.
I would like to make a package out of a function. The function
is working in a script, but when I install and load it as library()
I get an error. The example-function is:
#Make generic function
2012 Feb 08
2
Split dataframe into new dataframes
Hi,
I want to split a dataframe based on a grouping variable (in one column). The resulting new
dataframes should be stored in a new variable. I tried to split the dataframe using split() and
to store it using a FOR loop, but thats not working so far:
df <- data.frame(A=c("A1","A1","A2","A2"),B=seq(1:4))
Fsplit <- function(x,y){
ls <-
2011 Aug 15
2
MCMC regress, using runif()
Hello,
just to follow up a question from last week. Here what I've done so far (here an example):
library(MCMCpack)
Y=c(15,14,23,18,19,9,19,13)
X1=c(0.2,0.6,0.45,0.27,0.6,0.14,0.1,0.52)
X2a=c(17,22,21,18,19,25,8,19)
X2b=c(22,22,29,34,19,26,17,22)
X2 <- function()runif(length(X2a), X2a, X2b)
model1 <- MCMCregress(Y~X1+X2())
summary(model1)
but I am not sure if my X2-function is
2012 Feb 14
3
Wildcard for indexing?
Hi,
I'd like to know if it is possible to use wildcards * for indexing...
E.g. I have a vector of strings. Now I'd like to select all elements
which start with A_*? I'd also need to combine that with logical operators:
"Select all elements of a vector that start with A (A*) OR that start with B (B*)"
Probably that is quite easy. I looked into grep() which I think might
2012 May 11
2
text(): combine expression and line break
Hi,
I would like to plot some extra text in my plot.
This should be a two line text including a special character (sigma).
I tried so far a to use expression in combination with paste and "\n"...
but I can't get the line break...
Here what I've done so far:
plot(1,type="n", xaxt='n', yaxt='n', ann=FALSE)
text(1,1,labels=expression(paste(sigma,"\n
2011 Nov 03
2
variable transformation for lm
Hello,
I am doing a simple regression using lm(Y~X).
As my response and my predictor seemed to be skewed
and I can't meet the model assumptions. Therefore
I need to transform my variables.
I wanted to ask what is the preferred way to find out
if predictor and/or response needs to be transformed
and if yes how (log-transform?).
I found a procedure in "A modern approach to Regressoin
in
2012 Jun 14
0
Complex summary of counts of rank positions over multiple dataframes
Hi,
I've kind of a tricky question, which I don't know how to solve yet:
I get multiple dataframes loaded (readRDS) in a loop function. Each loaded dataframe contains two columns one with a var-name and one with a value. The rownumber (order) is very important as it is a value of the rank (1:x).
A example with a similar looped structure:
df1 <-
2012 Jul 25
2
reshape -> reshape 2: function cast changed?
Hi,
I used to use reshape and moved to reshape2 (R 2.15.1). Now I tried some of my older scripts and was surprised that my cast function wasn't working like before.
What I did/want to do:
1) Melt a dataframe based on a vector specifying column names as measure.vars. Thats working so far:
dfm <- melt(df, measure.vars=n, variable_name = "species", na.rm = FALSE)
2) Recast the