break different than
a simple call to seq().
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Mon
[i] = 0}
}
When you write a loop, you need to use the loop index
to select the individual value you're working with.
- Phil Spector
Statistical Computing Facility
. . .
And I'm still not sure I've answered your question.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
will return only the first 10 observations.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Steve -
Take a look at daisy() in the cluster package.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC
Ali -
If all you care about is if there are any missing values
(not how many or where they are), I think it would be a bit
faster to use
if(any(is.na(x))){...}
- Phil Spector
Statistical Computing Facility
')
So to reproduce your x, y, fit, and res:
x = result$x[[1]]
y = result$orig[[1]]
fit = result$fit[[1]]
res = result$res[[1]]
Of course, you can access any of the other results by changing the subscript.
- Phil Spector
assuming you're using month/date/year.)
I can pretty much guarantee it will run in less than 18 hours :-)
- Phil Spector
Statistical Computing Facility
Department of Statistics
David -
I *think*
apply(x,1,function(x)rle(x[which(x==1)[1]:length(x)])$lengths[1])
gives you what you want, but without a reproducible example it's
hard to say. It will fail if there are no 1s in a given row.
- Phil Spector
Herzberg wrote:
Thank you Phil - I'll give this a try. I do have some empty rows, so I'll have
to deal with that eventually.
Dave
Sent via DROID X
-Original message-
From: Phil Spector spec...@stat.berkeley.edu
To: David Herzberg dav...@wpspublish.com
Cc: r-help@r
loop reads up until the word Source appears in the
line, and the second loop builds a text representation of what
you want so that you can read it using textConnection.
Hope this helps.
- Phil Spector
Statistical
certainly free to make it one:
as.integer(difftime(strptime(24NOV2004, format=%d%b%Y),
+ strptime(13MAY2004,format=%d%b%Y), units=days))
[1] 195
- Phil Spector
Statistical Computing Facility
a
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Mon, 1
You didn't say what form you wanted the output in, but
here's one way:
sapply(split(dat,dat$individual),function(s)lm(height~time,data=s)$coef)
1 2
(Intercept) 8.47 19.87
time2.485714 -2.057143
- Phil Spector
Steven -
Does typing
Sys.setlocale('LC_ALL','C')
before the offending command suppress the message?
- Phil Spector
Statistical Computing Facility
Department
(dat))
user system elapsed
0.024 0.000 0.026
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC
Well, there's the obvious:
N = matrix(0,n-1,n-1)
for(i in 2:(n-1))
N[1,i] = 1/(pi * (i-1))
for(i in 2:(n-2))
for(j in i:(n-1))
N[i,j] = N[i-1,j-1]
for(i in 2:(n-1))
for(j in 1:i)
N[i,j] = -N[j,i]
- Phil Spector
Dimitri -
While merge is most likely the fastest way to solve
your problem, I just want to point out that you can use
a named vector as a lookup table. For your example:
categories = my.lookup$category
names(categories) = my.lookup$names
creates the lookup table, and
my.df$category =
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Mon, 8 Nov 2010
Mohan -
Suppose your data frame is named df. Try this:
data.frame(df[,1],1,df[,2:5])
- Phil Spector
Statistical Computing Facility
Department of Statistics
-standard location.
You didn't mention what Linux distribution you're using, or
whether you built R and the kernlab library from source or
not, so it's hard to give specific guidance to solve your
problem.
- Phil Spector
NA NA NA
2 9 10 NA NA NA 15
3 10 20 NA 30 NA NA
4 12 19 NA NA 25 NA
Hope this helps.
- Phil Spector
Statistical Computing Facility
Department of Statistics
, you can use as.numeric:
as.numeric(myvar)
[1] 0 0 0 1
Hope this helps.
- Phil Spector
Statistical Computing Facility
Department of Statistics
,data=somedat,skip=chk,layout=c(7,7),as.table=TRUE)
I'm not sure what you mean by the legends, but maybe this will give you
a start.
- Phil Spector
Statistical Computing Facility
Aleksandr -
What happens when you use
library(maptools)
spb = readShapePoly('/home/sasha/Documents/maps/spb.shp')
- Phil Spector
Statistical Computing Facility
Department
Cameron -
Are you sure Mthticker is a table? It looks like a
list containing named vectors. Are you trying to reformat
the list (Mthticker), or to reformat one element in the
list (MthTicker[[i]]).
- Phil Spector
Does this version of y do what you want?
y=function(j)sum(sapply(1:3,function(i)x(i,j)))
- Phil Spector
Statistical Computing Facility
Department of Statistics
Tianchan -
Your X is not a matrix -- it's a dataframe. Probably the
simplest solution is to use
lm(y~as.matrix(X))
but you should also learn the difference between a data frame
and a matrix.
- Phil Spector
Hope this helps!
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Eduardo -
I'd guess that
Ybar = function(u)mean(sapply(Y,function(fun)fun(u)))
will do what you want, but without a reproducible example,
it's hard to tell.
- Phil Spector
Statistical Computing Facility
Vectorize() before
trying to integrate:
integrate(Vectorize(Ybar),0,1)
0.4587882 with absolute error 5.6e-05
- Phil Spector
Statistical Computing Facility
Department
)))
user system elapsed
1.324 0.000 1.323
system.time(two - Ybar1(seq(0,1,length=1)))
user system elapsed
0.004 0.000 0.002
- Phil Spector
Statistical Computing Facility
,]0010
[3,]0010
[4,]0001
- Phil Spector
Statistical Computing Facility
Department of Statistics
(lab,foreground='red',text='wrong')
green = function(...)tkconfigure(lab,foreground='green',text='correct')
tkpack(tkbutton(base,text='Red',command=red))
tkpack(tkbutton(base,text='Green',command=green))
- Phil Spector
and then truncate it at the end.
I'd strongly recommend that you avoid building your matrix
incrementally inside a loop!
- Phil Spector
Statistical Computing Facility
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Mon, 22
],FALSE)
dat[!(abv blw),]
[,1] [,2]
[1,]37
[2,]65
[3,]55
[4,]84
[5,]74
[6,]06
- Phil Spector
Statistical Computing Facility
.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Wed, 24
I believe R is complaining that it can't find the
jags library. You can find out about it here:
http://www-fis.iarc.fr/~martyn/software/jags/
There appear to be rpms available.
- Phil Spector
Statistical
Alon -
It says it couldn't find it in /usr/local/lib -- is it
in some non-standard location? If so, you could modify the
~/.R/Makevars file to contain
PKG_LIBS=/location/of/jagslibrary
before trying to build the package.
- Phil
On Wed, 24 Nov
$V2)
t2$V3
[1] badbadb badbad b ba
Hope this helps.
- Phil Spector
Statistical Computing Facility
Department of Statistics
).
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Mon, 29 Nov 2010, clangkamp
Does
A = lapply(A,function(x)if is.null(x) 0 else x)
or
for(i in 1:length(A))if(is.null(A[[i]]))A[i] = 0
do what you want?
- Phil Spector
Statistical Computing Facility
displaying the
object, the names or dimnames should not affect anything
you do with the object, and they do allow you to index
elements by name instead of number.
- Phil Spector
Statistical Computing Facility
[-1]0]))
t(apply(myDF,1,doit))
id sum_positive sum_negative
[1,] 100 1.8 -2.2
[2,] 101 1.8 -1.7
- Phil Spector
Statistical Computing Facility
Juliet -
Since you're operating on each column, apply() would
be the appropriate function;
mymat = apply(mymat,2,function(x){x[x0] = min(x[x0]);x})
- Phil Spector
Statistical Computing Facility
results in a list.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
$shape=factor(two$shape,labels=c('Circle','Square','Triangle'))
two$color=factor(two$color,labels=c('Blue','Red','Green'))
names(two)[4] = 'value'
- Phil Spector
Statistical Computing Facility
library(car)
recode(d,c(1,2)='1')
[1] 0 1 1
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
='membership',
+ v.names='Freq',timevar='label',direction='wide')
membership Freq.0 Freq.1
1 1 2 1
2 2 1 2
3 3 0 3
- Phil Spector
Statistical Computing
,]
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Wed, 21
.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Mon
Harold -
If there aren't any true quoted fields in the file, you
could pass the quote= option to read.delim().
- Phil Spector
Statistical Computing Facility
Department
?all
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec
,...)})
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec
)
For POSIXct objects:
aggregate(thedata$value,list(hour=format(thedata$date,'%H')),mean)
If I made the wrong assumptions, please provide a reproducible example.
- Phil Spector
Statistical Computing Facility
.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec
This seems to work, although it eliminates the
sparseness of the storage:
dimnames(a) = list(NULL,letters[1:5])
as.data.frame(as.matrix(a))
a b c d e
1 0 0 0 1 0
2 2 1 0 0 0
3 0 0 3 0 1
- Phil Spector
Marianne -
The function you're looking for is mapply:
mapply(function(one,two)one[two],x,y)
[[1]]
[1] one
[[2]]
[1] four five
- Phil Spector
Statistical Computing Facility
Here's one possibility:
sort.v-c(Lake=1,Shoreline=2,Floodplain=3)
test.df[order(sort.v[as.character(test.df$Zone)]),]
Zone Cover
2 Lake60
3 Shoreline70
1 Floodplain50
- Phil Spector
Toby -
Since dat$doy is just a number, the default S3 method
for format is used, where the second argument is the trim
parameter. I suspect you are confusing format (which is for
output) with strptime (which is for input).
For example,
strptime(dat$doy,'%j')
will assume that the dates
Hyunchul -
You don't have to rely on the operating system to
provide information about the file system. Look at
?list.files
For example,
list.files('/path/to/directory',recursive=TRUE)
- Phil Spector
url
1 http://$IMAGE_ID$ www.url.com/image.jpg http://www.url.com/image.jpg
2$IMAGE_ID$ http://www.blah.com/image.gif http://www.blah.com/image.gif
- Phil Spector
Statistical Computing
Does
outer(p_11,p_12,Vectorize(guete))
do what you want?
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC
, check.names=FALSE)
expFC.TRUE - expFC[expFC[dim(expFC)[2]]==TRUE,]
write.table(expFC.TRUE, file=test_TRUE.txt, row.names=FALSE, sep=\t,
quote=FALSE )
- Phil Spector
Statistical Computing Facility
Gregory -
Suppose your list is called mymats. Then
Reduce(+,mymats)
does what you want.
- Phil
On Sun, 12 Sep 2010, Gregory Ryslik wrote:
Hi,
I have a list of several hundred 2 dimensional matrices, where each matrix is n
x m. What I need to do is
' is not subsettable
Thanks again!
Kind regards,
Greg
On Sep 12, 2010, at 3:49 PM, Phil Spector wrote:
Gregory -
Suppose your list is called mymats. Then
Reduce(+,mymats)
does what you want.
- Phil
On Sun, 12 Sep 2010, Gregory Ryslik wrote:
Hi,
I have a list
Sunny -
I don't think mapply is needed:
lapply(1:length(mylist),function(x)rep(x,length(mylist[[x]])))
[[1]]
[1] 1 1 1
[[2]]
[1] 2
[[3]]
[1] 3 3
- Phil Spector
Statistical Computing Facility
!10 %in% x
(or !(10 %in% x) if you don't believe in R's precedence rules.
- Phil Spector
Statistical Computing Facility
Department of Statistics
Maybe prop.table ?
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
I think
t(mapply(rnorm,1000,vector_of_means,vector_of_sds))
will do what you want.
- Phil Spector
Statistical Computing Facility
Department of Statistics
Chien-Pang -
Here's a *reproducible* example that should answer your question:
k = list()
n = 10
max = 10:19
for(i in 1:n) (k[i]=list(c(0:max[i])))
k[[1]] + 1
[1] 1 2 3 4 5 6 7 8 9 10 11
- Phil Spector
Kevin -
Here's one way:
z = boxplot(mydata$score,outline=FALSE,ylim=range(mydata$score))
text(1,z$out,SubNo[which(score == z$out)])
- Phil Spector
Statistical Computing Facility
533 2.328799
. . .
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
the estimates into
the pth row (mymat[p,]) or pth column (mypat[,p]) of the matrix.
- Phil Spector
Statistical Computing Facility
Department of Statistics
.)
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec
Bastien -
In what way did
subset(yourdataframe,ESS %in% softwood)
not work?
- Phil Spector
Statistical Computing Facility
Department of Statistics
Soyeon -
I think scan() (combined with matrix and data.frame) is the
easiest way.
Suppose your text file is called data.txt. Then
data.frame(matrix(scan('data.txt'),byrow=TRUE,ncol=14))
should give you what you want.
- Phil Spector
Harold -
Two ways that come to mind:
1) do.call(rbind,lapply(split(tmp,tmp$index),function(x)x[1:5,]))
2) subset(tmp,unlist(tapply(foo,index,seq))=5)
- Phil Spector
Statistical Computing Facility
Anan -
If you actually want the indices, you can use
seq_along(sampWB)[-censidx]
If you want the values themselves, then use
sampWB[-censidx]
- Phil Spector
Statistical Computing Facility
pwr.chisq.test
[9] pwr.f2.testpwr.norm.test pwr.p.test pwr.r.test
[13] pwr.t2n.test pwr.t.test
Those are the functions that are made available by loading the
pwr package. Do you see something different after you load pwr?
- Phil Spector
Does using
df = df[order(df$type,df$set,df$x),]
before calling xyplot fix the problem?
- Phil Spector
Statistical Computing Facility
Department of Statistics
Ralf -
Try
bins = as.numeric(names(t1))
freqs = as.vector(t1)
- Phil Spector
Statistical Computing Facility
Department of Statistics
)
. . .
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec
$login_end tm)))
time count
1 2010-01-01 10:00:00 1
2 2010-01-01 10:30:00 1
3 2010-01-01 11:00:00 2
4 2010-01-01 11:30:00 1
5 2010-01-01 12:00:00 1
6 2010-01-01 12:30:00 0
Hope this helps.
- Phil Spector
all the .csv files in the current directory, and write out
a file with the extension changed to .new in the directory /some/location .
- Phil Spector
Statistical Computing Facility
.0.N C.2.S C.0.G H.3.G
Hope this helps.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Matthew -
It's a bit simpler than you think:
as.POSIXlt(pk)$hour
should return what you want. (If not, please provide a
reproducible example.)
- Phil Spector
Statistical Computing Facility
,all)
both$Pct = both$Freq / both$Total * 100
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
)
[1] 19 15 21 22
and
c(2,2,2,2)
[1] 2 2 2 2
or
rep(2,4)
[1] 2 2 2 2
I would ignore any other advice you got from the source that
advised you to use expressions like 19:15:21:22 in R.
- Phil Spector
Statistical
$st,6),labels=FALSE) + 1)
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
9 14
[5,]5 10 15
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
If you don't mind the prompt of 1:, I think
scan will do what you want:
a = scan(n=1,what='',quiet=TRUE);b = paste(t,a,sep='');
1: ada
b
[1] tada
- Phil Spector
Statistical Computing Facility
Gregory -
I'm confused -- if the first element is the matrix you
want, why would you use 2 as an index?
Here's a way to get a list with the first elements of each
member of a list:
lapply(thelist,'[[',1)
- Phil Spector
(x$y)])
merge(dat,data.frame(id=names(two),type=two))
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC
?invisible
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
John -
Is this what you're looking for?
r = sample(c(0,1),10,replace=TRUE)
r
[1] 0 1 0 1 1 0 0 1 0 1
v = 1:10
ifelse(r == 1,v-1,v)
[1] 1 1 3 3 4 6 7 7 9 9
- Phil Spector
Statistical Computing Facility
)mapply(function(n,w)doit1(x,n,w),qq$nodes,qq$weights))
Both seem to agree with your rr1.
- Phil Spector
Statistical Computing Facility
Department of Statistics
Jared -
The value 2010-08-17 is a character value, and your dates
are stored as POSIXlt values. So you'd need to use
Date == as.POSIXlt(2010-08-17)
in your subset statement.
- Phil Spector
Statistical
1 - 100 of 399 matches
Mail list logo