Thomas -
Two ways that come to mind are
apply(dat,1,function(x)sum(x != 0))
and
rowSums(dat!=0)
(assuming your data frame is named "dat").
- Phil Spector
Statistical Computin
ere:
http://gis.washington.edu/phurvitz/R/rodbc_problem/
-P.
**
Phil Hurvitz, MFR | PhD Student, Urban Planning | CBE
1107 NE 45th Street, Suite 535 | Box 354802
University of Washington, Seattle, Washington 98195-4802,
] 1 1 1 1 NA 1
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berk
quot; "1"
[2,] "B" "2"
[3,] "B" "3"
[4,] "B" "4"
$C
[,1] [,2]
[1,] "C" "1"
[2,] "C" "2"
[3,] "C" "3"
- Phi
The rle (run length encoding) function is ideal for
problems like this:
y <- c(4,4,4,2,45,12,12)
rr = rle(y)
rep(seq(along=rr$values),rr$lengths)
[1] 1 1 1 2 3 4 4
- Phil Spector
Statistical Computing Facil
5 percent confidence interval:
1.001052 2.998948
sample estimates:
mean in group F mean in group M
3.5 1.5
If you're uncomfortable with the formula notation, try
with(df,t.test(x[y=='M'],x[y=='F']))
Steve -
Take a closer look at the help page for ave(), especially
the ... argument. Try
data_ave <- ave(data$rammday, data$month, data$year,FUN=mean)
(Assuming you want to calculate the mean -- your example
didn't specify a function.)
x with a 2 column
matrix, but it is a documented fact.
- Phil Spector
Statistical Computing Facility
Department of Statistics
U
David -
You can do what you want pretty easily using sink.
Suppose you want the source code for function "blah"
in the file "blah.func":
sink('blah.func')
print(blah)
sink()
- Phil Spector
ULL)
grp x1 x2
A.1 A 2.5 3.4
B.1 B 5.3 5.4
A.2 A 2.7 5.6
B.2 B 6.5 7.5
A.3 A 5.7 5.4
B.3 B 1.3 4.5
A.4 A 10.1 9.4
B.4 B 10.5 4.1
You could generalize the varying argument like this:
mkvarying = function(n)list(paste('x',seq(1,n,by=
get around this restriction using readline:
pat = readline()
\t
pat
[1] "\\t"
cat(pat,'\n')
\t
It also should be remembered that R will add an extra backslash
when it prints a single backslash -- as can be seen, this is
avoided when you use cat().
unique values
of x, and
do.call(rbind,lapply(sdf,getone))
will return a data frame with one row for each unique value
of x.
- Phil Spector
Statistical Computing Facility
";)
two[1:3]
[1] "Date,Open,High,Low,Close,Volume,Adj Close"
[2] "2010-04-15,592.17,597.84,588.29,595.30,6716700,595.30"
[3] "2010-04-14,590.06,592.34,584.01,589.00,3402700,589.00"
This shows that the dates have been faithfully copied from the
csv file
Since R provides the file.exists() function for exactly this
purpose, I would recommend avoiding using shell scripts for
such a simple task. file.exists() is a multiplatform solution
to the problem.
- Phil Spector
If I understand what you're looking for, I think this
may work:
seq=c(2,3,4)
v=c(4,2,5,8,9,2,3,5,6,1,7,2,3,4,5)
lseq = length(seq)
lv = length(v)
matches = sapply(1:(lv-lseq+1),function(i)all(v[i:(i+lseq-1)] == seq))
sum(matches)
[1] 1
- Phil Sp
ar='Hour',idvar='Date',direction='long')
dfnew = dfnew[order(dfnew$Date,dfnew$Hour),]
- Phil Spector
Statistical Computing Facility
I made a list (dataList) of data frames. The list looks like this (the
first two elements):
[[1]]
est cond targets
1 400 exo_depth_65Hautklinik
2 300 exo_depth_65 Ostturm_UKM
3 200 exo_depth_65 Kreuzung_Ro
Dimitri -
Use %in% instead of ==:
test[test$total %in% needed,]
x y total
1 1 2 7
2 2 3 7
5 5 6 9
6 6 7 9
- Phil Spector
Statistical Computing Facility
('id','author'),timevar='time',direction='wide')
should give you what you want.
- Phil Spector
Statistical Computing Facility
arToInt('7')
[1] 55
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Are you saying that
sapply(xx,function(x)weighted.mean(x$H,x$N))
assuming the list of data frames was called xx,
doesn't give the result you want? Could you please
elaborate as to why sapply doesn't give the correct
result?
- Ph
Joel -
Suppose the columns are named x1, x2, x3, x4, and x5.
You can use subscripting:
x[c('x2','x4','x1','x3','x5')]
or, to save typing the quotes
subset(x,select=c(x2,x4,x1,x3,x5))
re cell.line value
1 feature1 5637 -0.56
2 feature2 5637 -0.91
3 feature3 5637 0.44
4 feature11321N1 -0.93
5 feature21321N1 -0.94
6 feature31321N1 -0.25
- Phil Spector
Statistica
happy to take a look.
- Phil
On Sat, 24 Oct 2009, Michael Jones wrote:
If I make the data from smaller:
featureDataHead = head(featureData)
featureDataHead = featureDataHead[ , 1:4]
melt(featureDataHead,id.var='feature',variable_name='cell.line')
It works fine
Hi R Community:
I want to take the difference in two dates:
dt2 - dt1.
But, I want the answer in months between those 2 dates.
Can you advise me?
Please respond to: p...@cdc.gov
Thank you!
Phil Smith
Centers for Disease Control and Prevention
latA longA id
1.A 1A 41.68 82.85 1
2.A 2A 41.90 82.52 2
3.A 3A 42.25 81.92 3
4.A 4A 42.55 80.03 4
5.A 5A 44.05 83.03 5
. . .
- Phil Spector
Jason -
I've found the mult.fig.p function in the cwhmisc package
to be very handy for this sort of thing.
- Phil Spector
Statistical Computing Facility
Departme
R CMD INSTALL mprobit_0.9-2.tar.gz
They'll be some warning messages, but the package should get built.
- Phil Spector
Statistical Computing Facility
Department of
uot;, xlab="Day of adult
life",ylab='lx',lwd=2.2)
mapply(function(x,y,col)points(x,y,type='b',col=col),day,lx,rainbow(length(lx)))
legend('topright',names(lx),pch=1,lty=1,col=rainbow(length(lx)))
title('Survival vs. Ti
;File2','File3')
themats = lapply(files,read.table)
ans =
outer(1:3,1:3,Vectorize(function(i,j)sd(sapply(themats,function(x)x[i,j]
- Phil Spector
Statistical Computing Faci
Lisa -
I think this is what you're looking for:
myfunction = function(...)do.call(cbind,list(...))
- Phil Spector
Statistical Computing Facility
Department of Stati
df[rep(1:nrow(df),each=3),]
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
b <- a[rmask,,drop=FALSE]
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berke
ngs. Since you said the numbers could
occur anywhere in the string, you could have provided some
examples where the numbers weren't the last part of the string.
- Phil Spector
Statistical Computing Facility
(y,1,function(x)as.numeric(strsplit(x[3],',')[[1]]))
names(res) = y[,1]
boxplot(res)
- Phil Spector
Statistical Computing Facility
more readable form:
v1 = sapply(output,function(x)x$vec)
v2 = sapply(output,function(x)x$other))
Notice that if the objects returned by sapply are not conformable,
it will return its result in a list.
- Phil Spector
Nancy -
The separator in these files is the comma, not the semicolon.
Try
train = read.csv('trainingset.txt',check.names=FALSE)
test = read.csv('testset.txt',check.names=FALSE)
- Phil Spector
ata*
[7] lme.groupedData* lmList.groupedData*
[9] print.groupedData* update.groupedData*
Thus subscripting for these objects is performed differently when
the nlme package is loaded.
- Phil Spector
Janna -
Another thing that's sometimes useful with a new package
is to run the example function, like
example(TTR)
This will run the examples from the documentation to give
you a quick idea of what the package can do.
- Phil Sp
column of a matrix or data frame. So if you
wanted the means of each column of test, you could write
apply(test,2,mean)
- Phil Spector
Statistical Computing Facility
if you wish to use jni with java 1.6 on a mac you have to compile the native
code as a 64 bit application (-m64 on a gcc command line)
hope this helps
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list
https://stat.ethz.
1
11 7 6 4 4 8 3 8 8 10 61
12 9 2 6 2 8 7 5 4 2 11
- Phil Spector
Statistical Computing Facility
Department of Statistics
Nancy -
Please notice that ** is not an R operator.
The caret (^) is the exponentiation operator in R.
- Phil
On Tue, 29 Dec 2009, Nancy Adam wrote:
Hi everyone,
I tried to write the code of computing R2 for a regression system but I failed.
This
Nathan -
One way would be
df$id[match(v,df$Name)]
- Phil Spector
Statistical Computing Facility
Department of Statistics
Anna -
You could also look at the problem from the other direction:
data[,names(datas) != 'A']
- Phil Spector
Statistical Computing Facility
Department of
Barry =
Suppose your data frame is called "mydat". Then something like
mydat[,sapply(mydat,class) %in% c('numeric','integer')]
might do what you want.
- Phil
On Sat, 16 Feb 2013, Barry DeCicco wrote:
pecial characters like dashes in variable
names.
Hope this helps.
- Phil Spector
Statistical Computing Facility
Department of Statistics
event due to the missing time-dependent covariate at day
6. Is there a way I can keep this event without filling in a covariate
value at day 6?
-Phil
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list
https://stat.ethz.
://www.stat.berkeley.edu/classes/s243/calling.pdf
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
','u','b')
any(list2 %in% list1)
[1] TRUE
list2 = c('z','y','x','w','v','u','t')
any(list2 %in% list1)
[1] FALSE
- Phil Spector
Statistical Computing Facility
Sherri -
Perhaps calling
par(ask=TRUE)
before plotting would be useful. (You'll be prompted to
hit Return to see the next plot in the series.)
- Phil Spector
Statistical Computing Fac
Arturo -
Something like
cut(x,quantile(x,(0:10)/10),labels=FALSE,include.lowest=TRUE)
should give you what you want.
- Phil Spector
Statistical Computing Facility
00
100 * prop.table(tt,2) # total of column percentages = 100
AB
a 22.58065 18.25397
b 24.19355 13.49206
c 14.51613 20.63492
d 21.77419 26.19048
e 16.93548 21.42857
- Phil Spector
Stati
eriod)
lapply(names(my.data)[1:2],
+function(y)boxplot(formula(paste(y,'TimePeriod',sep='~')),
+main=y,data=my.data))
- Phil Spector
Stati
c,sep='.')
tt$b=NULL
tt$c=NULL
answer = reshape(tt,idvar='a',timevar='bc',direction='wide')
- Phil Spector
Statistical Computing Facility
Rachel -
Not exactly a reproducible example, but maybe
t1 <- subset(nih2009, ic_name %in% levels(nih2009$ic_name)[c(27,51)])
- Phil Spector
Statistical Computing Facil
Sarah -
If you're willing to forgo the loop,
res = unlist(mapply(rbinom,frequency,no_trials,prob))
res[res == 0] = 1
will give you what you want.
- Phil Spector
Statistical Computing Fac
Yuan -
There may be faster ways, but
names(lst)[sapply(lst,function(i)'a' %in% i && 'c' %in% i)]
seems to do what you want.
- Phil Spector
St
Song -
Set the element to NULL:
al=list(c(2,3),5,7)
al[[2]] = NULL
al
[[1]]
[1] 2 3
[[2]]
[1] 7
- Phil Spector
Statistical Computing Facility
Department of Statistics
; enters into the picture.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.
75.00NaN 18.00NaN 12.90
If this isn't suitable for your larger problem, please describe that
problem in greater detail.
- Phil Spector
Statistical Computin
see why your
program doesn't work properly.)
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Ber
Colton -
Have you looked at the invert= argument of grep()?
(In regular expressions, ^ means "beginning of string",
and ! has no special meaning.)
- Phil Spector
Statistical Computin
Giulio -
This
sub('^.* ?(Rv[^ ]*) ?.*$','\\1',a)
[1] "Rv3018c" "Rv1135c" "Rv1548c" "Rv0755c" "Rv3367"
seems to do what you want.
- Phil Spector
Stephen -
format(as.POSIXct(x),"%Y-%m-%d %H:%M:%S")
[1] "2009-08-07 17:00:00" "2009-08-07 17:15:00" "2009-08-07 17:29:59"
[4] "2009-08-07 17:45:00" "2009-08-07 18:00:00"
- Phil Spector
c',str1,sep='')
print(qr2)
[1] "abc\"xyz\""
cat(qr2,'\n')
abc"xyz"
nchar(qr2)
[1] 8
- Phil Spector
Statistical Computing Facility
Hello R-philes,
I'm very new to R and hope this is a simple question to answer:
I reading in 10 univariate time series and then using "plot()", which produces
two columns of stacked plots showing the data. Perfect.
Next, I want to add things using "lines()", but it's not working correctly. How
e=sum(x[-1][x[-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 Co
Juliet -
Since you're operating on each column, apply() would
be the appropriate function;
mymat = apply(mymat,2,function(x){x[x<0] = min(x[x>0]);x})
- Phil Spector
Statistical Computi
results in a list.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
direction='long',timevar='color')
two$shape=factor(two$shape,labels=c('Circle','Square','Triangle'))
two$color=factor(two$color,labels=c('Blue','Red','Green'))
names(two)[4] = '
'1','1'))
[1] 0 1 1
library(car)
recode(d,"c(1,2)='1'")
[1] 0 1 1
- Phil Spector
Statistical Computing Facility
Department of Sta
='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
art[2,]
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.berkeley.edu
On We
image pattern 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
Does
outer(p_11,p_12,Vectorize(guete))
do what you want?
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC
TRUE, sep="\t", 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
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.
Gregory -
Please provide a reproducible example.
I have no idea what results is.
- Phil
On Sun, 12 Sep 2010, Gregory Ryslik wrote:
Hi,
Doing that I get the following:
Browse[2]> Reduce["+",results]
Error in Reduce["+", results] :
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 Fac
!10 %in% x
(or !(10 %in% x) if you don't believe in R's precedence rules.
- Phil Spector
Statistical Computing Facility
Department of
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 Sp
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 Fac
B533 2.328799
. . .
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Ber
t the estimates into
the pth row (mymat[p,]) or pth column (mypat[,p]) of the matrix.
- Phil Spector
Statistical Computing Facility
Department of Stati
50 when you meant 70.)
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
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.
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 Facil
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
.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
Statistical Computing Facility
Department of Statistics
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
')) data = resp_data )
. . .
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
function(tm)sum(dat$login_time <= tm & dat$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 he
\.csv$'),readwrite,'/some/location')
It will read 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
7;)
Read 7 items
[1] "H.2.C" "C.1.D" "C.3.R" "E.0.N" "C.2.S" "C.0.G" "H.3.G"
Hope this helps.
- Phil Spector
Statistical Computing Facility
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 Fac
101 - 200 of 488 matches
Mail list logo