Displaying 20 results from an estimated 10000 matches similar to: "How to strip one term from a data.frame? + How to write long line in script?"
2006 May 01
4
efficiency in merging two data frames
I have two data sets about lots of companies' stock
and fiscal data. One is monthly data with about
144,000 lines, and the other is quaterly with about
56,000. Each data set takes different company code.
I need to merge these two together. I read both ask
cvs. And the other file with corresponding firm code.
Now I have three data sets. return$PERMNO,
account$GVKEY. id is the data frames
2008 Jul 31
1
strip names lattice graphics
R-helpers,
I'm having difficulty with customizing strip names for a lattice graphic.
Here is an example using the iris data set :
xyplot(Sepal.Length+Sepal.Width~Petal.Length,groups=Species,data=iris)
## I'd like to change the 2 strip names to "Length" and "Width" for example, this is what I've tried :
2006 Apr 26
2
program and comment
Hi. I am a newbie to R. I need to do a courses
projects with some manipulation lots of data record
and some back-and-forth linear regression. I do not
want to spend $100 for a SAS lincence, which professor
used. So I decide to start to learn R to finish it.
I am using R in Windows. I feel it is somehow works
like mathemica. I try to write the work into a little
program for future reference.
2006 Dec 14
5
Nicely formatted tables
If I use latex(summary(X)) where X is a data frame with four
variables I get something like
Rainfall Education Popden Nonwhite
Min. :10.00 Min. : 9.00 Min. :1441 Min. : 0.80
1st Qu.:32.75 1st Qu.:10.40 1st Qu.:3104 1st Qu.: 4.95
Median :38.00 Median :11.05 Median :3567 Median :10.40
Mean :37.37 Mean :10.97 Mean :3866
2012 Jul 10
3
fill 0-row data.frame with 1 line of NAs
Dear all
Is there a simpler method to achieve the following: When I obtain an
empty data.frame after subsetting, I need for it to contain one line
of NAs. Here's a dummy example:
> (.xb <- iris[ iris$Species=='zz', ])
[1] Sepal.Length Sepal.Width Petal.Length Petal.Width Species
<0 rows> (or 0-length row.names)
> dim(.xb)
[1] 0 5
> (.xa <-
2004 Aug 21
2
more on apply on data frame
Hi R People:
Several of you pointed out that using "tapply" on a data frame will work on
the iris data frame.
I'm still having a problem.
The iris data frame has 150 rows, 5 variables. The first 4 are numeric,
while the last is a factor, which has the Species names.
I can use tapply for 1 variable at a time:
>tapply(iris[,1],iris[,5],mean)
setosa versicolor virginica
2011 Aug 10
2
round() a data frame containing 'character' variables?
Dear all
It is difficult to use round(..., digits=2) on a data frame since one
has to first take care to remove non-numeric variables such as
'character' or 'factor':
> head(round(iris, 2))
Error in Math.data.frame(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, :
non-numeric variable in data frame: Species
> head(round(iris[1:4], 2))
Sepal.Length Sepal.Width Petal.Length
2010 Mar 07
1
xyplot: strip size
Hi,
I was wondering if there is a way to control
the strip size in xyplot for example using the
strip.default function. Or do I need to redraw
the strips by myself?
I would like to make
the strip slimmer and I have reduced the font
size using cex. However, I don't know how
to change the size of the strip.
Thanks for any tips.
Hadassa
[[alternative HTML version deleted]]
2007 Dec 03
1
cor(data.frame) infelicities
In using cor(data.frame), it is annoying that you have to explicitly
filter out non-numeric columns, and when you don't, the error message
is misleading:
> cor(iris)
Error in cor(iris) : missing observations in cov/cor
In addition: Warning message:
In cor(iris) : NAs introduced by coercion
It would be nicer if stats:::cor() did the equivalent *itself* of the
following for a data.frame:
2011 Mar 06
4
sorting & subsetting a data.frame
Dear all
This may be obvious, but I cannot get it working. I'm trying to subset
& sort a data frame in one go.
x <- iris
x$Species1 <- as.character(x$Species)
##subsetting alone works fine
with(x, x[Sepal.Length==6.7,])
##sorting alone works fine
with(x, x[order(Sepal.Length, rev(sort(Species1))),])
##gets subsetted, but not sorted as expected
with(x, x[(Sepal.Length==6.7) &
2010 Sep 24
3
boundary check
Dear R,
I have a covariates matrix with 10 observations, e.g.
> X <- matrix(rnorm(50), 10, 5)
> X
[,1] [,2] [,3] [,4] [,5]
[1,] 0.24857135 0.30880745 -1.44118657 1.10229027 1.0526010
[2,] 1.24316806 0.36275370 -0.40096866 -0.24387888 -1.5324384
[3,] -0.33504014 0.42996246 0.03902479 -0.84778875 -2.4754644
[4,] 0.06710229 1.01950917
2008 Oct 13
2
split data, but ensure each level of the factor is represented
Hello,
I'll use part of the iris dataset for an example of what I want to
do.
> data(iris)
> iris<-iris[1:10,1:4]
> iris
Sepal.Length Sepal.Width Petal.Length Petal.Width
1 5.1 3.5 1.4 0.2
2 4.9 3.0 1.4 0.2
3 4.7 3.2 1.3 0.2
4 4.6 3.1 1.5
2008 Feb 27
2
multiple plots per page using hist and pdf
Hello,
I am puzzled by the behavior of hist() when generating multiple plots
per page on the pdf device. In the following example two pdf files
are generated. The first results in 4 plots on one pdf page as
expected. However, the second, which swaps one of the plot() calls
for hist(), results in a 4 page pdf with one plot per page.
How might I get the histogram with 3 other scatter
2006 Jul 07
1
replace values in data frame
Hi all,
I have a three columned list that I have imported into R. The first column
is a plot (ex. Plot1), the second is a species name (ex ACERRUB) and the
third a numeric value. I want to replace some of the second column names
with other names (for example replace ACERRUB with ACERDRU). The original
and replacement values are in separate lists (not vectors), but I can't seem
to find the
2006 May 31
2
a problem 'cor' function
Hi list,
One of my co-workers found this problem with 'cor' in his code and I confirm it too (see below). He's using R 2.2.1 under Win 2K and I'm using R 2.3.0 under Win XP.
===========================================
> R.Version()
$platform
[1] "i386-pc-mingw32"
$arch
[1] "i386"
$os
[1] "mingw32"
$system
[1] "i386, mingw32"
$status
2006 Apr 30
1
general help on R and factor in R and a few simple comment from a newbie
Hi. I am starting to learn R for a course project. I
am relative OK c++ programer. I found the R is very
different. I have read the "an introduction to R". I
have to say it is not very newbie friendly. It does
not explain many things clearly. And unfortunately,
there is not too much introductory materials available
on-line. I do not want to buy a book.
For example, I found
2007 Sep 19
2
By() with method = spearman
I have a data set where I want the correlations between 2 variables
conditional on a students grade level.
This code works just fine.
by(tmp[,c('mtsc07', 'DCBASmathscoreSPRING')], tmp$Grade, cor,
use='complete', method='pearson')
However, this generates an error
by(tmp[,c('mtsc07', 'DCBASmathscoreSPRING')], tmp$Grade, cor,
use='complete',
2010 Jun 09
4
question about "mean"
Hi there:
I have a question about generating mean value of a data.frame. Take
iris data for example, if I have a data.frame looking like the following:
---------------------
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4
0.2 setosa
2 4.9 3.0 1.4
0.2
2007 Oct 09
2
lattice/xyplot: horizontal y-axis labels with scales(relation="free")
I would like to create an xyplot with varying y-axis limits and horizontal labels at the y-axis tickmarks.
The following does not seem to work, although I think it should, going by the documentation for par.
R version 2.5.1, Windows XP Prof.
Thanks for a clue.
Andreas Krause
library(lattice)
# axis labels for y-axis are horizontal
xyplot(Sepal.Length ~ Sepal.Width | Species, data=iris)
#
2013 Jan 16
4
Get a percent variable based on group
Dear all, I'd like to get a percentage variable based on a group, but without creating a new data frame.
For example:
data(iris)
iris$percent <-unlist(tapply(iris$Sepal.Length,iris$Species,function(x) x/sum(x, na.rm=TRUE)))
This does not work, I should have only three standard values, respectively for setosa, versicolor, and virginica. How can I do this?
MANY THANKS,
Karine