As I understand, it is an optimization problem.
LeastSquare=sum[y-f(x)]^2
Minimize least square by solving equations about a, b, and c. An iterative
method could be developed to get the result or some R functions might be
found useful. Please refer
http://r.789695.n4.nabble.com/Is-there-any-Gaus
Hi Ravi,
Thank you for your correction. I hope I didn't mess up anything:)
Cheers.
Wu
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/non-linear-fourth-order-differential-equations-tp3062805p3063761.html
Sent from the R help mailing list archive at Nabble.co
Hi Andy,
If you could provide a sample data set, it would help others to give a
solution.
I suggest look at the data and select a model, then anova. Take group as one
variable, record time (1 to 24 ) as the second variable and the week day
(Monday to Friday) as the third variable. Then test the
Hi Yanika,
Please try ?uniroot and ?ployroot
f <- function(x) x^4-16
uniroot(f, lower= -3, upper=0)
polyroot(c(-16,0,0,0,1))
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/non-linear-fourth-order-differential-equations-tp3062805p3062894.html
Sent from the R
Hi Romildo,
Merge two table by id2 first, then reshape to the wide format, sum by source
at last. Hope it helps.
### Data simulation
lsp.text <- " id source destiny id2 caminho order
1 1 2 4 7 0 0
2 2 6 10 4 0 0
3 3 6
Hi,
I would try to sample by row index and column index. Hope it helps.
df <- data.frame(matrix(1:18,nrow=3,ncol=6,byrow=TRUE))
colnames(df) <- c(letters[1:3],LETTERS[1:3])
## Generate a new data frame with 10 rows
one <- two <- three <- numeric(10)
for (i in 1:10) {
## Sample from type I
col
I want to create a graph to express the idea of the area under a pdf curve,
like
http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg
Thank you for any help.
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-sh
Hi Duncan:
I'm curious about the environment setting. ?eval says:
"If envir is not specified, then the default is parent.frame() (the
environment where the call to eval was made). "
So what's the difference between set envir=parent.frame() or not?
Thank you.
Wu
-
A R learner.
--
View t
firsthalf <- myframe[v1,]
or
firsthalf <- subset(myframe, number %in% v1)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Randomly-split-a-sample-in-two-equal-subsamples-tp3021140p3021353.html
Sent from the R help mailing list archive at Nabble.com.
__
Hi Yoan,
Please try ?sample.
Suppose you have 1:n ids of total observations where n is even, you want to
randomly split it into two subsamples, the following code should work.
n <- 20
one.sample <- sort(sample(1:n, n/2))
another.sample <- (1:n)[-one.sample]
Good luck.
Wu
-
A R learner.
Hi Bruclee,
?rle may help.
a <- c(5, 10, 13, 19, 23)
b <- c(1, 4, 7, 9, 15)
ab <- data.frame(value = c(a,b), type=c(rep(0,length(a)),rep(1,length(b
ab <- ab[order(ab$value),]
ab$v2 <- cumsum(ab$type)
ab$matched <- rep(ab$value[ab$type==1],rle(ab$v2)$lengths)
(result <- ab[ab$type==0,c("valu
Hi Solafah,
You are right that two commands are equivalent when p= pnorm(a). You can
check the results by following codes.
n <- 5
a <- -1
set.seed(123456)
qnorm(runif(n,0,pnorm(a)))
p <- pnorm(a)
set.seed(123456)
qnorm(p*runif(n))
Anyway, the elements of the lower tail are not chosen equally by
Hi,
You are right, runif(5,1,50) could generate a same value twice. And I think
that your code runs runif(5,1,50) twice too. Try ?sample
selected <- sample(1:50,3)
data.sim[selected,1] <- data.sim[selected,1] + rnorm(5, mean=20, sd=1)
Hope it helps.
-
A R learner.
--
View this message in
Hi,
Please try ?parse and ?eval. Here is an example:
text <- "3*6"
parse(text=text)
eval(parse(text=text))
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-convert-string-to-object-tp2999281p2999336.html
Sent from the R help mailing list archive at Nabb
Hi:
My result using Kaplan-Meier estimate in survival package was inconsistent
with that from Minitab. The survival probabilities are same, but their 95%
CI are different from other calculation. Could you help me find what is
wrong with the code? Thanks in advance.
library(survival)
raw.a <- c(8
Hi CecĂlia,
Assuming that you want to pair two samples as more as possible, let's
relabel the k1 indices. The x$k1 c(1,1,2,3,3,5) could be relabeled as
c(1.01,1.02,2.01,3.01,3.02,5.01), so as y$k1.
x$k1 <- x$k1+sequence(rle(x$k1)$lengths)/100
y$k1 <- y$k1+sequence(rle(y$k1)$lengths)/100
merge(x
Hi Chris,
Try ?ave will help you. Anyway, I guess you are computing a statistic.
strs <- " level.1 level.2 observation
1 1 0.5
1 1 0.2
1 2 0.6
1 2 0
Hi Nokuzola,
I guess the capital "T".
'c:/temp/M5/limestone.dat'
C:\Temp\M5\limestone.dat
Regards,
Wu
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Fwd-R-SOFTWARE-tp2329861p2329887.html
Sent from the R help mailing list archive at Nabble.com.
__
Hi John,
They are different as Erik said.
> identical(a,b)
[1] FALSE
> row.names(a)
[1] "2" "4" "6" "8"
> row.names(b)
[1] "1" "3" "5" "7"
> row.names(a) <- NULL
> row.names(b) <- NULL
> identical(a,b)
[1] TRUE
Regards,
Wu
array chip wrote:
>
>> a
> a b
> 2 10011048 L
> 4 100110
Hi John,
formatC will do your work. Hope it helps.
x <- y <- c(50.00,25.00,10.00,1.00,0.05,0.01)
plot(x,y,log = "xy",axes = F)
axis(1, x, formatC(x))
axis(2, y, formatC(y))
Regards,
Wu
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/print-numbers-tp2327378p
Hi Marcio,
Your friend has given the answer.
x <- rnorm(10)
y <- rnorm(10)
ind <- c(3,0,1,0,3,0,2,2,0,0)
plot(x, y, col = grey(0:max(ind)/max(ind))[ind], pch = 16)
Mestat wrote:
>
> I am working o a scatterplot where I would like to plot the variables
> according with another frequency var
Hi,
It seems that write.csv doesn't support append now. Use write.table()
write.table(dataF, file = outputFilePath, append=T,col.names =F)
Regards,
Wu
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Append-to-csv-without-header-tp2322115p2322172.html
Sent
Hi,
The code seems complicate, but it's understandable.
##
food=c('fruit','fruit','fruit','drink','drink','drink')
type=c('apple','apple','orange','water','soda','soda')
value=c(2,3,1,5,7,6)
data=data.frame(food,type,value)
share=c((2+3)/(2+3+1),5/6,1/6,5/(5+7+6),13/18,13/18)
market_con=c(re
Hi Yi,
It would be helpful for others to provide a solution if you give your
formulas that calculating the value of share and concentration.
?apply will helps.
Regards,
Wu
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-calculate-the-concentration-
Hi,
Try ?unique please.
x <- c(2,2,9,4,6,2,4,4,6,8,6) # Original vector
unique(x) #New vector only has unique elements
sort(unique(x)) # Ordered
Regards,
Wu
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2321884.html
Sent fro
Hi,
?plot will help you.
plot(0:18,col="white")
points(0:18,0:18,pch=0:18,col=rainbow(19),cex=2)
Turn & Fall wrote:
>
> How do you change the standard plotting function so that points are solid
> and can have a pretty colour?
>
-
A R learner.
--
View this message in context:
http://r
Hi Adrienne,
I guess apply should be better than for loop.
Code like this:
event.gen2 = function(genmat,use1,use2,num,ortho_obs_used){
onerow.gen <- function(one.row, use1){
one.row[num] <- ifelse(...}
genmat[,num] <- NA ##Add one row with NA values
apply(
Hi GL,
Erik has given a data.frame solution. If you data is a list with unequal
lengths, try lapply.
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Intersecting-list-vs-rows-in-matrix-tp2320427p2320463.html
Sent from the R help mailing list archive at Nabble.
Hi Carlos,
I give a handmade code, hope it helps.
y <- list()
y$a <- a
y$b <- c(b,c)
names(y$a) <- "i"
names(y$b) <- c("j","k")
Carlos Petti wrote:
>
> a <- 5
> names(a) <- "a"
> b <- 9
> names(b) <- "b"
> c <- 15
> names(c) <- "c"
> x <- list("i" = a, "j" = b, "j" = c)
>
-
A R learner
Hi,
I guess you just want to reshape your data to wide format.
strs <- "Index Time Value
1 2 0.1
2 3 0.2
3 1 0.3"
DF <- read.table(textConnection(strs),header=T)
rDF <- reshape(DF, idvar="Index", timevar="Time", direction="wide")
rDF[is.na(rDF)] <- 0
-
A R learner.
--
View this message in
iginal message which itself might quote the original original message
.., seem to be too much redundant to me. I have been trying to be a
well-behaved member of the R community:)
Best Regards,
Wu Gong
Uwe Ligges-3 wrote:
>
> Can you please refer and quote the original messages you are
I can't understand why you doubled "("
"if((combos[e,f]==1) "
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/TRUE-FALSE-tp2318668p2318684.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-pr
gsub(pattern = "^[0-9]+ (SPE )*(\\w+) - .*$", "\\2", dat)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Regular-Expression-tp2318086p2318101.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r
Hi,
I assume you used boot package. Try this:
library(boot)
x <- rnorm(136)
fun <- function(x,ind){
x <- x[ind]
m <- mean(x[63:136])-mean(x[1:62])
m
}
boot.x<- boot(x, fun, R = 5000, sim = "ordinary")
-
A R learner.
--
View this message in context:
http:/
Hi Steven,
You code has two problems. One is loop structure which should be for(i in
1:length). The second is that you loop the process twice (for and sapply).
Hope followed code will work.
for (i in 1:length(ind)) {
x <- dat$Close_date[i]
dat[["Flag"]][i] <- ifelse((x >= oc[ind[[i
It seems that we can't change the order of varying argument or v.names.
"Notice that the order of variables in varying is like x.1,y.1,x.2,y.2. "
Code can only be:
reshape(d,varying=c("x1","y1","x2","y2"),v.names=c("x","y"),dir="long")
-
A R learner.
--
View this message in context:
http:
It's interesting that sweep is the slowest one comparing to replicate and rep
:)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Multiply-each-depth-level-of-an-array-with-another-vector-element-tp2315537p2316586.html
Sent from the R help mailing list archive a
i <- "piante_venere.csv"
gsub("^.*_(.*)\\.csv$", "\\1", i)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/gsub-tp2316443p2316550.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org
ff <- function(filename)
{
dat1 <- read.csv(file=filename,header=TRUE)
}
filename <- "D:\dat.csv"
ff(filename)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-read-a-file-inside-a-function-tp2316516p2316528.html
Sent from the R help mailing list archi
I have only achieved a half improvement.
x <- array(1:2400*1, dim = c(200,300,400))
y <- 1:400*1
ptm <- proc.time()
z <- x*as.vector(t(replicate(dim(x)[1]*dim(x)[2], y[1:dim(x)[3]])))
"replicate:"
proc.time() - ptm
x <- array(1:2400*1, dim = c(200,300,400))
y <- 1:400*1
ptm <- proc.time
Assigning the value directly to result[i] would give a null to result. Like
that:
result[[i]]<-taxondiveO(abd,taxa)
result[[i]]<-as.data.frame(result[[i]])[1,]
In fact your code's result should have null elements in it. You lost your
nulls through do.call process.
I can't find a way to assign t
read.table("temp.txt",header=T,colClasses = "character")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/a-question-about-read-table-with-or-without-read-table-urgent-tp2314423p2314445.html
Sent from the R help mailing list archive at Nabble.com.
_
You have almost achieved your goal.
plot(1:100, axes=F)
axis(1,at=seq(0,100,10)[c(1,3,5,7,11)])
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/ticks-label-of-plot-tp2314226p2314294.html
Sent from the R help mailing list archive at Nabble.com.
You can't find a way to get the 3 column result by setting the aggregate
function.
data.frame(res[1], res[[2]],check.names = F)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/aggregate-with-non-scalar-functions-tp2313987p2314063.html
Sent from the R help mai
Hi,
Try help("$").
dwt <- function(ld, filter='d8', n.levels=lev, boundary="reflaction")
{
list(W=ld, V=n.levels,filter=filter)
}
dec <- dwt(1:10, filter='d8', n.levels=10, boundary="reflaction")
dec$W
dec$V
dec$filter
dec$W <- sqrt(1:10)
dec
-
A R learner.
--
View this messa
Just a little difference.
ecdf.tbl <- function (.dat) {
.dat <- as.matrix(.dat)
na.m <- is.na(.dat)
.dat[na.m]<-0 # Assign NA a value 0
res <- apply(t(apply(.dat,1,cumsum)),2,cumsum)
res[na.m] <- NA # Assign NA back
return(res)
}
-
I don't know what you really want, but reshape will help you.
reshape(mydata, timevar="taskid",idvar="userid", direction="wide")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/split-lapply-over-multiple-columns-tp2312871p2312909.html
Sent from the R help mai
Do you want to put two figures into one pdf page?
pdf(file="testpdf.pdf")
par(mfrow = c(2, 1))
plot((1:20)^2,1:20,type="b",lwd=4,col="blue")
lines((1:20)^3,1:20,type="b",lwd=4,col="red")
plot((1:20)^4,1:20,type="b",lwd=4,col="green")
lines((1:20)^5,1:20,type="b",lwd=4,col="yellow")
dev.off()
Hi,
Please check your dimensions of theta.
> ff <- function(theta) theta[,1]
> theta <- 1:5
> ff(theta)
Error in theta[, 1] : incorrect number of dimensions
> theta <- data.frame(c(1:5),c(6:10))
> ff(theta)
[1] 1 2 3 4 5
-
A R learner.
--
View this message in context:
http://r.789695.n4
I don't think one session can get information from another session, except
use load.
I simulate you situation within one session. Hope it helps.
#Simulate the first session
object1 <- 1:10
save(object1,file="ob1")
rm(object1)
object1
#Simulate the second session
object2 <- (1:10)*2
save(object2,
I have just learned from the R Language Definiation
##Operators are special functions
# Examples
"<-"(x,1:6)
"["(x,3)
"+"(3,5)
'-'(3,6)
'/'(3,6)
'*'(3,6)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Using-as-a-function-tp2307292p2312424.html
Sent from the R
Is this you want?
plot((1:20)^2,1:20,type="b",lwd=4,col="blue")
lines((1:20)^3,1:20,type="b",lwd=4,col="red")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Plotting-multiple-layers-maps-on-same-page-tp2312223p2312414.html
Sent from the R help mailing list arc
Another solution
factor(port1[,2], labels=levels(stocks[,2]))
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/mixing-strings-and-numeric-doubles-in-an-array-tp2312091p2312313.html
Sent from the R help mailing list archive at Nabble.com.
__
The apply function coerces the factor results to a character array
apply(g,2,class) # gives character
The kruskal.test function doesn't take character vector as the group
argument.
kruskal.test(as.character(plant.height) ~ as.character(g[,8])) #doesn't work
kruskal.test(plant.height ~ as.characte
I have been struggling to make the sense of permutation test for weeks. It
seems will work for you.
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Problems-with-normality-req-for-ANOVA-tp2310275p2310967.html
Sent from the R help mailing list archive at Nabble.
Hi,
Putting all parameters into a data frame would help.
Code like:
parameters <-
data.frame(mu=1:24,b=(1:24)*2,tau=(1:24)/2,sigma=(1:24)^2,ro=sqrt(1:24))
ll<- function(parameters){
results <- numeric(24)
for (i in 1:24){
mu <- parameters$mu[i]
b <- parameters$b
It would be helpful if you give a sample data to illustrate the problem. I
really can't understand what you want:)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Permutation-of-a-sequence-to-without-changing-local-distribution-tp2309283p2309616.html
Sent from
I failed many times until Gabor gave his solution. The magic tick!
PART1 <- 'TEXT'
PART2 <- '^'
PART3 <- '`\u00ae`'
ARG <- paste(PART1, PART2, PART3)
text(2,8, parse(text=str))
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Constructing-arguments-for-plotmat
The function write.foreign is used to export data to other statistical
software. To read data from Excel, R has :
library(foreign)
read.xport("name.xpt")
or
library(gdata)
read.xls()
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/a-problem-tp2308667p2308676
I replicated your error.
tau2ca <- NA
if (tau2ca==0) {x <- 0.01} else {x <- tau2ca}
Hope it helps. And I couldn't replicate your second program, but it seems
ok.
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/conditonal-if-tp2308568p2308578.html
Sent from
Hi,
R has a buildin function ?rowsum
rowsum(DF$Data,DF$Id,na.rm=T)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Summing-by-index-tp2308332p2308411.html
Sent from the R help mailing list archive at Nabble.com.
__
Hi Peter,
Here is my homework :)
DD <- function(f,order=1){
f.str <- "body(f)"
while(order>=1) {
f.str <- paste('D(',f.str,',"x")',sep="")
order <- order-1}
ddf <- f
body(ddf) <- eval(parse(text=f.str))
ddf}
f <- function(x,alpha) x^alpha
Hi, set sep="\n"
x <- c("X XXX","X XX.XX","- ( XX.XX XXX )" )
cat(x,file="x.txt",sep="\n")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Ouput-several-lines-of-cat-tp2307900p2307945.html
Sent from the R help mailing list archive at Nabble.com.
## specify the function string
f.str <- "x^alpha"
## higher derivatives
DD <- function(f.str, x = 2, alpha=3,order = 1){
expr.s <- parse(text=f.str)
while(order>=1) {
expr.s <- D(expr.s,"x")
order <- order-1}
eval(expr.s)
}
compute
DD(f.str,x=1,alpha=0.5,order=1)
-
A R learner.
--
View th
Hi,
Please try ?rle
t.x <- x[order(x[,1],x[,2]),]
t.x[cumsum(rle(t.x[,1])$lengths),]
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Fwd-duplicates-tp2306555p2306617.html
Sent from the R help mailing list archive at Nabble.com.
__
Hi,
The function head also works.
x <- 1:10
head(x,-1)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Replace-last-element-in-a-vector-elegant-solution-tp2306315p2306471.html
Sent from the R help mailing list archive at Nabble.com.
It is a little complicate for me to transform the table. Hope it works for
you.
x <- read.table(textConnection("Johnson 4
Smith4
Smith2
Smith3
Garcia 1
Garcia 4
Rodriguez 2
Adams 2
Adams 3
Adams 4
Turner 4
Turner 3 "),hea
Hi, please try ?merge
DF2$mappedColumn <- DF2$name
merge(DF1,DF2,all.x=T,sort=F)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/columns-mapping-tp2305213p2305250.html
Sent from the R help mailing list archive at Nabble.com.
__
hi,
Library DAAG has onet.permutation function for one-sample permutation test
and twot.permutation function for two-sample permutation test.
Anyway, p-value is a result of a test, what's your test?
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Permutation
Hi William,
I'm curious about that you used d[] <- lapply(d, factor...
Could you please tell me if there are any differences between d[] and d?
Thank you.
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-force-a-table-to-be-square-tp2298707p2298965.html
Hi, try ?levels
myData <- matrix(sample(c(LETTERS[1:10],NA),100,replace=T),nrow=25)
table(factor(as.vector(myData),levels=LETTERS[1:26]),useNA="ifany")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-force-a-table-to-be-square-tp2298707p2298833.html
Se
Hi,
I'm trying to replicate your program. It may be not the same as yours, hope
it helps.
## Create a vector of numbers
cip <- seq(1.0,2.5,by=0.1)
## Create ecdf function
Fn <- ecdf(cip)
## Create f function
f <- function(x){(1-Fn(x))^4}
## Create integrate function
## Because the integrate
Sorry, it was a typo:)
http://r.789695.n4.nabble.com/break-axis-using-plotrix-td803987.html#a803987
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Y-axis-break-tp2295499p2296254.html
Sent from the R help mailing list archive at Nabble.com.
__
plotrix can do it.
There is a post about axis break.
http://r.789695.n4.nabble.com/template/NodeServlet.jtp?tpl=reply&node=2295499
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Y-axis-break-tp2295499p2295998.html
Sent from the R help mailing list archive at
Hi, you can define delimiters
strsplit("Split%at blanks", " |%")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/specify-blank-in-a-string-with-special-characters-tp2295453p2295639.html
Sent from the R help mailing list archive at Nabble.com.
Hi, you can try plot3d
library(rgl)
plot3d(x=x[,2],y=x[,3],z=rowMeans(x[,2:4]))
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/multivariate-graphs-averaging-on-some-vars-tp2292039p2292076.html
Sent from the R help mailing list archive at Nabble.com.
Hi Davis,
Please try ??regex
gsub("(\\-|\\+)([0-9]+)(\\w*)(\\w)", replacement="\\4", x)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Deleting-a-variable-number-of-characters-from-a-string-tp2291754p2291797.html
Sent from the R help mailing list archive at
Do you want to replace specific values of a data set?
df <- sample(c(0,1,2),600,replace=T)
table(df)
df[df==2]<-1
table(df)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-collapse-categories-or-re-categorize-variables-tp2291704p2291727.html
Sent from t
Hi szhan,
I think Joshua gives all you wants -- scale is a really good function.
You can also make your own function work by setting an argument na.rm.
tmp1[tmp1==0]<-NA
student<- function(x){
x<-(x-mean(x,na.rm=T))/sd(x,na.rm=T)
return (x)
}
tmp4<-apply(tmp1, 2, student)
-
I guess your data frame is a little different from the reference, so your
as.logical doesn't work.
attach(Q)
FUN <- function(X, Y) {abs(X - Y)}
round(outer(rank(date)[colour=="b"],rank(date)[colour=="g"],FUN) +
outer(rank(number)[colour=="b"],rank(number)[colour=="g"],FUN))
detach(Q)
-
A
There may exists a good solution, but I can only give a shortcut:)
tmp2 <- (tmp1!=0)*tmp3
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-skip-a-specific-value-when-using-apply-function-to-a-matrix-tp2290898p2290925.html
Sent from the R help mailing li
Correction:
## Minus 7*60*60 seconds to change AM interval from 0-12AM to 7AM-7PM
barplot(table(format((dates-7*60*60), "%w %p")),names.arg=labels)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-plot-a-histogram-of-weekday-frequencies-in-a-list-of-date
Hope it works.
## Create a sample of dates
dates <- sample(seq(ISOdate(2009,1,1), ISOdate(2009,12,31), "hour"),1000)
## Create 14 labels for barplot("Mon AM","Mon PM",etc.)
labels <- format(seq(ISOdate(2010,7,11,5), ISOdate(2010,7,18,4), "12
hours"),"%a %p")
## Use table function to calculate
I don't really understand your question. The function unique can remove
duplicate elements.
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Separating-parts-of-a-column-of-data-in-R-tp2290793p2290840.html
Sent from the R help mailing list archive at Nabble.com.
gsub("(.*)(.{2})","\\1/\\2",dates)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Cut-a-within-elements-by-length-not-value-of-vectors-tp2290440p2290471.html
Sent from the R help mailing list archive at Nabble.com.
If you only want a count, please try table
text <- "ID Age School Grade
1 10 1 98
2 10 2 97
3 10 1 92
4 11 1 90
5 11 1 80
6 11 2 70
7 10 1 80
8 10 1 79
9 11 2 70"
df <- read.table(textConnection(text),header=T)
table(df[,2:3])
If you want sort the data, try order.
-
A R learner.
--
View t
I have the same question about how to see the process behind a function. If I
type sample in R, it really tells nothing about how R selects from a data
set and creates samples.
Thank in advance for any help.
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/How
Correction:
b$label <- cut(b$timestamp, breaks=bks, labels=lbs, include.lowest = T,
right=F)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Merging-columns-along-time-line-tp2289147p2289401.html
Sent from the R help mailing list archive at Nabble.com.
___
I take this case as cut a data set by breaks and assign each segment a label
name.
a <- data.frame(timestamp=c(3,5,8), mylabel=c("abc","def","ghi"))
b <- data.frame(timestamp=c(1:10))
bks <- c(a$timestamp,max(b$timestamp))
lbs <- a$mylabel
b$label <- cut(b$timestamp, breaks=bks, labels=lbs, inclu
Try this:
text <- 'var1 var2
1 ab_c_(ok)
2 okf789(db)_c
3 jojfiod(90).gt
4 "ij"_(78)__op
5 (iojfodjfo)_ab'
df <- read.table(textConnection(text), head=T, sep=" ",quote="")
df$var3 <- gsub("(.*\\()(.*)(\\).*)","\\2",df$var2)
-
A R learner.
--
View this message in context:
http://r.789695.
I suggest trying to write the data into .php file directly.
outfile <-paste(filepath,"distance",".php",sep="")
data <- "Distance=num"
num <- 1000
data <- sub("num", num,data)
write(data,file=outfile)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Write-val
Correction:
data[abs(data$price-avg)<=3*std,]
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Using-which-function-with-xts-tp226p2289166.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help
Let's say your "data" has 2 columns: one is "date" and another is "price",
then
avg = mean(data$price, na.rm=T)
std = sd(data$price, na.rm=T)
The data after those unwanted removed should be:
data[data$price-avg<=3*std,]
-
A R learner.
--
View this message in context:
http://r.789695.n4.n
I don't know the real reason, but help("==") gives some clues.
For numerical and complex values, remember == and != do not allow for the
finite representation of fractions, nor for rounding error. Using all.equal
with identical is almost always preferable. See the examples.
x1 <- 0.5 - 0.3
x2
Do you mean substring?
sub(".txt","", "mytest.txt")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/String-truncate-tp2284045p2284062.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-projec
Please try this
## Import data
id1<-c(4,17,9,1,1,1,3,3,6,15,1,1,1,1,3,3,3,3,4,4,4,5,5,12,9,9,10,10)
id2<-c(8,18,10,3,6,7,6,7,7,16,4,5,12,18,4,5,12,18,5,12,18,12,18,18,15,16,15,16)
id<-data.frame(id1 = id1, id2 = id2)
## Create same structure table
id <- id0 <- unique(id)
leng <- nrow(id)
n <- 0
Try unique and paste.
paste(unique(tes)[,1], unique(tes)[,2], sep = "")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/two-columns-into-one-tp2242516p2242658.html
Sent from the R help mailing list archive at Nabble.com.
__
Hope it helps.
text <- "var1var2
9G/G09abd89C/T90
10A/T932C/C
90G/G A/A"
x <- read.table(textConnection(text), header = T)
x$var1.1 <- sub(".*(.)/.*", "\\1", x$var1)
x$var1.2 <- sub(".*/(.).*", "\\1", x$var1)
x$var2.1 <- sub(".*(.)/.*", "\\1", x$var2)
x$var2.2 <- sub(".*/(.
Do you mean replace values of a column?
> df <- data.frame("Jan" = 1:3,"Feb" = 11:13)
> df
Jan Feb
1 1 11
2 2 12
3 3 13
> df$Jan <- 21:23
> df
Jan Feb
1 21 11
2 22 12
3 23 13
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Re-help-to-replace-
Thank you very much David. I'm sorry for this fault , hope it has not
confused Frostygoat.
I was clueless of recursive reference and I didn't meet any error when I
test the code. So I wonder if there are some useful tips to prevent making
this kind of faults:)
The revised code is followed.
###
1 - 100 of 121 matches
Mail list logo