e.g.
dat[ order(dat$a), ]
On Sun, May 31, 2009 at 2:34 PM, Угодай n/a wrote:
> I have a data frame, for exampe
>
>> dat <- data.frame(a=rnorm(5),b=rnorm(5),c=rnorm(5))
> a b c
> 1 -0.1731141 0.002453991 0.1180976
> 2 1.2142024 -0.413897606 0.7617472
> 3 -0.942848
Thanks a lot! :)
Grześ wrote:
>
> I have a vector like this:
> h <- c(4, 6, NA, 12)
> and I create the secound logical vector like this:
> g <- c(TRUE, TRUE, FALSE, TRUE)
>
> And my problem is that I would like to get a new "m" vector as a rasult
> "h" and "g"( as dot-matrix printer) but wit
Thanks a lot! :)
Linlin Yan wrote:
>
> On Sat, May 30, 2009 at 2:48 AM, Grześ wrote:
>>
>> I have a vector like this:
>> h <- c(4, 6, NA, 12)
>> and I create the secound logical vector like this:
>> g <- c(TRUE, TRUE, FALSE, TRUE)
> Why don't you create vector g like this:
> g <- ! is.na(h)
>
Thanks Jorge Ivan Velez!
--
View this message in context:
http://www.nabble.com/logical-vector-as-a--matrix-tp23785253p23796796.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mai
edwin Sendjaja wrote:
> Hi VQ,
>
> Thank you. It works like charm. But I think Peter's code is faster. What is
> the difference?
>
i think peter's code is more r-elegant, though less generic. here's a
quick test, with not so surprising results. gsubfn is implemented in r,
not c, and it is p
well, you do not have to compute the pairwise difference each time; for
instance, you could use something like this (untested):
out1 <- outer(a, c, "-")
out2 <- outer(b, c, "-")
u <- v <- 1:5
mat <- matrix(0, length(u), length(u))
for (i in seq_len(u)) {
for (j in seq_len(v)) {
res1
This is a new one on me.
Do you mean the Kronecker delta, or the Kronecker product?
The Kronecker product is more likely. In which case try ?kronecker. It is
available as an operator, %x%, as well.
Bill Venables.
From: r-help-boun...@r-project.org [r-h
Dear Jim,
with the help of Ted, we diagnosed that the cause is in the extreme
variability in line length during reading in. As the table column number
is apparently determined fro mthe first five lines, what exceeds this
length gets automatically on the next line.
I am now trying to find a way
Dear R-helpers,
I was testing the truncgof CRAN package, found something that looked
like a bug, and did my job: contacted the maintainer. But he did not
reply, so I am resending my query here.
I installed package truncgof and run the example for function ad.test. I
got the following output:
set
Is the code below showing a bug in Crosstable()? My expectation was that
the values produced by xtabs were rounded instead of truncated:
library(gmodels)
abc <- c("a", "a", "b", "b", "c", "c")
def <- c("d", "e", "f", "f", "d", "e")
wgt <- c(0.8, 0.6, 0.4, 0.5, 1.4, 1.3)
xtabs(wgt ~ abc + def)
Cr
Dear all,
I'm trying to access and modify grobs in a ggplot2 plot. The basic
idea for raw Grid objects I understand from Paul Murrell's R graphics
book, or this page of examples,
http://www.stat.auckland.ac.nz/~paul/grid/copygrob/copygrobs.R
However I can't figure out how to apply this to
Dear R user,
I am trying to convert the contents of a date.frame to a matrix. Since there
are negative values in the date.frame, when I use data.matrix(x,
rownames.force = NA), the resulting matrix is not the same as the original
one. Basically I think R treats the numbers in the date.frame as cha
On May 31, 2009, at 7:51 AM, Jakson Alves de Aquino wrote:
Is the code below showing a bug in Crosstable()? My expectation was
that
the values produced by xtabs were rounded instead of truncated:
library(gmodels)
abc <- c("a", "a", "b", "b", "c", "c")
def <- c("d", "e", "f", "f", "d", "e")
wg
Dear Marc Schwartz,
You are correct: there is no bug in CrossTable(). To get what I want I
should have done:
CrossTable(round(xtabs(wgt ~ abc + def)), prop.r = F, prop.c = F,
prop.t = F, prop.chisq = F)
Thank you for the explanation!
Jakson
Marc Schwartz wrote:
> On May 31, 2009, at 7:51 AM
Unable to reproduce:
> ?data.matrix
> x <- read.table(textConnection(" ALL ALL.1 ALL.2 ALL.3 ALL.4 ALL.5
ALL.6 ALL.7 ALL.8 ALL.9 ALL.10 ALL.11
+ 2 -214 -139 -76 -135 -106 -138 -72 -413 5 -88
-165-67
+ 3 -153 -73 -49 -114 -125 -85 -144 -260 -127 -105
-155
You can do something like this: count the number of fields in each line of
the file and use the max to determine the number of columns for read.table:
file <- '/tempxx.txt'
maxFields <- max(count.fields(file)) # max
# now setup read.table for max number
input <- read.table(file, colClasses=rep(NA
Ah!!! It was count.fields() which we had overlooked! We discoveered
a work-round which involved using
Data0 <- readLines(file)
to create a vector of strings, one for each line of the input file,
and then using
NF <- unlist(lapply(R0,function(x)
length(unlist(gregexpr(";",x,fixed=TRU
I am trying to rename the column names of a data frame called "data". It has
177 columns. I have used :
colnames(data) <- a
where a is a vector with 177 character names.
I don't get any error message, but the column names don't change because
when I then type :
colnames(data)
I get th
On May 31, 2009, at 10:49 AM, Hongyuan Cao wrote:
x = read.table("hongyuan_5_30_forsafe.txt", sep = "\t")
> x = read.table("/Users/davidwinsemius/Downloads/
hongyuan_5_30_forsafe.txt", sep = "\t")
> str(x)
'data.frame': 7131 obs. of 74 variables:
$ V1 : Factor w/ 7131 levels "","A28102_
Cannot reproduce with a toy example:
> data <- data.frame(a=1:3, b=4:6, c=6:8)
> colnames(data) <- c("d","e","f")
> colnames(data)
[1] "d" "e" "f"
Perhaps you need to produce more detail. Surely offering the results
of dput(a) would not tax the limits of the R-mail server.
--
David
On May
On May 31, 2009, at 12:03 PM, David Winsemius wrote:
On May 31, 2009, at 10:49 AM, Hongyuan Cao wrote:
x = read.table("hongyuan_5_30_forsafe.txt", sep = "\t")
> x = read.table("/Users/davidwinsemius/Downloads/
hongyuan_5_30_forsafe.txt", sep = "\t")
> str(x)
'data.frame': 7131 obs. of
Thanks, Juliet.
It works for filtering columns.
I am also wondering if there is a way to filter rows.
Thanks again.
-james
> One can use colClasses to set which columns get read in. For the
> columns you don't
> want you can set those to NULL. For example,
>
> cc <- c("NULL",rep("numeric",9))
>
>
I think you can use readLines(n=1) in loop to skip unwanted rows.
On Mon, Jun 1, 2009 at 12:56 AM, wrote:
> Thanks, Juliet.
> It works for filtering columns.
> I am also wondering if there is a way to filter rows.
> Thanks again.
> -james
>
>> One can use colClasses to set which columns get read
Hi,
I'm having trouble using dates (created using library(chron)) as
groupings for a boxplot. I have 10 repeat measurements of a variable
within an individual day. The measurements were done over 10 days. I
would like to plot the measurements as a box and wisker plot (using
boxplot or someth
library(gsubfn)
library(gtools)
library(rbenchmark)
n <- 1
df <- data.frame(
a = rnorm(n),
b = rnorm(n),
c = rnorm(n),
ip = replicate(n, paste(sample(255, 4), collapse='.'), simplify=TRUE)
)
res <- benchmark(columns=c('test', 'elapsed'), replications=10, order=NULL,
peda = {
con
The sqldf package can read a subset of rows and columns into R without
reading the entire file into R. There are a few caveats:
- It does not support ftp so you will need to download the file to your
computer first as shown in the example below
- since value is an SQL keyword it turns value int
Try this:
boxplot(as.matrix(data) ~ as.Date(date), cex.axis = 0.5, las = 2)
or if all the dates are in the same year and month as they are here
then you might want to just display the day of the month:
boxplot(as.matrix(data) ~ month.day.year(date)$day)
On Sun, May 31, 2009 at 1:45 PM, Ken
Since there are many rows, using read.table we spent too much on reading
in rows that we do not want. We are wondering if there is a way to read
only rows that we are interested in. Thanks,
-james
> I think you can use readLines(n=1) in loop to skip unwanted rows.
>
> On Mon, Jun 1, 2009 at 12:56
Gabor Grothendieck wrote:
> Hi, I was looking for your sendcodetoR.ahk autohotkey script
> but couldn't find it. Would you be able to point me to it.
> Thanks.
>
Here's what I have right now, it also maps right alt to send code to R.
You should change the ahk_class to your editor of choice (her
Dear David
Problem solved ! Remarkably, I saw your previous post about stringsasFactors
<- false and that was the root of the problem. I was trying to rename the
columns according to contents of one of the rows of the data frame, which
were being interpreted as factors (which I hadn't realised) an
Thanks very much. Regards.
On Sun, May 31, 2009 at 2:20 PM, Jose Quesada wrote:
> Gabor Grothendieck wrote:
>> Hi, I was looking for your sendcodetoR.ahk autohotkey script
>> but couldn't find it. Would you be able to point me to it.
>> Thanks.
>>
> Here's what I have right now, it also maps ri
Hi:
I have an application that uses MS Access as front end interacting with
Excel,Word,Sigmaplot and R in the background. I use the programs to do
different tasks but I mainly use R to create graphics on my Access forms
without having to manually open R.
To make this short, I was wondering if R
Hi:
I have an application that uses MS Access as front end interacting with
Excel,Word,Sigmaplot and R in the background. I use the programs to do
different tasks but I mainly use R to create graphics on my Access forms
without having to manually open R.
To make this short, I was wondering if R
Le dimanche 31 mai 2009 à 12:08 -0700, Felipe Carrillo a écrit :
> Hi:
> I have an application that uses MS Access as front end interacting
> with Excel,Word,Sigmaplot and R in the background. I use the programs
> to do different tasks but I mainly use R to create graphics on my
> Access forms with
Big thanks to Ted and Jim for all the help.
Martin
(Ted Harding) wrote:
Ah!!! It was count.fields() which we had overlooked! We discoveered
a work-round which involved using
Data0 <- readLines(file)
to create a vector of strings, one for each line of the input file,
and then using
NF <-
wow! :)
vQ
Henrik Bengtsson wrote:
> library(gsubfn)
> library(gtools)
> library(rbenchmark)
>
> n <- 1
> df <- data.frame(
> a = rnorm(n),
> b = rnorm(n),
> c = rnorm(n),
> ip = replicate(n, paste(sample(255, 4), collapse='.'), simplify=TRUE)
> )
>
> res <- benchmark(columns=c('test'
Hi All,
I am running quantile regression in a "for loop" starting with 1
variable and adding a variable at a time reaching a maximum of 20
variables.
I get the following warning messages after my "for" loop runs. Should I
be concerned about these messages? I am building predictive models and
a
Hi,
i have to reshape a dataset. my data have the following format:
ID; x1; x2; x3; x4; v1; ... v20
1; 0.1; 0.3; 0.4; 0.2; 2; ... 3
2; 0.3; 0.7; 0.1; 0.2; 1; ... 4
...
999; 0.9; 0.6; 0.3; 0.1; 4; ... 2
1000; 0.2; 0.6; 0.7; 0.8; 1; ... 5
ID is the number of persons (here 1000 persons)
x
Hello!
I have a function:
zywnoscCalosc<- function( jedzenie, n1, n2, n3, n4, d1, d2, d3, d4 ) {
ndf <- data.frame(nn1=n1,nn2=n2,nn3=n3,nn4=n4)
ddf <- data.frame(dd1=d1,dd2=d2,dd3=d3,dd4=d4)
for (i in 1:length(n1)){
wekt_n = ndf[i,]
wekt_n_ok = wekt_n[!is.na(wekt_n)]
dl_n = length(wekt_n_ok
Message is very clear:
> 1 * 'a'
Error in 1 * "a" : non-numeric argument to binary operator
"wekt_n_ok " must be non-numeric. You need to provide a reproducible
script. You also need to learn about debugging. 'str(wekt_n_ok )' when the
error occurred may have helped to pinpoint the problem.
On
> x <- data.frame(id=1:100, x1=sample(100), x2=sample(100), s1=1, s2=2,
s3=3, s4=4)
> require(reshape)
> z <- melt(x, id=1:3) # first three columns are ids
> head(z,10) # should be what you want
id x1 x2 variable value
1 1 97 43 s1 1
2 2 89 5 s1 1
3 3 59 97 s1
a shorter example:
> n <- 4
> x <- data.frame(id=1:n, x1=sample(n), x2=sample(n), s1=1, s2=2, s3=3,
s4=4)
> require(reshape)
> z <- melt(x, id=1:3) # first three columns are ids
> x
id x1 x2 s1 s2 s3 s4
1 1 3 1 1 2 3 4
2 2 4 2 1 2 3 4
3 3 1 4 1 2 3 4
4 4 2 3 1 2 3 4
Not really, just the old saying that any piece of code can be made
twice as fast (which often holds true recursively). /Henrik
On Sun, May 31, 2009 at 1:58 PM, Wacek Kusnierczyk
wrote:
> wow! :)
>
> vQ
>
> Henrik Bengtsson wrote:
>> library(gsubfn)
>> library(gtools)
>> library(rbenchmark)
>>
>>
There are several things you can tell read.table to make it faster.
First, as mentioned, setting colClasses helps. I think telling read.table how
many rows and columns there are also helps.
When this was not sufficient, I've had to do the data processing
using Python, Perl, or awk.
If that had
On May 31, 2009, at 12:22 AM, Duncan Murdoch wrote:
David Winsemius wrote:
You are wiping out all of the default options with that approach.
Actually, I think it hid the options() function.
Since I was doing this at the RGui and became concerned that it
appeared I no longer had any opti
On Sun, May 31, 2009 at 6:10 PM, jim holtman wrote:
> Message is very clear:
>
> > 1 * 'a'
> Error in 1 * "a" : non-numeric argument to binary operator
Though the user should have been able to figure this out, perhaps the error
message could be improved? After all, it is not the fact that the o
Thanks jholtman!
But I'm not sure what and where I should change my code... :(
wekt_n = ndf[i,]
wekt_n_ok = wekt_n[!is.na(wekt_n)]
If before this line I should change "wekt_n_ok" as numeric? but if I wrote
as.numeric(wekt_n_ok) it's also not correct
and I also don't understand why "wekt_n_ok
If you enter the code in this post first:
https://stat.ethz.ch/pipermail/r-help/2009-May/198791.html
then this post shows an example of how to do it with lattice:
https://stat.ethz.ch/pipermail/r-help/2009-May/199146.html
but I think there is a bug in grid since similar code does
not seem to work
What you need to do is to see that is in 'wekt_n_ok' at that point in your
program. You should be able to see it with str(wekt_n_ok) when the error
occurs. You can also add a print statement in the loop to print out the
value before it is used with the binary operator.
It would help if you provi
Hi R-users,
I try to use sn package but it give me the following message:
> install.packages(repos=NULL,pkgs="c:\\Tinn-R\\sn_0.4-12.zip")
Warning: package 'sn' is in use and will not be installed
updating HTML package descriptions
I did tried a few time to save the .zip file but it give me the s
use _search()_ to see if the package is on the search path. If yes,
use _detach("package:sn",unload=TRUE)_ to detach it and then try to
install it again.
Ronggui
2009/6/1 Roslina Zakaria :
> Hi R-users,
>
> I try to use sn package but it give me the following message:
>
>> install.packages(repos=
options(error=utils::recover)
Does indeed work, at least with the new install of R-devel (to be 2.10.0)
that I am running right now. I was sure I checked this with 2.9.0 last
night, but I am probably mistaken.
One point, the ?options help page is misleading in that the example is "
Note that thes
David Winsemius wrote:
On May 31, 2009, at 12:22 AM, Duncan Murdoch wrote:
David Winsemius wrote:
You are wiping out all of the default options with that approach.
Actually, I think it hid the options() function.
Since I was doing this at the RGui and became concerned
Mark Kimpel wrote:
options(error=utils::recover)
Does indeed work, at least with the new install of R-devel (to be 2.10.0)
that I am running right now. I was sure I checked this with 2.9.0 last
night, but I am probably mistaken.
One point, the ?options help page is misleading in that the exampl
Hi,
I seem to be facing a strange problem when I use Sweave for creating a
LaTeX document of the R lme() output --- The EPS and PDF figure files
get created, but are empty. I have attached a reproducible example
below (taken from the R lme() help example).
Carlos J. Gil Bellosta wrote:
Dear R-helpers,
I was testing the truncgof CRAN package, found something that looked
like a bug, and did my job: contacted the maintainer. But he did not
reply, so I am resending my query here.
I installed package truncgof and run the example for function ad.test.
Hello,
I have to build a function that takes a time serie and calculate the momentum.
For each date of the serie, I have to build a loop to calculate it using the
last few data.
My problem is that it takes one minute to compute and I need to run this
function very often.
I would like to vecto
I have three plots and I want the *plot area* to be of the same width on
each plot. Since the three plots have different legends, the text width
of the legend affects the width of the plot area (longer legend text =
narrower plot area). Exporting the three figures to postscript device
of same siz
58 matches
Mail list logo