Displaying 20 results from an estimated 3000 matches similar to: "summarize dataframe based on multiple cols, not their combinations"
2012 Sep 13
1
remove all terms with interaction factor in formula
Hi Folks,
I'm trying to find a way to remove all terms in a formula that contain a
particular interaction.
For example, in the formula below, I'd like to remove all terms that
contain the b:c interaction.
> attributes(terms( ~ a*b*c*d))$term.labels
[1] "a" "b" "c" "d" "a:b" "a:c"
[7]
2009 Oct 29
1
Basic question ( too broad for help topics).
I have searched help topics but don't know exactly what to search for.
Need to use my_num to find any matching STREPs in my_df
my_num <-
c("101","102","103","104","105","107","108","112","113","114","115")
## "my_df" has 8,000 different STREPS in it.
## I have a
2006 Nov 09
1
POSIXlt converted to POSIXct in as.data.frame()
In trying to use as.Date(), I've come across the conversion of POSIXlt to
POSIXct when a POSIXlt variable is included in a data frame:
my_POSIX <- strptime(c("11-09-2006", "11-10-2006", "11-11-2006",
"11-12-2006", "11-13-2006"), "%m-%d-%Y")
str(my_POSIX)
my_Date <- as.Date(my_POSIX)
str(my_Date)
data <- format(my_Date)
2011 Nov 03
2
query about counting rows of a dataframe
Dear R users,
I have got the following data frame, called my_df:
gender day_birth month_birth year_birth labour
1 F 22 10 2001 1
2 M 29 10 2001 2
3 M 1 11 2001 1
4 F 3 11
2008 Jan 22
2
contingency table on data frame
I am sorry if this is a faq or tutorial somewhere, but I am unable to
solve this one.
What I am looking for is a count of how many different
categories(numbers in this case) that appears for a given factor.
Example:
> l <- c("Yes", "No", "Perhaps")
> x <- factor( sample(l, 10, replace=T), levels=l )
> m <- c(1:5)
> y <- factor( sample(m, 10,
2012 Nov 07
3
extract indep vars from formula
Hello,
I'm trying to extract the independent variables from a formula. The
closest I've been able to come, aside from rolling my own, is the following:
> a = y ~ b * x
> attr(terms(formula(a)),"variables")
The reason I'm doing this is that I'm building a grid of points that I
use to construct a 3-d model prediction surface in rgl. If there are
more than two
2012 Nov 02
2
backreferences in gregexpr
Hi Folks,
I'm trying to extract just the backreferences from a regex.
> temp = "abcd1234abcd1234"
> regmatches(temp, gregexpr("(?:abcd)(1234)", temp))
[[1]]
[1] "abcd1234" "abcd1234"
What I would like is:
[1] "1234" "1234"
Note: I know I can just match 1234 here, but the actual example is
complicated enough that I have to
2023 Jun 04
2
Adding a numeric class to a data.frame
R-Help Community
How do I add a numeric class to a data .frame.
For example, I have calculated the following probabilities
1 2 3
0.0011566127 0.0009267028 0.0081623324
How would I add them back into my data.frame for example
My_df <- data.frame(col_1 = c('A', 'B', 'C')) such that I end up with
col_1
2012 May 21
2
sweave tables as images?
Hello folks,
I've been on a journey trying to figure out how to manage documents that
are amenable to sharing and editing, but that contain dynamic content
generated by R. I've come to the following solution: I use Sweave to
generate labeled png & pdf figures, and I "Insert & Link" those figures
as "Pictures" in a Word 2010 doc. Thus, when data or code
2012 Apr 07
3
How do Sweave users collaborate with Word users?
Hello All,
I'm getting my workflow switched over to Sweave, which is very cool.
However, I collaborate with folks (as many of you must as well) who use
Word to Track Changes amongst a group while crafting a paper. In the
simplest case, there will just be two people (one Sweave user and one
Word user) editing a paper.
I'm wondering, how do Sweave users go about this? I could convert a
2011 Jun 22
2
strange date problem - May 3, 1992 is NA
> is.na(strptime("5/2/1992", format="%m/%d/%Y"))
[1] FALSE
> is.na(strptime("5/3/1992", format="%m/%d/%Y"))
[1] TRUE
Any idea what's going on with this? Running strptime against all dates
from around 1946, only 5/3/1992 was converted as "NA". Even stranger,
it still seems to have a value associated with it (even though is.na
thinks
2013 Apr 02
2
exporting tables to word
Hello all,
What is your preferred method to export tables (from ftable()) to Word?
Do you just export to a text file and then copy/paste? Or perhaps via
HTML output?
Thanks,
Allie
2012 Apr 02
2
summaryBy: transformed variable on RHS of formula?
Hi Folks,
I'm trying to cut my data inside the summaryBy function. Perhaps
formulas don't work that way? I'd like to avoid adding another column
if possible, but if I have to, I have to. Any ideas?
Thanks,
Allie
require(doBy)
df = dataframe(a <- rnorm(100), b <-rnorm(100))
summaryBy(a ~ cut(b,c(-100,-1,1,100)), data=df) # preferred
solution, but it throws an
2012 Oct 18
3
bigmemory for dataframes?
Hi Folks,
I've been bumping my head against the 4GB limit for 32-bit R. I can't
go to 64-bit R due to package compatibility issues (ROBDC - possible but
painful, xlsReadWrite - not possible, and others). I have a number of
big dataframes whose columns all sorts of data types - factor,
character, integer, etc. I run and save models that keep copies of the
modeled data inside the model
2009 Aug 12
2
Symbolic references - passing variable names into functions
Hello All,
I am trying to write a function which would operate on columns of a
dataframe specified in parameters passed to that function.
f = function(dataf, col1 = "column1", col2 = "column2") {
dataf$col1 = dataf$col2 # just as an example
}
The above, of course, does not work as intended. In some languages one
can force evaluation of a variable, and then
2011 Jun 05
3
reproduction archives
Hello Folks,
As some of my old code broke when an updated package changed its
interface, I started thinking about reproduction of analyses. It's not
good enough to save our code - we have to save the package versions
those analyses used as well as the R-core. I saw a couple references to
"reproduction archives" around, but nothing specific. Is there any good
way to package up
2012 Apr 04
3
Rgui maintains open file handles after Sweave error
Hello Folks,
When I run the document below through sweave, rgui.exe/rsession.exe
leaves a file handle open to the sweave-001.pdf graphic (as verified by
process explorer). Pdflatex.exe then crashes (with a Permission Denied
error) because the graphic file is locked.
This only seems to happen when there is an error in the sweave document.
When there are no errors, no file handles are left open.
2012 Mar 07
2
dot products
Hello,
I need to take a dot product of each row of a dataframe and a vector.
The number of columns will be dynamic. The way I've been doing it so
far is contorted. Is there a better way?
dotproduct <- function(dataf, v2) {
apply(t(t(as.matrix(a)) * v2),1,sum) #contorted!
}
df = data.frame(a=c(1,2,3),b=c(4,5,6))
vec = c(4,5)
dotproduct(df, vec)
thanks,
2010 Nov 17
3
translate vector of numbers to indicies of 0/1 matrix
Hello All,
Searched around, haven't found a decent solution.
I'd like to translate a vector of numbers to a matrix (or to a list of
vectors) such that the vector values would serve as indicies of the 1's
in an otherwise-zero-filled matrix (or list of vectors). For example:
> a = c(1,3,3,4)
# perform operation
[,1] [,2] [,3] [,4]
[1,] 1 0 0 0
[2,] 0 0 1
2017 Sep 14
1
To implement OO or not in R package, and if so, how to structure it?
>>> Did you read this?
>>> https://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf
>>>
>>> Maybe it could give you some insight in how to create package.
>>
>> That resource is ~9 years old. There are more modern treatments available. You
>> can read mine at http://r-pkgs.had.co.nz.
>>
>> Hadley
>>
Thanks both.