x['price']
price
1 321.0
2 323.5
- Phil Spector
Statistical Computing Facility
Department of Statistics
U
John -
You can use a syntax similar to what you've tried with
the select= argument of the subset function:
subset(dfxyz,select=-y)
x z
1 1 0
2 2 0
. . .
subset(dfxyz,select=-z)
x y
1 1 11
2 2 12
. . .
- Phil Sp
Here's one way:
H = array(c(8:5,1:4),dim=c(2,2,2))
which(H==min(H),arr.ind=TRUE)
dim1 dim2 dim3
[1,]112
which(H==max(H),arr.ind=TRUE)
dim1 dim2 dim3
[1,]111
- Phil Sp
~lnbm|sp.id,data=one)
which might be more useful.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Luca -
What happens why you type
Sys.setlocale('LC_ALL','C')
before issuing the source command?
- Phil Spector
Statistical Computing Facility
Depa
hich would explain the error more
thoroughly, is included in the error message.
- Phil Spector
Statistical Computing Facility
Department of
[rows.to.keep,]
[,1] [,2]
a12
c34
d45
- Phil Spector
Statistical Computing Facility
Department of Statistics
55148 -4
9 11 5 2.4037376 -6
10 11 5 3.4295063 -5
- Phil Spector
Statistical Computing Facility
Department of Statistics
U
Marius -
Do you get the behaviour you want if you substitute
if(i == 5){cat('i==5\n');quit(save='n')}
for the line with the call to stop?
- Phil Spector
Statistica
u include all possible levels in a factor, R will
automatically put zeroes in the right places when you use table():
table(d1$group,d1$cat)
cat1 cat2 cat3 cat4 cat5 cat6
land 0 1700 19 23
water0 1500
Ben -
droplevels was introduced in R version 2.12.0.
Since you are running version 2.10.1, it won't be
available. You might want to upgrade to a more
recent version.
- Phil Spector
Statistical Comp
Robert -
If sqlTables() works, then R already knows the name of your database.
Do you get a different result if you try
seiz.df <- sqlFetch(chnl, 'MAIN')
- Phil Spector
Statistical Compu
?do.call
Please provide a reproducible example if the help file is
not sufficient.
- Phil Spector
Statistical Computing Facility
Department of Statistics
e information that you want.
- Phil Spector
Statistical Computing Facility
Department of Statistics
=pop,grid.dens))
and you can access the two parts like this:
result = UUU(pop,grid.dens)
result$pop# updated pop
result$grid.dens # updated grid.dens
Hope this helps.
- Phil Spector
Statistical Computing
',sep='~')),data)
will do what you want.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Harold -
If there aren't any true quoted fields in the file, you
could pass the quote="" option to read.delim().
- Phil Spector
Statistical Com
?all
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec
,...)})
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec
ects:
aggregate(thedata$value,list(hour=hours(thedata$date)),mean)
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
data frame from aggregate.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
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
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
the dates are in the current year, and
return a POSIXlt object. Alternatively, you could pass
an origin to as.Date:
as.Date(dat$doy,origin='2009-12-31')
to get a similar Date object.
- Phil
On Fri, 27 Aug 2010, Toby Gass wrote:
Hello
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)
as no effect, nor does xaxt = 'n'. However I can
add ticks with with yaxp or xaxp; I just can't remove the existing ticks. Is
this known/correct behavior? Am I overlooking some way to remove those default
ticks?
Thanks,
Phil
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
a,list(ID=df$ID),paste,collapse='')
- Phil Spector
Statistical Computing Facility
Department of Statistics
NA
[3,] -2.5787357 1.381395 -1.6545857 0.8239982 -1.169961
- Phil Spector
Statistical Computing Facility
Department of Statistics
Here's one possibility:
funmaker = function(x,y,z)function(z)x + y + (x^2 - z)
uniroot(funmaker(1,3,z),c(0,10))$root
[1] 5
uniroot(funmaker(5,2,z),c(30,40))$root
[1] 32
(The third argument to the function doesn't really do anything.)
- Ph
Ryan -
summary expects an lm object, and fit is a list. So
you need to use something like
lapply(fit,summary)
to pass each list element to the summary function.
- Phil Spector
Statistical Computing Facility
creating the
96x34 array, there might be a better solution.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
?arima.sim
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
One way to get the ratings would be to use the ave() function:
rating = ave(x$freq,x$track,
FUN=function(x)cut(x,quantile(x,(0:5)/5),include.lowest=TRUE))
- Phil Spector
Statistical Computing Facility
John -
In your example, the misclassified observations (as defined by
your predict.function) will be
kyphosis[kyphosis$Kyphosis == 'absent' & prediction[,1] != 1,]
so you could start from there.
lex number
(-2)^2.1
[1] NaN
complex(real=-2)^2.1
[1] 4.077269+1.324785i
- Phil Spector
Statistical Computing Facility
Department of
with the data frames you're creating.
- Phil
On Fri, 13 May 2011, Woida71 wrote:
I would like to create a certain number of dataframes out of one dataframe
where each of the dataframes
is related to a factor. This should be possible with
t of the final
query. You might also familiarize yourself with
dbGetQuery, which may be more suited to your needs.
- Phil Spector
Statistical Computing Facility
Depar
1 S1 T1 2 2
2 S2 T1 2 2
3 S1 T2 2 2
7 S2 T2 NA 4
- Phil Spector
Statistical Computing Facility
1 1
result[['Biak-Numfoor rain forests']]$Genus
Bromheadia Homalomena
1 1
Hope this helps.
- Phil Spector
Statistical Computing Facility
< 10 < 11 < 12 < 13 < ... < 31
Notice that it returns the days as factors.
- Phil Spector
Statistical Computing Facility
Department of Statistics
= subset(x,seq == use)
Hope this helps. Take a look at the help page for the ave function
to understand how it works.
- Phil Spector
Statistical Computing Facility
John -
Try
infert[,toolong] = sapply(infert[,toolong],cut2,g=10,levels.mean=TRUE)
- Phil Spector
Statistical Computing Facility
Department of Statistics
27;,'\\U\\1\\2\\L\\3',TEXT,perl=TRUE)
[1] "" "BBB|cc" "|ddd"
- Phil Spector
Statistical Computing Facility
reproducible example.
- Phil
On Fri, 27 May 2011, Jeanna wrote:
I may have prematurely excited...
I ended up using the split method since my family indicators are
alphanumeric so my issue is as follows.
I'm applying this to different subsets of my
00
[2,]10
[[2]]
[,1] [,2]
[1,]32
[2,]32
[[3]]
[,1] [,2] [,3]
[1,]101
[2,]010
[[4]]
[,1] [,2] [,3]
[1,]222
[2,]223
- Phil Spec
s.
Hope this helps.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@stat.b
'PHQ']
Error in `[.data.frame`(x, , "PHQ") : undefined columns selected
x[['PHQ']]
NULL
So if you don't want this "feature", you can use brackets instead
of the dollar sign for extraction.
Philipp -
I believe you're looking for the merge function.
If you need more guidance, please provide a meaningful
reproducible example.
- Phil Spector
Statistical Computing Fac
[,7] [,8][,9]
[1,] -1.7481451 0.4467964 -0.41358420
[2,] -0.2882922 1.0243662 -0.48263684
[3,] 0.9402479 0.5467952 -0.01922035
[4,] 0.6795783 1.4560765 -0.23013826
[5,] 0.9800312 -1.3462175 -0.77064872
- Phil Spector
handled correctly. There's certainly
no need to create a new input file.
It may be easier to understand as
as.numeric(sub('$','',as.character(x),fixed=TRUE))
which gives the same result.
- Phil Spec
"2" "4" "6"
You might want to use as.numeric to convert them back
to numbers, since SAS doesn't care about that particular
detail.
- Phil Spector
Statistical Computing Facility
Vincent -
I think
apply(y,2,function(x)
cut(x,quantile(x,(0:10)/10),label=FALSE,include.lowest=TRUE))
will give you what you want (although you didn't use set.seed so I
can't verify it against your example.)
- Ph
I need to compute the mean and the standard deviation of a data set and would
like to have the results in one table/data frame. I call tapply() two times
and do then merge the resulting tables to have them all in one table. Is
there any way to tell tapply() to use the functions mean and sd within
dat = c(1.3,1.2,1,3.3,3.3,5.1,1.1,1.2,0)
tt = table(dat)
sum(as.numeric(names(tt))*tt)/ sum(tt)
- Phil Spector
Statistical Computing Facility
Department of Statistics
df3$DESCRIPTION =
sub(' [a-z]{3}/[0-9]{2}','',df3$DESCRIPTION,ignore.case=TRUE)
- Phil Spector
Statistical Computing Facility
Depa
rm(100))
df.lm = lm(y~x1+x2,df)
sdf.lm = summary(df.lm)
sdf.lm$coefficients[,4]
(Intercept) x1 x2
0.7445605 0.8081874 0.2535098
or
sdf.lm$coefficients[,"Pr(>|t|)"]
(Intercept) x1 x2
0.7445605 0.8081874 0.2535098
Hope this helps
abel=FALSE)
[1] 10 6 7 5 9 1 3 7 4 2 9 4 2 10 5 8 1
It gives an answer, but it may not make sense for all data.
- Phil
On Thu, 13 May 2010, vincent.deluard wrote:
Dear Phil,
You helped me with a request to rand matri
split(df1,df1$category),
split(df2,df2$category))
will return a list with the information you want.
- Phil Spector
Statistical Computing Facility
Departmen
ot;"magenta" "yellow"
[8] "gray"
You might get better results by specifying the colors that you
want directly.
- Phil Spector
Statistical Computing Facility
ame,
you'll find the modeling functions work much more smoothly.
- Phil Spector
Statistical Computing Facility
Department of Statistics
enter= or scale= arguments can be omitted if
you only want to divide or subtract.
- Phil Spector
Statistical Computing Facility
Department of Stati
Iurie -
The help file for both functions has a "Values" section
that describes in detail exactly what the function returns.
In both cases, you'll see there is a component named
"statistic", which is what you want.
s(tmp)]
)
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Perhaps not the best or easiest way, but does:
apply(t(combn(idx,2)),1,paste,collapse='.')
[1] "1.3" "1.6" "1.9" "3.6" "3.9" "6.9"
get you in the right direction?
- Phil Spector
?any
Not really a reproducible answer, but I think you're looking
for
apply(tes[,sam],1,function(x)any(is.na(x)))
- Phil Spector
Statistical Computing Facility
Depar
Roni -
Try this:
lm(formula(paste(outcome,'income + covariate1 + coviarate2',sep='~')),
data=my.data) -> model
- Phil Spector
Statistical Computing Facility
Try
z$Col3 = as.numeric(sub('^X','',as.character(z$Col3)))
- Phil Spector
Statistical Computing Facility
Depa
know what
SoilVegHydro is.)
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec...@s
5.552 2.026
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
bject as a
named element.)
- Phil Spector
Statistical Computing Facility
Department of Statistics
U
Here's one possibility:
allfiles = list.files()
csvfiles = list.files(pattern='csv')
allfiles[!allfiles %in% csvfiles]
- Phil Spector
Statistical Com
?unlink
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
Luis -
I *think* that
mapply(list,LHS,RHS,SIMPLIFY=FALSE)
will give you what you want, but without a reproducible
example it's hard to tell.
- Phil Spector
Statistical Computing Fac
Suppose your correlation matrix is called cc. One way
to do what you want is
result = cbind(as.vector(row(cc)),as.vector(col(cc)),as.vector(cc))
result = result[result[,1] != result[,2],]
- Phil Spector
1
if(rls$values[length(rls$values)] == TRUE)ind = ind[-length(ind)]
start[ind] = 'start'
To number the starts, you could use something like
num = rep(0,length(vec))
num[start == 'start'] = 1:sum(start == 'start')
- Phil Sp
Rajarshi -
It's not clear to me what you mean by "the distribution of
levels obs.". Does
as.data.frame(table(x$obs,cut.grp1,cut.grp2))
give you something like what you want?
- Phil Spector
Yan -
Here's one way. It assumes there's exactly one set of
brackets in the string, and they can be anywhere:
aaa<- "up.6.11(16)"
sub('^.*?\\((.*)\\).*$','\\1',aaa)
[1] "16"
- Phil Spector
ur is perfectly consistent with the documentation.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Ber
;,'two','three','four','five','six','seven')
test %in% S1 + 2 * test %in% S2
[1] 1 1 1 2 2 2 0
- Phil Spector
Statistic
Robin -
Does
tapply(value,id,sum)
do what you want?
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC
ere are
many other issues regarding random number generation, but I think what
I've described addresses the issue of the t.test probabilities.
- Phil Spector
Statistical Computing Facility
Try
as.data.frame(as.table(a))
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
jects in your workspace, you
could look at the help page for the assign function.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
alues. (The subtle distinction between na.action=na.omit
and na.rm=TRUE is the function you're calling is that na.omit will remove
the entire row of data when it encounters a missing value, while the na.rm=TRUE
argument will remove missing values separately from eac
400
outer(x,y)
[,1] [,2] [,3] [,4]
[1,] 25 50 75 100
[2,] 50 100 150 200
[3,] 75 150 225 300
[4,] 100 200 300 400
The outer() function will accepts a FUN= argument
which defaults to '*'.
Another possibility is
mapply(rbind,list1,list2,SIMPLIFY=FALSE)
- Phil Spector
Statistical Computing Facility
Department of Statistics
the format you want.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spec.
9-06-15"
as.Date(sub('(\\d+/\\d+/\\d+) .*','\\1',dts),'%m/%d/%Y')
[1] "2009-06-10" "2009-06-15" "2009-06-15"
as.Date(sub('\\d+:\\d+:\\d+ [AP]M','',dts),'%m/%d/%Y')
[1] "200
a loop by preallocating space
for the result.
- Phil
On Tue, 8 Feb 2011, Mike Williamson wrote:
Phil,
Thanks! I am not sure why min & max sometimes work & other times don't
work. In fact, running the script as you had it did work for me.
Nicolas -
I don't think it can be done automatically, but
you can use
row.names(pop) = 1:nrow(pop)
after deleting the column(s) to restore consecutive
numbers for the row names.
- Phil Spector
Statis
Contrast the behaviour of these two statements:
plot(x,y,xlab=NULL,ylab=NULL)
plot(x,y,xlab='',ylab='')
In other words, use xlab='' to supress the label, not NULL.
- Phil Spector
s(c(i-.1,i+.1),rep(mns[i] + 1.96 * sds[i],2));
llines(c(i-.1,i+.1),rep(mns[i] - 1.96 * sds[i],2))}
panel.dotplot(x,y,...)
}
dotplot(Score ~ Dose | Sex, groups=Sex, data=dat,panel=mypanel)
- Phil Spec
time <= both$sunset,'day','night')
both$date = both$sunrise = both$sunset = NULL
Then both should be the data frame you want.
- Phil Spector
Statistical Computing Facility
r from yours because you didn't specify
a seed for the random number generator)
I'm not exactly sure how to form your column "combination", though.
- Phil Spector
Statistical Computing Facility
Try
my.data.frame[my.data.frame$Buy==1 | my.data.frame$Sell ==1, ]
or
subset(my.data.frame,buy == 1 | sell == 1)
Then take a look at the help page for || i.e., help("||")
to see what you did wrong.
- Ph
Marine -
Assuming your data frame is named "df", I think
apply(df,1,function(x)mean(x[x[7]:x[8]]))
will give you what you're looking for.
- Phil Spector
Statistical Com
Francois -
I think you're looking for the any function:
x = c(1,2,3)
y = c(4,5,6)
any(x==y)
[1] FALSE
any(which(x==y))
[1] FALSE
x = c(1,2,3)
y = c(4,2,5)
any(x==y)
[1] TRUE
any(which(x==y))
[1] TRUE
- Phil Sp
use a call to file.choose() by itself to see what
path R expects to see for a particular file or directory.
- Phil Spector
Statistical Computing Facility
Department of
a (most likely) easy solution.
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
301 - 400 of 488 matches
Mail list logo