Displaying 20 results from an estimated 300 matches similar to: "subset syntax"
2003 Sep 02
1
Plotting dates
I'm trying to plot observations against observation dates and getting julian
dates along the x-axis:
library(date)
Week<-as.date(c("05/02/03","05/09/03","05/16/03","05/23/03","05/30/03","06/0
7/03","06/14/03"))
Leafminers<-c(0,2,5,10,4,6,5)
Diglyphus<-c(0,0,4,5,7,3,1)
LeafDig<-cbind(Week,Leafminers,Diglyphus)
2002 Jan 08
6
Subsets without NA
Is there a way of removing all rows with missing values from a data frame?
I usually use
subset(x, var1!="NA")
and repeat for each variable. It would be nice to be able to do it in one
fell swoop. Also, surprisingly, it doesn't always work. Sometimes I'm left
with an empty set even though not all rows have missing values for the
variable.
Cheers,
mikkel
Mikkel Grum,
2001 Aug 21
4
looking for a smarter way
I have two problems where I've come up with some code that will do the
analysis that I want, but it looks pretty clumsy. In the first case, I
calculate the variance on five different columns for each of 14 clusters and
get them into one matrix. I get the job done, but I would have thought that
it could be done in one or two lines, not six, and be generalized so that it
didn't matter how
2003 Jan 07
2
Extracting means for given strata from dissimilarity object
Is there a way of extracting mean distance or dissimilarity for a given
strata from a 'dist' or 'dissimilarity' object, e.g. extract mean distances
for each species in Anderson's iris data?
data(iris)
iris.dist<-dist(iris[,1:4])
then what?
Mikkel Grum, PhD
Genetic Diversity Scientist
International Plant Genetic Resources Institute (IPGRI)
Sub-Saharan Africa Group
***
2002 Jan 08
3
colour coding and different point types in a plot
I'm trying to plot four different sorghum types on a plot using a different
colour/symbol combination for each sorghum type (TYPBOTA in the script
below). What am I doing wrong?:
plot(xx$LATITUDE,xx$SFD1,
points(xx$SFD1,xx$LATITUDE,
col=1:4[codes(xx$TYPBOTA)],pch=c(4,3,1,2)[codes(xx$TYPBOTA)])
grid()
I get the following error message
Error in 1:4[codes(xx$TYPBOTA)] : NA/NaN argument
2001 Aug 09
1
Mixed mode import problem
First question:
I have an Excel file with both character and numeric variables that I want
to import to a data.frame, so I've saved the data to a tab-delimited text
file.
read.table :
* Won't identify the mode of my character variables, as some of them
contain only numbers and none of them are surrounded by quotes,
* Won't allow me to specify the mode of my variables,
* Doesn't
2003 Aug 04
1
hclust() and agnes() method="average" divergence (PR#3648)
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C35A53.75780090
Content-Type: text/plain;
charset="iso-8859-1"
Anyone have a clue why hclust() and agnes() produce different results in the
example below when both use method="average"?? I'm not able to reproduce
2003 Aug 18
0
displaying pruned clusters
Any idea why clusters five and six fall off the scale in the following?
library(cluster)
library(maptree)
data(flower)
dfl2<-daisy(flower,type=list(asymm=c(1,3),ordratio=7))
hdfl2<-hclust(dfl2)
prune.dfl2<-prune.clust(hdfl2,k=6)
plot(prune.dfl2)
Of course the following will display all six clusters, but without a scale:
draw.tree(prune.dfl2)
Best wishes,
Mikkel
Mikkel Grum
2002 May 14
1
cutree() and horizontal dendrograms
When I use the function cutree(), the numbers of the clusters are not in the
same order as the plotted dendrogram. Is there any way of sorting them so
that they match the tree?
Is it possible to plot a dendrogram horizontally, preferably with the
branches to the right? This would enable some practical composite plots,
e.g. labels that were an entire table with several columns of information,
or
2006 Jan 27
3
substituting an object not found
Is there any function in R like
is.not.found(x, y)
meaning if you can't find object x, then use object
y??
Mikkel Grum
2017 Nov 14
1
Dates to numeric in for loop
Hi
Can anyone explain why a date becomes numeric when you loop over a series
of dates?
> dt <- Sys.Date()
> dt
[1] "2017-11-14"
> class(dt)
[1] "Date"
> dts <- dt - 1:0
> class(dts)
[1] "Date"
>
> for (i in dts) {
+ print(i)
+ print(class(i))
+ print(as.Date(i, "1970-01-01"))
+ print(class(as.Date(i,
2006 Jan 02
1
"7:9, 12:14" in dataframe to c(7:9, 12:14)
I want to do something like df[df$b %in% df2[i, 2], ]
where df$b is a numeric vector and df2[i, 2] is a
factor with
levels like "7:9, 12:14". For example:
a <- c(paste("A", 1:10, sep = ""), paste("B", 1:10,
sep = ""))
b <- 1:20
df <- as.data.frame(cbind(a, b))
df$b <- as.numeric(levels(df$b))[as.integer(df$b)]
f <-
2010 Dec 28
4
batch file output
I run a batch file with the following command in Windows XP:
C:\R\R-2.12.1\bin\Rterm.exe --no-save --no-restore <C:\users\me\file.R> C:\users\me\file.out 2>&1
Is there any way to get only the output of R in file.out, without getting all the code from file.R too?
Any help greatly appreciated,
Mikkel
2006 Mar 15
3
"\r" with RSQLite
What am I doing wrong, or is the \r that I'm getting
in the example below a bug?
> a <- (1:10)
> b <- (LETTERS[1:10])
> df <- as.data.frame(cbind(a, b))
>
> df
a b
1 1 A
2 2 B
3 3 C
4 4 D
5 5 E
6 6 F
7 7 G
8 8 H
9 9 I
10 10 J
> library(RSQLite)
> drv <- dbDriver("SQLite")
> con <- dbConnect(drv, dbname = "Test")
2006 Mar 15
3
"\r" with RSQLite
What am I doing wrong, or is the \r that I'm getting
in the example below a bug?
> a <- (1:10)
> b <- (LETTERS[1:10])
> df <- as.data.frame(cbind(a, b))
>
> df
a b
1 1 A
2 2 B
3 3 C
4 4 D
5 5 E
6 6 F
7 7 G
8 8 H
9 9 I
10 10 J
> library(RSQLite)
> drv <- dbDriver("SQLite")
> con <- dbConnect(drv, dbname = "Test")
2005 Jul 07
3
xmat[1, 2:3] <- NULL
I have a situation where I'm filling out a dataframe
from a database. Sometimes the database query doesn't
get anything, so I end up trying to place NULL in the
dataframe like below.
> temp <- NULL
> xmat <- as.data.frame(matrix(NA, 2, 3))
> xmat[1, 2:3] <- temp
Error in if (m < n * p && (n * p)%%m)
stop(gettextf("replacement has %d items, need %d",
2007 Dec 30
3
Date formats
Is the following expected behaviour for a date used in
an ifelse function?
> date <- Sys.Date()
> date
[1] "2007-12-30"
> ifelse(TRUE, date-1, date)
[1] 13876
> ifelse(FALSE, date-1, date)
[1] 13877
> ifelse(TRUE, as.character(date-1), date)
[1] "2007-12-29"
> if (TRUE) {date}
[1] "2007-12-30"
It would seem more natural to me if a date produced
2007 Sep 30
1
clipping viewports
Dear useRs,
Why are the rotated blue and yellow boxes in the example below clipped outside of 6 x 6 inch window in the middle of the page?? Where does the 6 x 6 inch window come from? I would like to make use of the entire page.
> library(grid)
> pdf(file = "FarmMaps.pdf", paper = "a4")
> pushViewport(viewport(
+ width = unit(7.6, "inches"), height =
2004 Sep 01
2
RODBC query on one line
Dear R-helpers,
When I use sqlQuery in the package RODBC, I cannot
break the line, but have to write the entire SQL Query
on the same line. Is this expected behaviour? It is
definitely workable, but makes the queries a slightly
difficult to read and edit.
I'm using R 1.9.1 and RODBC 1.0-4 on Windows Server
2003 and querying a Sybase database.
Best wishes,
Mikkel
2005 Nov 02
2
readline() and Rterm in Windows
I'm running an R script in Rterm and would like the
user to be prompted for input as in:
id <- readline("Please enter ID: ")
myfunction(id)
. . . etc.
This works when I run one line at a time in RGui, but
not when I try to run the script in Rterm (I'm working
with R 2.2.0 in Windows Server 2003).
Is there any way to do this?
Mikkel