Hi,
Try:
string1<- "Red, Romeo, Calf"
string2<- "Red, Rome, Ralf"
string3<- "China, Japan, USA"
gsub("R[[:alpha:]]{1,}","MM",string3)
#[1] "China, Japan, USA"
gsub("R[[:alpha:]]{1,}","MM",string2)
#[1] "MM, MM, MM"
gsub("R[[:alpha:]]{1,}","MM",string1)
#[1] "MM, MM, Calf"
Other way would be:
HI,
May be this helps:
record.length <- read.table(text = "NR length
1 100
2 130
3 150
4 148
5 100
6 83
7 60", sep="",header = TRUE)
valida.records <- read.table(text = "NR factor
1 3
Hi,
Try:
a_table[grep("\\d+",a_table)]<- paste0(a_table[grep("\\d+",a_table)],"$\\pm$")
library(xtable)
print(xtable(a_table),sanitize.text.function=identity)
% latex table generated in R 3.0.1 by xtable 1.7-1 package
% Thu Sep 12 21:26:45 2013
\begin{table}[ht]
\centering
\begin{tabular}{rl
Hi,
Also:
a_table[grep("\\d+",a_table)]<-paste0(sprintf("%.2f",as.numeric(a_table[grep("\\d+",a_table)])),"$\\pm$")
# 2 d.p.
print(xtable(a_table),sanitize.text.function=identity)
A.K.
- Original Message -
From: arun
To: Sachinthaka Abeywar
1 package
% Thu Sep 12 22:42:58 2013
\begin{table}[ht]
\centering
\begin{tabular}{rlll}
\hline
& Fruits & Adam & steve \\
\hline
1 & apples & 17.10$\pm$2.22 & 3.20$\pm$1.10 \\
2 & oranges & 3.10$\pm$2.55 & 18.10$\pm$3.20 \\
\hline
\end{tabular}
\end{ta
Hi,
rownames(y_raw_mt)=y_raw[,1] ## y_raw not defined.
set.seed(25)
mat1<- matrix(sample(c(NA,1:20),100,replace=TRUE),20,5)
#changed the function to process 'mat1'. Also, it is better to read the file
separately and check ?str(dt.table) before proceeding.
write.table1=function(durty_data){
HI,
Hi,
(fit <- arima(USAccDeaths, order = c(0,1,1),
seasonal = list(order = c(0,1,1
forecasted_value<-predict(fit, n.ahead = 24)
lst1<-lapply(forecasted_value,function(x)
data.frame(Year=as.vector(floor(time(x))),
Month=factor(as.vector(cycle(x)),label=month.abb),value=as
Hi,
You could try:
val1<- c(0.854400, 1.648465, 1.829830, 1.874704, 7.670915, 7.673585, 7.722619)
thresh1<- c(1,3,5,7,9)
rowSums(t(replicate(length(thresh1),val1))<= thresh1)
#[1] 1 4 4 4 7
#using ?sapply() could be shortened
sapply(thresh1,function(x) {sum(val1
To: r-help@r-project.org
Cc:
Sent:
Hi,
Some speed comparison
set.seed(434)
val1<- rnorm(1e5)
set.seed(28)
thresh1<- sample(1:20,1e2,replace=TRUE)
system.time(res<- rowSums(t(replicate(length(thresh1),val1))<= thresh1))
# user system elapsed
# 0.320 0.064 0.382
system.time(res2<- sapply(thresh1,function(x) {sum(val1
T
Hi Bill,
Great soluiton!
Just to add:
if values are not sorted (in this case, okay)
set.seed(434)
val1<- rnorm(1e5)
set.seed(28)
thresh1<- sample(1:20,1e2,replace=TRUE)
system.time(res11<- findInterval(thresh1,val1))
#Error in findInterval(thresh1, val1) :
# 'vec' must be sorted non-de
Hi,
Try:
for(i in 1:10) {print(grep("a",letters))}
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
x<- vector()
for(i in 1:10) {x[i]<-grep("a",letters) }
x
# [1] 1 1 1 1 1 1 1 1 1 1
A.K.
- Original Message -
From: capricy gao
To: "r-help@r-project.org"
Cc:
Sent: Frida
Hi,
dat1<- read.table("gao.txt",sep="",header=FALSE,stringsAsFactors=FALSE)
dat1
# V1 V2 V3 V4 V5 V6 V7 V8
#1 ref_gene_id ref_id class_code cuff_gene_id cuff_id FMI FPKM FPKM_conf_lo
#2 - - u C.3 C.3.1 100
HI,
By running your code: on the example dataset:
mat<- structure(c(0.8959863, 0.8951168, 0.8971445, 0.8962497, 0.8963061,
0.8973174, 0.8986438, 0.8964609, 0.8975849, 0.8965599, 1, 2,
3, 4, 5, 6, 7, 8, 9, 10), .Dim = c(10L, 2L), .Dimnames = list(
NULL, c("trace", "iterations")))
while(nro
Hi,
If you have a vector of values to compare:
thresh1<- c(30,4,12,65,5)
indx<-findInterval(thresh1-1,cumsum(X))
indx2<-ave(rep(indx,indx),rep(indx,indx),FUN=seq)
X[indx2]
# [1] 1 3 4 5 8 1 1 3 4 1 3 4 5 8 15 1 3
#you can split this into a list
split(X[indx2],cumsum(c(TRUE,diff(
Hi,
Try:
lab<- as.character(x[,3])
library(lattice)
xyplot(y~time(y),type="b",xlab="Date",ylab="Price",scales=list(x=list(at=time(y),labels=format(time(y),"%b-%d"))),
panel=function(x, y, ...) {
panel.xyplot(x, y, ...);
ltext(x=x, y=y, labels= lab, pos=1, offset=1, cex
Hi,
Try:
aggregate(IND~.,data=net1,sum)
CAMP LOTE HAB TRANS ORDEN IND
1 C1 B1 C C1 0
2 C1 B1 B B3 ACARI 3
3 C1 B1 B B1 ARANEAE 1
4 C1 B1 B B3 ARANEAE 2
5 C1 B1 B B3 COLEOPTERA 2
6 C1 B1 B B1
Hi Jean,
Just to clarify whether it is a 'typo' or not.
data2 <- data.frame(
id = rep(data1$ID, 3),
visit = rep(1:3, rep(dim(data1)[1], 3)),
date = as.Date(c(data1$V1Date, data1$V2date, data1$V3date), "%m/%d/%y"),
dva = c(data1$V1a, data1$V2a, data1$V3a),
dvb = c(data1$V1a, data1$V2a, data1$V3a),#
HI Elaine,
Regarding the second part of your question, use ?cut()
dta$Lat<-floor(dta$Latitude)
res<-aggregate(Range~cut(dta$Lat,breaks=c(6,10,15,20),label=c("6-10","11-15","16-20")),dta,mean)
colnames(res)<-c("Rangesize","Mean")
res
# Rangesize Mean
#1 6-10 675.1920
#2 11-15 851.5
Hi,
You could also use ?xtabs()
dat1<-structure(list(Col1 = structure(c(1L, 3L, 2L, 1L, 3L, 3L, 1L), .Label =
c("A",
"B", "C"), class = "factor"), Col2 = structure(c(2L, 2L, 1L,
1L, 2L, 1L, 2L), .Label = c("a", "b"), class = "factor"), Col3 = c(1,
2, 3, 4, 5, 6, 2)), .Names = c("Col1", "Col2
Hi,
You could also use:
df$x_new<-unlist(lapply(split(df,df$ID),function(x)
as.numeric(min(x[,2])!=x[,2])))
df
# ID T x x_new
#1 1 1 1 0
#2 1 2 1 1
#3 1 3 1 1
#4 2 1 1 0
#5 2 4 1 1
#6 3 3 1 0
#7 3 5 1 1
#8 3 6 1 1
#9 3 8 1 1
A.K.
- Original Mess
HI,
It guess ?get() does not work with $ elements.
x1 <- list(a=c(1,2), b = c(2,4), c=c(4,5,6))
#this works
get(paste("x","1",sep=""))["a"]
#$a
#[1] 1 2
#or
get(paste("x","1",sep=""))[[2]]
#[1] 2 4
A.K.
- Original Message -
From: Soyeon Kim
To: r-help
Cc:
Sent: Tuesday, December
Hi,
I get the results from your method:
x_new
#[1] 0 1 1 0 1 1 1 1 1
I guess there should be three zeros, as there are three IDs.
A.K.
- Original Message -
From: Jose Iparraguirre
To: Carlos Nasher ; "r-help@r-project.org"
Cc:
Sent: Tuesday, December 18, 2012 11:32 AM
Subject: Re:
Hi,
I didn't understand ">".
Lines1<-textConnection("Date Time Close
10/15/12 09:00:00 252.40
10/15/12 09:01:00 253.10
10/15/12 09:02:00 253.15
10/15/12 09:03:00 253.30
10/15/12 09:04:00 253.25
10/15/12 09:05:00 253.45")
library(zoo)
library(xts)
z<- read.zoo(Lines1,header=TRUE,index=list(1,2),FUN
HI,
As I said earlier, I am able to generate the plot.
pdf("Parkplot1.pdf")
plot(1:length(zc1$Close),split(zc1$Close,row(zc1)))
dev.off()
#the pdf is attached.
A.K.
From: 박상규
To: arun
Sent: Wednesday, December 19, 2012 10:04 AM
Subject: Re:
Hi,
You could also try this:
#dat1<-structure BTW, p20 was labelled incorrectly as p29
library(reshape)
dat2<-melt(dat1)
res1<-na.omit(cbind(ID=rep(dat2[,2][grep("ID",dat2$variable)],times=((nrow(melt(dat1))-nrow(dat1))/3)/nrow(dat1)
),dat2[grep("p",dat2$variable),],dat2[grep("lat",dat2$vari
HI,
You could replace the times=. in res1 with:
res1<-na.omit(cbind(ID=rep(dat2[,2][grep("ID",dat2$variable)],times=length(grep("p",names(dat1,dat2[grep("p",dat2$variable),],dat2[grep("lat",dat2$variable),],dat2[grep("long",dat2$variable
HI,
library(gtools)
If you need ?combinations()
combinations(2,10,0:1,repeats.allowed=TRUE)
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#[1,] 0 0 0 0 0 0 0 0 0 0
#[2,] 0 0 0 0 0 0 0 0 0 1
#[3,] 0 0 0 0 0
Hi,
test$test2<-ifelse(test$test1!=0,39,1/test$test1)
A.K.
- Original Message -
From: Yanyuan Zhu
To: r-help@r-project.org
Cc:
Sent: Thursday, December 20, 2012 10:45 AM
Subject: [R] an entry level (stupid) question
Hello all, i'm a newbie to R and now I get stuck by the question, w
Hi,
Try this:
range1<-cut(x,breaks=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1),labels=paste("(",c("0-0.1","0.1-0.2","0.2-0.3","0.3-0.4","0.4-0.5","0.5-0.6","0.6-0.7","0.7-0.8","0.8-0.9","0.9-1"),")",sep=""))
table(range1)
#range1
# (0-0.1) (0.1-0.2) (0.2-0.3) (0.3-0.4) (0.4-0.5) (0.5-0.6) (0.6-0.7)
HI,
May be this link helps you:
http://stackoverflow.com/questions/5764499/decompress-gz-file-using-r
A.K.
- Original Message -
From: herr dittmann
To: "r-help@r-project.org"
Cc:
Sent: Friday, December 21, 2012 9:51 AM
Subject: [R] how can I import op.gz files with read.csv or other
Hi Katherine,
You could try this:
library(plotrix)
png("katherine.png")
plot(0:3,0:3,xlab="",ylab="",type="n",axes=FALSE)
addtable2plot(1,1,output1,cex=2)
dev.off()
A.K.
- Original Message -
From: Katherine Gobin
To: r-help@r-project.org
Cc:
Sent: Friday, December 21, 2012 8:59
HI,
May be this helps:
dat1<-data.frame(var1=factor(rep(1:4,times=3)))
dat1<-transform(dat1,o.var1=ordered(var1,levels=c(1,2,3,4),labels=c("very
satisfied", "fairly satisfied","not very satisfied", "not at all
satisfied")))
dat2<-transform(dat1,or.var1=factor(o.var1,levels=rev(levels(o.var1))
HI,
May be this helps:
Lines1<-"15,30,45;20,45,39;60,49,32;48,59,63"
res1<-read.table(text=unlist(strsplit(Lines1,split=";")),sep=",")
str(res1)
#'data.frame': 4 obs. of 3 variables:
# $ V1: int 15 20 60 48
# $ V2: int 30 45 49 59
# $ V3: int 45 39 32 63
#or
res2<-read.table(text=gsub(";",
HI,
May be this helps:
dat1 <- read.table(text="
20100914 08:01, 3.74
20100914 08:11, 3.74
20100914 08:21, 3.71
20100914 08:31, 4.39
20100914 08:41, 3.74
20100915 08:01, 3.64
20100915 08:11, 3.54
20100915 08:21, 3.61
20100915 08:31, 4.49
20100915 08:41, 3.84
", sep=",
Hi,
try this:
z1<-data.frame(z)
z1[colSums(is.na(z1))<=1]
# id a b
#1 1 4 3
#2 2 3 NA
#3 3 2 2
#4 4 NA 7
#5 5 1 1
A.K.
- Original Message -
From: Evgenia
To: r-help@r-project.org
Cc:
Sent: Sunday, December 23, 2012 4:16 PM
Subject: [R] Select maximum subset
Suppose i
Hi,
Just to make it more general.
z1<-data.frame(z)
z1[colSums(is.na(z1))<=min(colSums(is.na(z1[,-1])))]
# id a b
#1 1 4 3
#2 2 3 NA
#3 3 2 2
#4 4 NA 7
#5 5 1 1
A.K.
- Original Message -
From: Evgenia
To: r-help@r-project.org
Cc:
Sent: Sunday, December 23, 2012 4:16 P
taing information about station name, year, month, day, and
discharge information. i opened it by using
following command
> dat1<-read.table("EL.csv",header=TRUE, sep=",",na.strings="NA")
then by using following codes suggested by arun and rui i managed
, sep=",",na.strings="NA")
>
> You can probably use
>
> dat1 <- read.csv("EL.csv")
>
> (although you may have to double-check some of the other
> default differences between read.csv and read.table, e.g.
> quote and comment.char argument
$WW
#[1] 2.153747 2.130745 5.828026 12.909944
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
Cc: "r-help@r-project.org"
Sent: Sunday, December 23, 2012 9:10 PM
Subject: RE: [R] colmeans not working
Dear Arun,
on having a bir
24739 8.591345 13.773817 5.386458 2.847495
5.448138
# 9 10 11 12
#9.266519 7.63 15.249745 14.335008
Hope it helps.
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
Cc: "r-help@r-project.org"
HI,
Not sure if this works for you.
set.seed(5)
dat<-data.frame(x=sample(1:20,6,replace=TRUE),a=sample(20:40,6,replace=TRUE))
dat1<-transform(dat,f=a/median(a),x_new=x*(a/median(a)))
head(dat1,2)
# x a f x_new
#1 5 31 1.016393 5.081967
#2 14 36 1.180328 16.524590
A.K.
- O
327869 0.7213115
#5 3 25 2.459016 0.8196721
#6 15 30 14.754098 0.9836066
#or
res<-do.call(data.frame,lapply(lapply(1,function(y) dat),function(y)
{y$f<-y$a/median(y$a);y$x_new<-y$f*y$x;y}))
A.K.
From: meng
To: arun
Cc: R help
Sent: Monday, Dece
t;WW","HH")
names1<-names(res)
b<-lapply(res,function(x) {if(is.data.frame(x[,-1])) rowMeans(x[,-1]) else
x[,-1]})
mypath<-file.path("/home/arun/Trial1",paste("myplot_",names1,".jpg",sep=""))
#change the file.path
for(i i
HI Eliza,
You could try this:
set.seed(15)
mat1<-matrix(sample(1:2000,1776,replace=TRUE),ncol=444)
colnames(mat1)<-paste("Col",1:444,sep="")
res<-lapply(seq_len(ncol(mat1)),function(i) mat1[,seq(i,444,37)])
#If you want only this from 1:37, then
res1<-lapply(1:37,function(i) mat1[,seq(i,444,37)]
Hi,
You should have provided a reproducible example.
To convert in general, ?as.POSIXct()
A.K.
- Original Message -
From: Antonio Rodriges
To: r-help@r-project.org
Cc:
Sent: Tuesday, December 25, 2012 7:28 AM
Subject: [R] as.Date to as.POSIXct
Hello,
I have converted some UNIX tim
#your code
identical(res1,res2)
#[1] TRUE
From: eliza botto
To: "smartpink...@yahoo.com"
Cc: "r-help@r-project.org" ; kri...@ymail.com
Sent: Tuesday, December 25, 2012 1:57 AM
Subject: RE: [R] for loop not working
Dear Arun,
as usuall y
Hi,
Jim's method was found to be faster than data.table()
n <- 1
nLevels <- 10
nRows <- 120
Cols <- list(rep(list(sample(nRows)), n))
df <- data.frame(levels = sample(nLevels, nRows, TRUE), Cols)
colnames(df)[-1] <- paste0('col', 1:n)
# convert to matrix for faster processing
df.m <-
Hi,
You could use library(data.table)
x <- data.frame(A=rep(letters,2), B=rnorm(52), C=rnorm(52), D=rnorm(52))
res<- with(x,aggregate(cbind(B,C,D),by=list(A),mean))
colnames(res)[1]<-"A"
x1<-data.table(x)
res2<- x1[,list(B=mean(B),C=mean(C),D=mean(D)),by=A]
identical(res,data.frame(res2))
#[1]
Hi,
You can do this either by:
with(data1,aggregate(y,by=list(x),function(x) x)) #2nd column is a list here
#or
res1<-split(seq(nrow(data1)),data1$x)
#or
res1<-tapply(data1$y,list(data1$x),function(x) x)
res2<- t(sapply(res1,`[`,1:max(sapply(res1,length
res2[cbind(c(rep(8,4),rep(9,4)),c(1:4,1:
Hi,
Assuming the data structure is similar to this example:
difMH<-list(c(1,9,19,21,22,24,25,27,29,30,34,38,40),c(1,2,9,14,18,19,21,22,25,28,30,34,38,39),c(1,8,9,19,21,22,24,25,26,28,30,34,38),c(1,8,9,10,16,18,21,22,25,28,30,32,34,38,39),c(1,9,19,21,22,23,25,27,30,34,36,38,39),c(1,9,10,11,17,18,2
HI,
format(asd,"%d/%m/%Y")
#[1] "03/01/2012"
A.K.
- Original Message -
From: Ron Michael
To: "r-help@r-project.org"
Cc:
Sent: Wednesday, December 26, 2012 1:31 PM
Subject: [R] Working with date
Hi,
Let say I have a date variable:
> asd <- as.Date("2012-01-03")
> asd
[1] "2012-01-
Hi,
Try this:
sapply(iris[,-5],function(x) rbind(mean(x,na.rm=T),sd(x,na.rm=T)))
# Sepal.Length Sepal.Width Petal.Length Petal.Width
#[1,] 5.843 3.057 3.758000 1.199
#[2,] 0.8280661 0.4358663 1.765298 0.7622377
A.K.
- Original Message -
From: Yao H
Hi,
gsub("^\\d(.*/)\\d(.*/.*)","\\1\\2",format(asd,"%d/%m/%Y"))
#[1] "3/1/2012"
A.K.
- Original Message -
From: Ron Michael
To: jim holtman
Cc: "r-help@r-project.org"
Sent: Wednesday, December 26, 2012 2:25 PM
Subject: Re: [R] Working with date
Thanks Jim for your reply.
However I
HI,
Check this link
http://stackoverflow.com/questions/6695105/call-r-scripts-in-matlab
A.K.
- Original Message -
From: Uma Shahani
To: R-help@r-project.org
Cc:
Sent: Wednesday, December 26, 2012 6:38 PM
Subject: [R] Converting R script to Matlab
Hello,
I am very new to R. I have us
))
#[1] "3/1/2012" "25/12/2012" "12/1/2012" "1/10/2012"
A.K.
- Original Message -
From: Jim Holtman
To: arun
Cc: Ron Michael ; R help
Sent: Wednesday, December 26, 2012 9:38 PM
Subject: Re: [R] Working with date
what happens with 25/12/2012?
Hi,
Try
which(!duplicated(c(3,4,1,2,1,1,2,3,5)))
#[1] 1 2 3 4 9
which(!duplicated(c(1,1,2,2,3,3,4,4)))
#[1] 1 3 5 7
A.K.
- Original Message -
From: Emmanuel Levy
To: R-help Mailing List
Cc:
Sent: Thursday, December 27, 2012 2:17 PM
Subject: [R] Retrieve indexes of the "first occurre
HI,
Not sure if this is what you wanted:
set.seed(14)
Z<-array(sample(1:100,80,replace=TRUE),dim=c(5,2,8))
set.seed(21)
Y<-matrix(sample(1:40,40,replace=TRUE),nrow=8)
do.call(cbind,lapply(seq_len(dim(Z)[1]),function(i) Z[i,,]%*%Y[,i]))
# [,1] [,2] [,3] [,4] [,5]
#[1,] 5065 6070 12328 11536
Hi,
You could also use:
apply(cbind(v1,v2),1,function(x) x[order(x)])
#or
unique(t(apply(cbind(v1,v2),1,sort.int,method="quick")))
By comparing different methods:
set.seed(51)
v1<-sample(0:9,1e5,replace=TRUE)
set.seed(49)
v2<-sample(0:9,1e5,replace=TRUE)
system.time(res1<-unique(t(apply(cbind(v1,
Hi, Sorry, but how did you bring it out?
Thanks
On Fri, Dec 28, 2012 at 8:48 AM, arun kirshna [via R] <
ml-node+s789695n4654093...@n4.nabble.com> wrote:
> Hi,
> bp.sub<- structure(list(CODEA = c(1L, 3L, 4L, 7L, 8L, 9L, 10L, 11L, 12L,
> 13L, 14L, 16L, 17L), C45 = c(NA, 2L, 2L, 2
HI,
YOu may try ?merge() or ?join() from library(plyr)
bat_activity<-read.table(text="
Date Time Label Number
6/3/2011 10:01 Tadbra 2
6/3/2011 10:02 Tadbra 4
6/3/2011 10:08 Tadbra 1
6/3/2011 10:13 Tadbra 2
6/3/2011 10:49 Tadbra
: arun
Sent: Friday, December 28, 2012 9:19 AM
Subject: Re: [R] Merging data tables
Hi, I was able to get the merge to work OK, I think...
Bats_weather<-merge(sewage.Wind_Temp.temp,Tabr_all2.temp,by.x="row.names",by.y="row.names",incomparables
= NA,all.x =
HI,
Check this link:
http://stackoverflow.com/questions/6894922/how-to-read-multiple-excel-sheets-in-r-programming
http://theweiluo.wordpress.com/2011/09/07/how-to-read-a-multiple-sheet-excel-file-into-r/
A.K.
- Original Message -
From: eliza botto
To: "r-help@r-project.org"
Cc:
Sen
Hi,
Try:
y<-paste("c","(",paste(unlist(sapply(x,seq)),collapse=","),")",sep="")
y
#[1] "c(1,2,3,4,1,2,3,1,2,3,4,5)"
A.K.
- Original Message -
From: Haoda Fu
To: "r-help@r-project.org"
Cc: "haod...@yahoo.com"
Sent: Friday, December 28, 2012 12:43 PM
Subject: [R] Any simple way to ma
28, 2012 6:09 PM
Subject: thanks -- Re: syntax for identifying more than one
Hi Arun,
Thanks for responding to my posted question. Your example showed how to use
numsummary to produce mean incidents, sd incidents, etc. for each level of "id"
and for each level of "year." I'm tr
ve.
"
A.K.
- Original Message -
From: "Suzen, Mehmet"
To: arun
Cc: Ranjan Maitra ; R help
Sent: Saturday, December 29, 2012 1:19 PM
Subject: Re: [R] efficiently multiply different matrices in 3-d array with
different vectors?
What I had in mind was a tensor multiplicatio
HI,
Its not clear esp
"
I wanna do the following:
10*x1,100*x2,1000*x3"
Did you mean 10* dat[,1], 100*dat[,2], 1000*dat[,3]?
dat<-read.table(text="
x1 x2 x3
0.2 1.2 2.5
0.5 2 5
0.8 3 6.2
",sep="",header=TRUE)
z<-c(10,100,1000) # 3rd element in your z is 100, which is confusing
es: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
For
your question, I guess you need to add interaction term also in the
model. I am not sure whether you need random effects in the model. If
that is the case, you need ?lmer() from library(lme4). You could also
post the question in R
$ x3: num 2500 5000 6200
A.K.
____
From: meng
To: arun
Cc: R help
Sent: Sunday, December 30, 2012 9:40 PM
Subject: Re:Re: [R] How to multiple the vector and variables from dataframe
Hi,arun:
Yes,your answer is what I want.
A little different is :
data.frame(t(t(dat)*z))
Becau
HI Meng,
Just try:
rep(z,rach=nrow(dat))
#[1] 0.1 10.0 100.0
rep(z,chair=nrow(dat))
#[1] 0.1 10.0 100.0
rep(z,times=nrow(dat))
#[1] 0.1 10.0 100.0 0.1 10.0 100.0 0.1 10.0 100.0
rep(z,each=nrow(dat))
#[1] 0.1 0.1 0.1 10.0 10.0 10.0 100.0 100.0 100.0
rep(z,nrow(dat))
#[1]
I can't say whether nlme or
lme4 is better in this case. You could fit the model with several other
variables and select the best model based on different criteria.
Happy New Year!
A.K.
From: Usha Gurunathan
To: arun
Sent: Sunday, December 30, 2012
Hi,
Try this:
x<-c(11.00,11.25,11.35,12.01,11.14,13.00,13.25,13.35,14.01,13.14,14.50,14.75,14.85,15.51,14.64)
x[substr(x,4,5)>=60]<-(x[substr(x,4,5)>=60]-.60)+1
res<-sort(as.POSIXct(paste("2012-12-31", sprintf("%.2f",x),sep="
"),format="%Y-%m-%d %H.%M")) #
ifelse(format(res,"%H:%M")>=12, paste(
HI,
Just by taking David's solution:
y <- as.POSIXct(paste( floor(x), round(60*(x-floor(x))) ), format="%H %M")
y1<-data.frame(y,AM_PM=format(y,format="%p"))
y1[3,1]-y1[4,1]
#Time difference of -40 mins
y1[5,1]-y1[3,1]
#Time difference of -13 mins
head(y1,2)
# y AM_PM
#1 20
HI,
May be this helps:
set.seed(5)
dat1<-as.data.frame(matrix(sample(1:100,100,replace=TRUE),ncol=20))
dat1[,8:ncol(dat1)]
A.K.
- Original Message -
From: eliza botto
To: "r-help@r-project.org"
Cc:
Sent: Wednesday, January 2, 2013 8:59 AM
Subject: [R] column selection
Dear R users
HI,
Try this:
which(mata==4,arr.ind=TRUE)
# row col
#[1,] 1 2
which(matb==4,arr.ind=TRUE)
# row col
#[1,] 3 1
A.K.
- Original Message -
From: Charles Novaes de Santana
To: r-help@r-project.org
Cc:
Sent: Wednesday, January 2, 2013 6:12 AM
Subject: [R] In which column a
HI,
Assuming the structure is similar to this:
set.seed(15)
list1<-lapply(c(60,120),function(i)
as.data.frame(matrix(sample(1:100,240,replace=TRUE),nrow=i))) # with 2 list
elements
lapply(list1,function(x) x[-c(32,64,96,128,160,192),])
A.K.
- Original Message -
From: eliza botto
To
Hi,
Check this link
http://tolstoy.newcastle.edu.au/R/help/05/04/1765.html
set.seed(15)
list1<-lapply(1:3,function(i) matrix(sample(1:10,6,replace=TRUE),ncol=i) )
lapply(list1,function(x) colMeans(x,na.rm=TRUE))
[[1]]
#[1] 6.67
#[[2]]
#[1] 6.33 6.00
##
#[[3]]
#[1] 7.0 9.0 7.5
A.K.
88 12529.8313
#[7] 13965.5763 9270.4147 4352.4091 2082.5329 1441.8123 1158.6669
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
Sent: Wednesday, January 2, 2013 5:41 PM
Subject: RE: [R] list of matrices
dear arun,
can u please try your c
HI Eliza,
I looked into your data.
It's not a list of matrices, but a "list of data.frames" and as suspected, some
of the columns were "chr" instead of "num".
str(d) #only selected list elements which showed the anomaly
$ :'data.frame': 1998 obs. of 13 variables:
..$ Col0 : num [1:1998] 1 2
Hi,
You could also try:
set.seed(51)
mat1<-matrix(sample(1:5000,1116*12,replace=TRUE),nrow=1116)
dim(mat1)
#[1] 1116 12
res1<-lapply(split(as.data.frame(mat1),rep(1:36,each=31)),as.matrix)
unlist(lapply(res1,nrow))
# 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Hi,
YOu could use ?count() from library(plyr) or ?table() or ?sum()
count(test)[,2][count(test)[,1]==0]
#[1] 6
table(test)["0"]
#0
#6
A.K.
- Original Message -
From: Hermann Norpois
To: r-help@r-project.org
Cc:
Sent: Thursday, January 3, 2013 5:49 PM
Subject: [R] count appearence o
wouldn't it end up with less number of rows than 372.
> Same applies for the last matrix in all the list elements.
> Arun
>
>
>
>
>
>
>
>
> From: eliza botto
> To: "smartpink...@yahoo.com"
> S
Hi,
You could try this:
dat1<-read.table(text="
id,age,weight,height,gender
1,22,180,72,m
2,13,100,67,f
3,5,40,40,f
4,6,42,,f
5,12,98,66,
6,50,255,60,m
",sep=",",header=TRUE,stringsAsFactors=FALSE,na.strings="")
list1<-by(dat1[c("weight","height")],dat1[c("age","gender")],colMeans,na.rm=TR
As long as there are no negative numbers, method2 and 3 works:
test[1]<- -1
length(which(test==0))
#[1] 6
length(which(test<1))
#[1] 7
length(which(test < .Machine$double.xmin))
#[1] 7
length(which(abs(test)<1))
#[1] 6
length(which(abs(test) < .Machine$double.xmin))
#[1] 6
A.K.
- Orig
889
str(dat2)
#An ‘xts’ object from 2003-01-03 to 2003-01-09 containing:
# Data: int [1:7, 1] 20235 25655 225860 289658 243889 244338 243889
# Indexed by objects of class: [Date] TZ:
# xts Attributes:
#List of 2
# $ tclass: chr "Date"
#$ tzone : chr ""
plot(dat2)
A.K.
___
98 2503433 2254394 1218622 2913082
337881 ...
A.K.
- Original Message -
From: Fares Said
To: arun
Cc:
Sent: Friday, January 4, 2013 1:38 PM
Subject: Re: Can you help me please
Sorry Arun,
I don't have any columns I need to generate them both with certain criteria.
First c
ek(dat1[,1])
Week1<-gsub(".*\\-(.*)\\-.*","\\1",Week)
head(Week1)
#[1] "W01" "W01" "W01" "W01" "W01" "W02"
A.K.
From: Fares Said
To: arun
Sent: Friday, January 4, 2013 2:10 PM
Sub
Hi,
You could also use ?dcast()
occ.data1<-occ.data[,-c(2:3)]
library(reshape2)
res1<-dcast(occ.data1,year+Site+specie+Pres~Rep,value.var="Rep")
names(res1)[grep("[0-9]",names(res1))]<-paste("Rep",1:5,sep="")
res1[,-c(1:4)]<-sapply(res1[,-c(1:4)],function(x) as.integer(is.na(x)))
res1
# year Sit
Hi,
For the second part of your question, use ?merge() or ?join() from library(plyr)
dat1<-read.table(text="
2011-02-01 15.29130
2011-02-08 17.60278
2011-02-15 17.99737
2011-02-22 25.43690
",sep="",header=FALSE,stringsAsFactors=FALSE)
dat2<-read.table(text="
2011-02-01 342.34
2011-02-02 68.45
20
HI,
May be this helps:
occ.data1<-occ.data[,-c(2:3)]
res<-reshape(occ.data1,direction="wide",idvar=c("specie","Site","Pres","year"),timevar="Rep",v.names="Rep")
res<-res[,c(1:4,7:8,5:6,9)]
res[grep("Rep",names(res))]<-apply(res[grep("Rep",names(res))],2, function(x)
ifelse(is.na(x),0,1))
nam
Hi,
One more way:
dat1<-read.table(text="
ID V1 V2 V3 V4
1 6 5 3 2
2 3 2 2 1
3 6 5 3 2
4 12 15 3 2
5 6 8 3 2
6 3 2 4 1
7 6 5 3 3
8 12 15 3 1
9 6 5 3 3
10 3 2 7 5
11 6 5
HI,
May be this helps:
dat1<-read.table(text="
ID V1 V2 V3 V4
1 6 5 3 2
2 3 2 2 1
3 6 5 3 2
4 12 15 3 2
5 6 8 3 2
6 3 2 4 1
7 6 5 3 3
8 12 15 3 1
9 6 5 3 3
10 3 2 7 5
HI,
You could try this:
Time1<-as.POSIXct("2013-01-01 00:00:00")
tseq<-seq(Time1,length.out=50,by="secs")
dat2<-data.frame(TIME=tseq,Data1=NA,Data2=NA,Data3=NA)
dat3<-read.table(text="
ID Date TIME Data1 Data2 Data3
1 2013-01-01 00:00:00 34
date1 donation Holiday
#180 2003-06-29 358
#181 2003-06-30 2895407
#182 2003-07-01 1619049 CACanadaDAy
#183 2003-07-02 1391688
#184 2003-07-03 422074
#185 2003-07-04 1481923
A.K.
From: Far
Hi,
Just to add:
As you have more columns of data, it would be better to do in this way:
Time1<-as.POSIXct("2013-01-01 00:00:00")
tseq<-seq(Time1,length.out=50,by="secs")
dat2<-data.frame(TIME=tseq,matrix(NA,nrow=50,ncol=3)) #change nrow and ncol
names(dat2)[-1]<-paste("Data",1:3,sep="")
dat
HI,
Sorry, there was a mistake, which I noticed after seeing David's post.
dat1<-read.table(text="
ID V1 V2 V3 V4
1 6 5 3 2
2 3 2 2 1
3 6 5 3 2
4 12 15 3 2
5 6 8 3 2
6 3 2 4 1
7 6 5 3 3
8 12 15 3 1
9 6
1 & overweight=1 as obese itself.
Can you tell me if I can use the geese or geeglm function with this data
eg: : HIBP~ time* Age
Here age is a factor with 3 levels, time: 2 levels, HIBP = yes/no.
It says geese/geeglm: contrast can be applied only with factor with 2 or
more levels. What is the way
Hi,
You didn't provide any example data. So, I am not sure whether this helps.
set.seed(15)
dat1<-data.frame(A=sample(10:20,5,replace=TRUE),B=sample(18:28,5,replace=TRUE),C=sample(25:35,5,replace=TRUE),D=sample(20:30,5,replace=TRUE))
dat2<-dat1[,-1] # I forgot to paste this line
res<-lapply(la
\121%",row.names(res1)[grep("mean of
y",row.names(res1))])
res1
# mean p.value
#EW.INCU.13% 22.3 0.2754842
#EW.INCU.21% 29.3 0.2754842
#EW.17.5.13% 20.5 0.4705772
#EW.17.5.21% 16.0 0.4705772
#EMW.13% 23.9 0.9638679
#EMW.21% 24.2 0.9638679
A.K.
- Original Message ---
Hi,
Try this:
dat1<-read.table(text="1 2012-07-01 00:57:54 +0900 156
2 2012-07-01 01:07:41 +0900 587
3 2012-07-01 01:09:31 +0900 110
4 2012-07-01 01:18:42 +0900 551
5 2012-07-01 01:39:01 +0900 1219
6 2012-07-01 01:40:40 +0900 99",sep="",header=FALSE,stringsAsFactors=FALSE)
dat2
7.68000 0.09355374
#EW.17.5.13% 42.87000 0.17464018
#EW.17.5.21% 45.97333 0.17464018
#EW.INCU.13% 49.61333 0.43689727
#EW.INCU.21% 47.08333 0.43689727
A.K.
- Original Message -----
From: Yao He
To: arun
Cc: R help
Sent: Monday, January 7, 2013 4:00 AM
Subject: Re: [R] how to aggregate T-test
401 - 500 of 3327 matches
Mail list logo