x27;
both = merge(correct,all)
both$Pct = both$Freq / both$Total * 100
- Phil Spector
Statistical Computing Facility
Department of Statistics
21,22)
[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
Statis
oef$a[i] * o, obs,
cut(obs,c(coef$st,6),labels=FALSE) + 1)
- Phil Spector
Statistical Computing Facility
Department of Statistics
49 14
[5,]5 10 15
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Ber
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
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)
er(x$mode)[which.max(x$y)])
merge(dat,data.frame(id=names(two),type=two))
- Phil Spector
Statistical Computing Facility
Department of Statistics
?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 Fac
)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.
Even better, from inside R, type
install.packages("GRASS")
to install the package.
- Phil Spector
Statistical Computing Facility
Departmen
else factor)(x, levels = names(sort(scores)))
attr(ans, "scores") <- scores
ans
}
- Phil Spector
Statistical Computing Facility
Here's a simple example that might be instructive:
x = 9.790001
y = 9.79
x
[1] 9.79
y
[1] 9.79
x == y
[1] FALSE
abs(x - y) < 1e-8
[1] TRUE
all.equal(x,y)
[1] TRUE
And as others have said, FAQ 7.31 .
- Phil
a.group myData.name Freq
2 1AEnzo 66.5
7 0BJane 58.5
121BMary 70.5
130A Tom 62.5
- Phil Spector
Richard -
Yes, you certainly can use aggregate to acheive what you want:
aggregate(a$hobby,a['name'],paste,collapse=' ')
name x
1 Tom fishing reading
2 Mary reading running
3 John boating
6 1 d 6.0
7 2 f 4.0
8 2 g 4.6
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
colors in cols.
- Phil
On Thu, 7 Oct 2010, ANJAN PURKAYASTHA wrote:
Hi,
I have a data set of 47 columns. I would like to create a boxplot for each
column, each boxplot of a different colour.
So I created a vector "col1". This vector has a subset of the colors
returned by color()- "
)
summary(fcast)
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Eli -
I think you're looking for missing():
tst = function(a,b=1)
+ if(missing(a))print("You must provide a") else print(a)
tst()
[1] "You must provide a"
tst(7)
[1] 7
- Phil Spector
Casper -
I think you want
dotplot(BATCH~RESPONSE,data=d,subset=Type=='SHORT')
or
dotplot(BATCH~RESPONSE,data=subset(d,Type=='SHORT'))
- Phil Spector
Statistica
1, aggregate *would* fail.))
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
printcp(fit1);
x[which.min(x[,'xerror']),'nsplit']})
will put the numbers you want into answer, but there was no reproducible
example to test it on. Unfortunately, I don't know of any way to
surpress the printing from printcp().
Please take a look at the documentation for lmList regarding
the na.action= argument. It should be a *function*, not TRUE
or FALSE. For example, try
lmList(score ~ childid | spring, data=a, na.action=na.omit)
- Phil Spector
.
So when t reaches 22, there is no corresponding
column in Mhb0 or Mhb1.
- Phil Spector
Statistical Computing Facility
Department of Statistics
)'s break different than
a simple call to seq().
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC
her words, you can have a factor's levels appear in whatever
order you'd like by using the levels= argument to factor.
Hope this helps.
- Phil Spector
Statistical Computing Facility
mmy[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
x27;)
[1] "07:00" "07:15" "07:30" "07:45" "08:00" "08:15" "08:30" "08:45" "09:00"
[10] "09:15" "09:30" "09:45" "10:00" "10:15" "10:30" "1
your sas.get call will return only the first 10 observations.
- Phil Spector
Statistical Computing Facility
Department of Statistics
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
)
+ }
result = lapply(pats,getnums)
names(result) = c('first','x','y','fit','res','parameters')
So to reproduce your x, y, fit, and res:
x = result$x[[1]]
y = result$orig[[1]]
fit = result$fit[[1]]
r
d_date,'%Y'))
(I'm 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
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 Sp
David -
I think changing
apply(x,1,function(x)rle(x[which(x==1)[1]:length(x)])$lengths[1])
to
apply(x,1,function(x)if(!any(x==1)) 0 else
rle(x[which(x==1)[1]:length(x)])$lengths[1])
solves the problem.
- Phil
On Thu, 28 Oct 2010, David
.6540 544.6540 17.86 0 P
The first 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
er, you're 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 Spect
yet another sentence and it also has a
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
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
- Ph
Steven -
Does typing
Sys.setlocale('LC_ALL','C')
before the offending command suppress the message?
- Phil Spector
Statistical Computing Facility
00*sapply(dat,function(x)sum(dat >= x))/length(dat))
user system elapsed
0.024 0.000 0.026
- Phil Spector
Statistical Computing Facility
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 Sp
= categories[my.df$names]
creates the category column.
- Phil
On Mon, 8 Nov 2010, Dimitri Liakhovitski wrote:
Hello!
Hope there is a nifty way to speed up my code by avoiding loops.
My task is simple - analogous to the vlookup formula in Excel. Here is
how I
A 1
6C 3
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
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
ary in some non-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.
)
a b c d f g
1 1 2 3 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
ot;1"
If you want the variable to be treated as a numeric
variable, you can use as.numeric:
as.numeric(myvar)
[1] 0 0 0 1
Hope this helps.
- Phil Spector
Statistical Computing Facility
2,6,1,7,0))
chk
[1] FALSE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE
[13] TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE
[25] FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE
[37] FALSE FALSE FALSE FALSE FALSE TRUE FALSE F
Aleksandr -
What happens when you use
library(maptools)
spb = readShapePoly('/home/sasha/Documents/maps/spb.shp')
- Phil Spector
Statistical Computing Facility
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 Sp
unction(x)!any(x == 100)))
[1] 350
Hope this helps!
- Phil Spector
Statistical Computing Facility
Department of Statistics
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 Computin
x27;d need to use Vectorize() before
trying to integrate:
integrate(Vectorize(Ybar),0,1)
0.4587882 with absolute error < 5.6e-05
- Phil Spector
Statistical Computing Facility
th=1)))
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 Computi
,]0010
[3,]0010
[4,]0001
- Phil Spector
Statistical Computing Facility
Department of Statistics
function(...)tkconfigure(lab,foreground='red',text='wrong')
green = function(...)tkconfigure(lab,foreground='green',text='correct')
tkpack(tkbutton(base,text='Red',command=red))
tkpack(tkbutton(base,text='
e efficient to overallocate the
matrix and then truncate it at the end.
I'd strongly recommend that you avoid building your matrix
incrementally inside a loop!
- Phil Spector
1.0985411 1 -1.3981632
[5,] 0.5787438 0 0.2246174
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
],FALSE)
dat[!(abv & blw),]
[,1] [,2]
[1,]37
[2,]65
[3,]55
[4,]84
[5,]74
[6,]06
- Phil Spector
Statistical Computing Faci
ssage.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On We
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
Statis
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, 2
d',5),collapse='')
thestring
[1] "badbadbadbadbad"
t2$V3 = substring(thestring,1,t2$V2)
t2$V3
[1] "bad""badb" "badbad" "b" "ba"
Hope this helps.
- Phil
reproducible example).
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On Mon, 29
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
dimnames.
But remember that, other than when you're 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
3 1 2 3 4 5 1 2 3
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...
Judit -
Does this example provide any insight?
pop <- matrix(0,7,7)# Population matrix when t==0
pop[sample(1:length(pop),1)] <-1 #Population matrix when t==1
which(pop!=0,arr.ind=TRUE)
row col
[1,] 3 4
- Phil S
Rolf -
I'd suggest using
junk <- read.csv("junk.csv",header=TRUE,fill=FALSE)
if you don't want the behaviour you're seeing.
- Phil Spector
St
Katharina -
I think something like this may be helpful:
z = data.frame(matrix(sample(c(LETTERS[1:4],'NR',NA),100,replace=TRUE),20,5))
codes = c(A=100,B=27,C=50,D=25,NR=0)
newz = sapply(z,function(x)codes[x])
- Ph
t <- c(4, 5, 3, 2)
paste(test,collapse=' ')
[1] "4 5 3 2"
- Phil Spector
Statistical Computing Facility
Department of Statistics
mydf[,sort(names(mydf))]
mydf
id var1 var2 var3 var4 var5 var6 var7 var8
1 1 0.0 0.10 0.300 0.9 0.0
2 2 0.4 0.60 0.000 0.0 0.2
3 3 0.0 0.00 0.000 0.8 0.7
- Phil Spector
Jahan -
Try
dat$target = toupper(dat$target)
I would not recommend a loop for something
like this.
(You might also want to brush up on your python,
because what you're trying doesn't work in
python either.)
- Ph
Jonathan -
If I understand correctly,
max(0,floor(log(x,10)))
will return the value you want.
- Phil Spector
Statistical Computing Facility
Department of Statistics
roduce warnings.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Another way, using just base R is
reshape(df,idvar='y',timevar='x',v.names='z',direction='wide')
y z.A z.B z.C
1 D a b c
4 E d e f
7 F g h i
- Phil Spector
work properly if y is a factor or character
variable. If y was numeric, you would need
df[!table(df$y)[as.character(df$y)]
- Phil Spector
Statistical Computing Facility
Depar
15.335847 25.291502
Using snowfall:
library(snowfall)
sim = function(mu)max(replicate(10,max(rnorm(100,mu
sfInit(cpus=4,type='SOCK',parallel=TRUE)
sfSapply(c(1,5,10,20),sim)
[1] 6.200161 10.307807 15.271581 25.055950
Hope this helps.
- Ph
there may be more direct ways.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.ed
almost exactly with R.
Hope this helps.
- Phil
On Mon, 13 Dec 2010, Jared Blashka wrote:
Phil,
This is great! I had no idea nls would accept functions in the formula
position. My apologies for not including data to reproduce my issue.
da
ate into a list as they are created,
rather than giving each one an individual name. That
way you could simply use do.call(rbind,list-of-dataframes) .
- Phil Spector
Statistical Computing Facility
f(lead)paste('^',dots,sep='') else paste(dots,'$',sep='')
+sub(pat,'',str)
+ }
str = "this is a test"
delchars(str,4)
[1] " is a test"
delchars(str,4,lead=FALSE)
[1] "this is a "
Mark -
I believe
lapply(dd,function(m)eval(parse(text=m)))
will do what you want.
- Phil Spector
Statistical Computing Facility
Department of Statistics
ers[1:3]))
mat[as.matrix(df[,1:2])] = df[,3]
mat
a b c
A 1 2 3
B 4 5 6
C 7 8 9
- Phil Spector
Statistical Computing Facility
Department of Stati
Jonathan -
Same problem, same solution:
Suppose your data frame is called df:
thematrix = matrix(NA,max(df$x),max(df$y))
thematrix[as.matrix(df[,1:2])] = df[,3]
- Phil Spector
Statistical Computing Facility
)
That would still assume there was at least one value for each of
med1, med2, and med3 for each combination.
- Phil Spector
Statistical Computing Facility
Department of
7;re looking for, a reproducible example
would be helpful.
- Phil Spector
Statistical Computing Facility
Department of Statistics
Patrik -
I don't know if it's the fastest, but, assuming your
Matrix is called mat, this seems to work fairly quickly:
wh = which(is.na(mat),arr.ind=TRUE)
mat[wh] = apply(mat,2,mean,na.rm=TRUE)[wh[,2]]
- Ph
])
}
Then I think you'll get the result you want if you use
densityplot(~Value|Type, group=Category, data=d, panel=mypanel)
- Phil Spector
Statistical Computing Facility
Jannis -
One approach is as follows:
one = c(1,2,6)
two = c(0,0.5,1,2,3,8)
findit = function(x,vec){
+ y = vec - x
+ y[y<=0] = NA
+ if(all(is.na(y)))NA else which.min(y)
+ }
> sapply(two,findit,one)
[1] 1 1 1 2 3 NA
- Phil S
sample as the second argument.
Hope this helps.
- Phil Spector
Statistical Computing Facility
Department of Statistics
.
- Phil
On Fri, 17 Dec 2010, Jannis wrote:
Dear list,
this may not be related to R but rather to my OS, but I do not
understand the issue of compiling R packages deeply enough to figure out
the exact cause of the problem.
I am trying to
Julian -
I've written a document you might find helpful.
http://www.stat.berkeley.edu/classes/s243/calling.pdf
It also includes the C/matlab interface.
- Phil Spector
Statistical Computing Fac
quot;OK with %s and %s\n", deparse(substitute(var1)),
deparse(substitute(var2
but since you're just printing the string returned by sprintf, I'd
go with cat.
- Phil Spector
Statistical Computing Facility
e "Values" section in the help file for cor.test
to get the names of other quantities of interest.)
The main advantage to this approach is that if you add more matrices
to the allmats list, the other steps automaticall take it into account.
Hope this helps.
as a regular R
value:
20 + nvec['three']
three
60
If the names annoy you (as they seem to annoy many R users),
you can unname the object:
unname(20 + nvec['three'])
[1] 60
- Phil
201 - 300 of 488 matches
Mail list logo