Hi,
Try:
sweep(Mat,1,Vec,"/")
# [,1] [,2] [,3]
#[1,] 0.200 1 1.80
#[2,] 0.333 1 1.67
#[3,] 0.4285714 1 1.571429
#[4,] 0.500 1 1.50
do.call(rbind,lapply(seq_len(nrow(Mat)),function(i) Mat[i,]/Vec[i]))
# [,1] [,2] [,3]
#[1,] 0.200
res2
# patient_id responsed_at t
#1 1 2010-5 0
#2 1 2010-7 2
#3 1 2010-8 3
#4 1 2010-9 4
#5 2 2010-5 0
#6 2 2010-6 1
#7 2 2010-7 2
identical(res,res2)
#[1] TRUE
A.K.
___
10-1 0
#12 3 2010-2 1
#13 3 2010-4 3
#14 3 2010-5 4
#15 4 2011-01 0
#16 4 2011-03 2
#17 5 2012-04 0
#18 5 2012-06 2
A.K.
____
From: GUANGUAN LUO
To: arun
Sent: Wedne
6 4 2011-03 2
#17 5 2012-04 0
#18 5 2012-06 2
A.K.
From: GUANGUAN LUO
To: arun
Sent: Wednesday, April 17, 2013 9:25 AM
Subject: Re: how to change the date into an interval of date?
mutate(evt_c.11,t=ave(as.numeric
Hi,
Try:
set.seed(25)
g<- list(sample(1:40,20,replace=TRUE),sample(40:60,20,replace=TRUE))
names(g)<- c("2009-10-07","2012-02-29")
pdf("Trialnew.pdf")
lapply(seq_along(g),function(i) plot(g[[i]],main=names(g)[i]))
dev.off()
A.K.
- Original Message -
From: Ivan Alves
To: "R-help@r-proj
Hi.
No problem.
cc:ing to Rhelp.
A.K.
From: GUANGUAN LUO
Sent: Wednesday, April 17, 2013 10:25 AM
Subject: Re: how to change the date into an interval of date?
Thank you so much . That is exactly the things i want.
GG
Hi,
>Try this:
>library(mondate)
>
ot;,"orange"),names(g),horiz=TRUE)
A.K.
From: Ivan Alves
To: Duncan Murdoch ; arun
Cc: "R-help@r-project.org"
Sent: Wednesday, April 17, 2013 11:33 AM
Subject: Re: [R] use of names() within lapply()
Dear Duncan and A.K.
Many thanks for yo
do.call(rbind,lapply(split(sim_sub,((seq_len(nrow(sim_sub))-1)%/%
5)+1),colMeans))
# V11 V12 V13 V14 V15 V16 V17 V18 V19 V20
#1 0.004 0.008 0.002 0.008 0.004 0.01 0.004 0.014 0.022 0.010
#2 0.002 0.000 0.002 0.006 0.006 0.01 0.018 0.006 0.010 0.014
#3 0.000 0.004 0.002 0.012 0.
#3 0.000 0.004 0.002 0.012 0.004 0.01 0.010 0.016 0.012 0.012
#4 0.000 0.008 0.002 0.014 0.012 0.01 0.014 0.020 0.010 0.018
A.K.
- Original Message -
From: arun
To: Keith S Weintraub
Cc: R help
Sent: Wednesday, April 17, 2013 1:04 PM
Subject: Re: [R] Best way to calculate averages of
0.7169663 0.1328287 0.2467554
A.K.
From: Janesh Devkota
To: Farnoosh
Cc: arun ; R help
Sent: Wednesday, April 17, 2013 1:05 PM
Subject: Re: [R] Merge
Hi, I have a quick question here. Lets say he has three data frames and he
needs to combine those three data frame using merge. Can w
No, you don't have to use four dots.
Please check these links for further details:
http://stackoverflow.com/questions/5890576/usage-of-three-dots-or-dot-dot-dot-in-functions
http://cran.r-project.org/doc/manuals/R-lang.pdf
A.K.
From: Janesh Devkota
To:
tapply(t(data.matrix(sim_sub)),rep( rep(1:4, each=5), each=10),mean)
# 1 2 3 4
#0.0086 0.0074 0.0082 0.0108
unlist(lapply(split(sim_sub,((seq_len(nrow(sim_sub))-1)%/%5)+1),function(x)
mean(unlist(x
# 1 2 3 4
#0.0086 0.0074 0.0082 0.0108
A.K.
Hi,
You could also use:
x <-
"73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557"
sapply(strsplit(substring(x,seq(1,nchar(x)-4,5),seq(5,nchar(x),5
Hi Janesh,
This is a bit shorter:
library(seqinr)
sapply(split(as.numeric(s2c(x)),((seq(nchar(x))-1)%/%5)+1),prod)
A.K.
- Original Message -
From: arun
To: Janesh Devkota
Cc: R help
Sent: Thursday, April 18, 2013 8:55 AM
Subject: Re: [R] Subsetting a large number into smaller
Hi,
Try:
vec1<-c(1,1,1,1,1,1,1,1,1)
if(all(vec1==1)) "x" else "yyy"
#[1] "x"
vec2<-c(rep(1,4),2)
if(all(vec2==1)) "x" else "yyy"
#[1] "yyy"
#or
if(length(unique(vec1))==1) "x" else "yyy"
#[1] "x"
if(length(unique(vec2)
Hi,
You didnt provide an example dataset:
set.seed(25)
mycd<-
data.frame(a_vol3=sample(1:20,20,replace=TRUE),a_vol4=sample(5:45,20,replace=TRUE),week=rep(1:4,each=5))
aggregate(a_vol3 ~ week , data = mycd, mean)
aggregate(a_vol4 ~ week , data = mycd, mean)
#The above two could be combined to:
gt;I want...if the vector has all values equal (but probably I don't know which
>number is...
>
>Thank you very much
- Original Message -
From: arun
To: R help
Cc:
Sent: Thursday, April 18, 2013 10:08 AM
Subject: Re: vectors with equal values
Hi,
Try:
vec1<-c(1,1,1
Hi,
May be this helps (Assuming that there are only '0's and '1's in the dataset)
dat1<-read.table(text="
ID X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15
1 5184 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 0
2 6884 0 0 1 0
Hi,
Try:
vec1<-
"mue#d/sjbijk@ruepvnvbnceiicrpgxkgcyl@keduhqvqi/ubudvxopddpfddgitrynzshzdcwgneyffrkpbxwilwqngrsals#geqmtkcpkp/qecgdfa#uag"
library(seqinr)
res<-lapply(0:4,function(i) lapply(2:5,function(j)
splitseq(s2c(gsub("[#@/]","",vec1)),word=j,frame=i)))
#or
library(stringr)
res1<-lapply
vec1<- c(0,1,1,1,2,2,2,3,3)
length(unique(vec1[vec1!=0]))
#[1] 3
vec2<- c(0,2,2,3)
length(unique(vec2[vec2!=0]))
#[1] 2
A.K.
>Hi. I have a new question.
>I need count the different numbers in a vector,but different of zero.
>I mean,if I have c(0,2,2,3) the result is 2. If the
>vector is c(
Hi,
Try:
par(mfrow=c(3, 2))
mapply(hist,as.data.frame(a),main=colnames(a),xlab="x")
A.K.
- Original Message -
From: C W
To: r-help
Cc:
Sent: Thursday, April 18, 2013 6:30 PM
Subject: [R] How to keep plot title same as column name using apply/sapply?
Dear list,
I am trying to plot h
#or
par(mfrow=c(3,2))
sapply(seq_len(ncol(a)),function(i) hist(a[,i],main=colnames(a)[i],xlab="x"))
A.K.
- Original Message -----
From: arun
To: C W
Cc: R help
Sent: Thursday, April 18, 2013 6:49 PM
Subject: Re: [R] How to keep plot title same as column name using apply/s
Hi,
Try this:
Assuming that "table" is "data.frame"
dat1<-read.table(text="
Gender Age Rate
Female 0-10 Good
Male 0-10 Good
Female 11-20 Bad
Male 11-20 Bad
Male >20 N/A
",sep="",header=TRUE,stringsAsFactors=FALSE,na.strings="N/A")
lapply(seq_len(ncol(dat1)),fun
ame "dots[[1L]][[49L]]" "dots[[1L]][[50L]]"
equidist TRUE TRUE
#it is going through every single observation rather than by columns.
A.K.
- Original Message -
From: C W
To: arun
Cc: R help
Sent: Thursday, April 18, 2013 7:
ot;:","
"))," ",2)),stringsAsFactors=FALSE),X2=as.numeric(X2))
res1
# Categ X1 X2
#1 Gender Female 2
#2 Gender Male 3
#3 Age 0-10 2
#4 Age 11-20 2
#5 Age >20 1
#6 Rate Bad 2
#7 Rate Good 2
#8 Rate N/A 1
A.K.
- Origina
Hi,
I am not sure I understand your question correctly.
set.seed(25)
mydata<-
data.frame(vol3=sample(1:20,20,replace=TRUE),vol4=sample(5:45,20,replace=TRUE),vol15=sample(25:50,20,replace=TRUE),vol20=sample(30:60,20,replace=TRUE),week=rep(1:4,each=5))
funct<- function(target,data=NULL){
target<- e
Hi,
May be
library(Biostrings) from Bioconductor helps you.
source("http://bioconductor.org/biocLite.R";) biocLite("Biostrings")
?matchPattern()
?letterFrequency()
vec1<- "ababbbassdaa"
alphabetFrequency(DNAString(vec1))
#A C G T M R W S Y K V H D B N - +
#5 0 0 0 0 0 0 2 0 0 0 0 1 4 0 0 0
l
w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
# $ : num 5 5 5 5 5 5 5 5 4 5 ...
# $ : num 4 3 3 3 4 4 3 3 3 3 ...
# - attr(*, "label")= chr "Some df label"
A.K.
- Original Message -
From: Liviu Andronic
To: arun
Cc: R help
male 1 NA NA
#2 Male 1 NA NA
#3 0 0 0
#4 11-20 NA 2 NA
#5 Bad NA NA 2
#$C
# Var1 Gender Age Rate
#1 Male 1 NA NA
#2 0 0 1
#3 >20 NA 1 NA
A.K.
From: Ye Lin
To: arun
Cc: R help
$Rate
# Var1 Rate A B C
#1 Bad 2 0 2 0
#2 Good 2 2 0 0
#3 1 0 0 1
A.K.
From: Ye Lin
To: arun
Sent: Friday, April 19, 2013 1:44 PM
Subject: Re: [R] count each answer category in each column
Yes, but I am wondering if I can calculate how many ki
#or
ddply(jd1,.(fid,year),numcolwise(sum,na.rm=TRUE))
# fid year rice wheat maize
#1 1 1995 5 3 2
#2 1 1996 4 2 6
#3 2 1995 3 8 4
#4 2 1996 7 6 7
A.K.
- Original Message -
From: Janesh Devkota
To: shyam basnet
Cc: "r-help@R-project.
Hi Janesh,
There is a difference in output between these :
ddply(jd1,.(fid,year),colSums,na.rm=T) #especially the first two columns
# fid year rice wheat maize
#1 3 5985 5 3 2
#2 3 5988 4 2 6
#3 6 5985 3 8 4
#4 6 5988 7 6 7
ddply(jd1,.(fid,yea
colnames(x1)[2];x3[,c(1,7,2:6)]})
names(lst2)<- colnames(dat1)[-1]
identical(lst1,lst2)
#[1] TRUE
A.K.
From: Ye Lin
To: arun
Sent: Friday, April 19, 2013 5:49 PM
Subject: Re: [R] count each answer category in each column
Hey A.K
I modified the scripts
-
From: arun
To: Janesh Devkota
Cc: R help ; shyam basnet ; Rui
Barradas
Sent: Friday, April 19, 2013 6:25 PM
Subject: Re: [R] how to subtotal by rows
Hi Janesh,
There is a difference in output between these :
ddply(jd1,.(fid,year),colSums,na.rm=T) #especially the first two columns
# fid
0.57385268
#14 F 0.59750664
#15 G -0.01775669
#17 F 0.11683731
#18 H -1.11311883
#20 H 0.46184261
A.K.
From: farnoosh sheikhi
To: "smartpink...@yahoo.com"
Sent: Sunday, April 21, 2013 2:45 AM
Subject: Excluding observations
Hi Arun,
I h
10 3.846154
From: Bruce Miller
To: arun
Sent: Sunday, April 21, 2013 4:19 PM
Subject: Re: [R] Reshape or Plyr?
Hi Arun,
This looks good; however the not quite correct yet.
Looks like the mutate option may be a good place to start.
Sorry I did not clearly exp
HI,
dat1<- structure(list(Location_name = c("079-f2p1-Acetuna", "079-f2p1-Acetuna",
"079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna",
"079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-Acetuna",
"079-f2p1-Acetuna", "079-f2p1-Acetuna", "079-f2p1-A
4 1.6460905
#13 Rhotum 079-f2p1-Acetuna 36.4 30 8.2417582
#14 Sacbil 079-f2p1-Acetuna 36.4 11 3.0219780
#15 Saclep 079-f2p1-Acetuna 36.4 32 8.7912088
write.csv(res,file="BruceFile.csv",row.names=FALSE)
A.K.
- Original Message -
From: Bruce Miller
46.4 Myoele 1 0.2155172
dim(Final)
#[1] 44 5
A.K.
- Original Message -
From: Bruce Miller
To: arun
Cc:
Sent: Monday, April 22, 2013 11:32 AM
Subject: Re: More
Arun,
Attached are two Excel sheets that I manually did what I am hoping I can
automate in R for the larg
iginal Message -----
From: Bruce Miller
To: arun
Cc:
Sent: Monday, April 22, 2013 12:55 PM
Subject: Re: More
Hi Arun,
My last message overlapped yours.
YES...
that seems correct.
Now if I can get this to work with teh entire data set all is be great.
Thanks again for your valuable time and help
Hi,
May be this helps:
vec<- "this is a nice text with nice characters"
library(stringr)
vec2<-unlist(str_match_all(vec,"\\w+"))
#or
# vec2<-str_split(vec," ")[[1]]
res<-unique(lapply(vec2,function(x) which(!is.na(match(vec2,x)
names(res)<- unique(vec2)
res
#$this
#[1] 1
#
#$is
#[1] 2
#
#$
HI,
Could you provide an example dataset?
set.seed(15)
agoa<- data.frame(X.1=rep(c("AGOA","GSP","CST"),3),X1996=
sample(1:2,9,replace=TRUE),X2000=sample(40:3,9,replace=TRUE))
str(agoa)
#'data.frame': 9 obs. of 3 variables:
# $ X.1 : Factor w/ 3 levels "AGOA","CST","GSP": 1 3 2 1 3 2
uot;,..: 1 1 1
# $ X1996: int 12043 13019 16304
# $ X2000: int 24950 15292 25260
#To drop the levels:
agoaSub[]<- lapply(agoaSub,function(x) x[drop=TRUE])
str(agoaSub)
#'data.frame': 3 obs. of 3 variables:
# $ X.1 : Factor w/ 1 level "AGOA ": 1 1 1
# $ X1996: int 12043 13019 1
Hi,
May be this helps:
set.seed(25)
dat1<-
data.frame(ID=c("1001#01","1001#02","1001#03","1002#01","1002#02"),val=rnorm(5),stringsAsFactors=FALSE)
dat1$ID<-as.numeric(gsub("#.*","",dat1$ID))
dat1
# ID val
#1 1001 -0.2118336
#2 1001 -1.0415911
#3 1001 -1.1533076
#4 1002 0.3215315
#5 10
licated case (maybe simple to most of you :) )?
>
>10011001, 10011004, 20012001, 40012034, etc.,
>
>I would like to only keep the last 4 digits of each number.
>
>How should I do it?
>
>Thanks,
>
>York
>
>- Original Message -
>From: arun
>To: R help
Hi,
It is not that clear.
If VAR1 is a match between columns AB001A, AB0002A, VAR2 between AB001A, AB362
and VAR3 between AB0002A and AB362:
Also, I assume row8 match would be taken as 1.
dat1<- read.table(text="
S.No AB001A AB0002A AB362
1 -/- C/C A/A
1 1 1 3 100 7
#4 4 C/C C/C A/A 1 1 1 3 100 7
#5 5 C/C C/C A/A 1 1 1 3 100 7
#6 6 C/C C/C A/A 1 1 1 3 100 7
A.K.
>Hi Arun,
>Thank you very much for
K=rank(MATCH,ties.method="min");SUM[1:2]<-NA;AB001A_1[1:2]<-NA;AB0002A_1[1:2]<-NA;AB362_1[1:2]<-NA})
identical(res,res1)
#[1] TRUE
A.K.
- Original Message -
From: arun
To: R help
Cc:
Sent: Wednesday, April 24, 2013 10:09 AM
Subject: Re: matching observations a
HI
Not sure whether this helps:
ipso<- read.table(text="
id dbh h g
1 FPE0164 36 13.62 0.10178760
2 FPE0164 31 12.70 0.07547676
21 FPE1127 57 18.85 0.25517586
13 FPE1127 39 15.54 0.11945906
12 FPE1127 34 14.78 0.09079203
6 FPE1127 32 15.12 0.08042477
5 FPE1127 28 14.13 0.
HI,
Your code is not very clear.
mata<-m[,c(u)] # assume that "m" is "mat1" or "w" (as "m" was not defined)
#also assume that "124" as nrow of each matrix
# For 10 distance matrices (#10C4)
set.seed(25)
lst1<- lapply(1:10,function(i)
dist(matrix(sample(1:50,5*124,replace=TRUE),nrow=124
HI,
set.seed(24)
#creating the four matrix in a list
lst1<-lapply(1:4,function(x) matrix(sample(1:40,20,replace=TRUE),ncol=5))
names(lst1)<- paste0("B",1:4)
vec<- c(1,2,4,3,2,3,1)
res<-do.call(rbind,lapply(vec,function(i) lst1[[i]]))
dim(res)
#[1] 28 5
#or
B1<- lst1[[1]]
B2<- lst1[[2]]
B3<- l
Hi,
May be this helps.
L<- list(c("A1","B1"),c("A2","B2"),c("A3","B3"))
simplify2array(L)[1,]
#[1] "A1" "A2" "A3"
simplify2array(L)[2,]
#[1] "B1" "B2" "B3"
#or
library(stringr)
word(sapply(L,paste,collapse=" "),1)
#[1] "A1" "A2" "A3"
A.K.
- Original Message -
From: "ted.hard...@wland
Hi,Not sure about the criteria for deciding number of zeros.
vec1<- c(23,244,1343,45,153555,546899,75)
lst1<- strsplit(as.character(vec1),"")
m1<-max(sapply(lst1,length))
res<- t(sapply(lst1,function(x) as.numeric(c(rep(0,m1-length(x)),x
res
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
44 24 14
#[5,] 45 25 15
#
#[[2]]
#[1] 7 13 15
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
Sent: Thursday, April 25, 2013 4:45 PM
Subject: RE: [R] Distance matrices Combinations
dear arun,
I will see through it thoroughly if yo
Hi,
It would be better to give an example.
If your dataset is like the one attached:
con<-file("Trial1.txt")
Lines1<- readLines(con)
close(con)
#If the data you wanted to extract is numeric and the header and footer are
characters,
dat1<-read.table(text=Lines1[-grep("[A-Za-z]",Lines1)],sep="\t",
26 30 34 38
#[19,] 23 27 31 35 39
#[20,] 24 28 32 36 40
#[21,] 41 45 49 53 57
#[22,] 42 46 50 54 58
#[23,] 43 47 51 55 59
#[24,] 44 48 52 56 60
#[25,] 1 5 9 13 17
#[26,] 2 6 10 14 18
#[27,] 3 7 11
] 32 62 72
#[3,] 33 63 73
#[4,] 34 64 74
#[5,] 35 65 75
#
#[[2]]
#[1] 9 5 3
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
Sent: Thursday, April 25, 2013 9:54 AM
Subject: connecting matrices
Dear Arun,
[text file co
A.K.
- Original Message -
From: arun
To: eliza botto
Cc: R help
Sent: Thursday, April 25, 2013 10:09 AM
Subject: Re: connecting matrices
Dear Elisa,
Try this:
el<- matrix(1:100,ncol=20)
set.seed(25)
el1<- matrix(sample(1:100,20,replace=TRUE),ncol=1)
In the example you show
Hi,
labs <- format(as.Date(time(rr)), "%b-%Y")
#Error in as.Date.default(time(rr)) :
# do not know how to convert 'time(rr)' to class “Date”
#I guess this needs library(zoo)
library(zoo)
labs <- format(as.Date(time(rr)), "%b-%Y")
sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-
Hi,
You can do this:
lst1<-lapply(split(colnames(df)[-1],gsub("_.*","",colnames(df)[-1])),function(x)
{x1<-cbind(date=df[,1],df[,x]);colnames(x1)[-1]<- x;x1})
lst1
#$ABC
# date ABC_f ABC_e ABC_d ABC_m
#1 2013-04-15 62.80740 11.36784 38.71090 40.28474
#2 2013-04-14 81.04526 6
525
#5 2013-04-11 25.81805
#
#$XYZ
# date XYZ_p XYZ_zz
#1 2013-04-15 55.88855 85.74755
#2 2013-04-14 94.13587 63.48582
#3 2013-04-13 84.00891 81.61107
#4 2013-04-12 98.99747 58.15729
#5 2013-04-11 64.71084 27.44133
A.K.
- Original Message -
From: arun
To: Katherine Gobin
Hi,
The format is bit messed up.
So, not sure this is what you wanted.
x1<- read.table(text="State_prov,Shape_name,bob2009,bob2010,bob2011
Nova Scotia,Annapolis,0,0,1
Nova Scotia,Antigonish,0,0,0
Nova Scotia,Gly,NA,NA,NA
",sep=",",header=TRUE,stringsAsFactors=FALSE)
x2<- read.table(text="
FID,S
time.m<- as.matrix(read.table(text='
"08:00:20.799" "08:00:20.799" "08:00:20.799" "08:00:20.799" "08:00:20.799"
"08:00:21.996" "08:00:22.071" "08:00:23.821" "08:00:24.370" "08:00:25.573"
"08:00:29.200" "08:00:29.200" "08:00:29.591" "08:00:30.368" "08:00:30.536"
"08:00:31.073" "08:00:31.372" "08:0
0 0 1 1
#3 Nova Scotia Gly 0 0 NA 2 1
A.K.
From: Catarina Ferreira
To: arun
Sent: Friday, April 26, 2013 2:23 PM
Subject: Re: [R] Help with merge function
Hello,
I didn't realize that the format had been ch
fill=TRUE)
dim(x2)
#[1] 34577 189
library(plyr)
res<- join(x1,x2,type="right")
#Joining by: State_Prov, Shape_name, bob2009, bob2010, red2009, red2010,
coy2009, coy2010, lyn2009, lyn2010
dim(res)
#[1] 34577 193
res2<- merge(x1,x2,all.y=TRUE)
dim(res2)
#[1] 34577 193
A
HI,
"Find 'T','C','A','F' and 'Y', delete them from all the 110 files"
I assume that you meant to replace it with NA.
set.seed(28)
myfiles<- lapply(1:5,function(i)
as.data.frame(matrix(sample(c(LETTERS,"-999.99M"),40*i,replace=TRUE),ncol=(40*i)/8),stringsAsFactors=FALSE))
myfiles[[1]]
# V1 V2
t;S" "R" "Q" "W" "N" "I"
#
#$V3
#[1] "K" "S" NA "M" "G" "G" "Z"
#
#$V4
#[1] "O" "M" "G" "G" "B" "X" "M&quo
NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
# V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33
#1 NA NA NA NA NA NA NA NA NA NA NA NA
#2 NA NA NA NA NA NA NA NA NA NA NA NA
A.K.
From: Zilefac Elvis
To: arun
Sent: Saturday, April 27, 2013 11:14 PM
Subjec
paste0(gsub(".txt","",temp[i]),"_new",".txt"),row.names=FALSE,quote=FALSE))
#or write as .csv.
lapply(seq_along(res),function(i)
write.csv(res[[i]],gsub(".txt",".csv",temp[i]),row.names=FALSE,quote=FALSE)
A.K.
HI,
library(MBESS)
Cor.mat <- matrix(c(1,0.5,0.5,1),nrow=2)
Sd<- c(0.07,0.05)
Covmat<-cor2cov(Cor.mat,Sd)
Covmat
# [,1] [,2]
#[1,] 0.00490 0.00175
#[2,] 0.00175 0.00250
cov2cor(Covmat)
# [,1] [,2]
#[1,] 1.0 0.5
#[2,] 0.5 1.0
Cor.mat2<-matrix(c(1,0.2,0.8,0.2,1,0.6,0.8,0.6,1
Hi, res<- unlist(mget(ls()))
names(res)<-NULL
res
#[1] 5 5 10
A.K.
- Original Message -
From: Rui Esteves
To: r-help@r-project.org
Cc:
Sent: Monday, April 29, 2013 7:07 AM
Subject: [R] How to "call" an object given a string?
Hello,
This is very basic and very frustrating.
Suppose
Hi Katherine,
res1<-aggregate(cbind(cashflow,cashflows_pv)~instrument+id,data=cashflow_df,sum)
res2<-res1[order(res1$instrument),]
res2$cashflow_change<-with(res2,ave(cashflows_pv,instrument,FUN=function(x)
x-head(x,1)))
names(res2)[3:4]<- paste0("total_",names(res2)[3:4])
res2
# instrument i
0
#14 UVWXYZ 4 816000 683854.37 -5407.4959
#15 UVWXYZ 5 816000 683959.75 -5302.1153
A.K.
- Original Message -
From: arun
To: Katherine Gobin
Cc: R help
Sent: Monday, April 29, 2013 9:43 AM
Subject: Re: [R] Adding elements in data.f
r
# [,1] [,2] [,3]
#a 1 5 9
#e 3 7 11
#b 4 8 12
#c NA NA NA
I guess you meant:
r1<- Mat[match(Subscript_Vec,rownames(Mat)),]
rownames(r1)<- Subscript_Vec
r1
# [,1] [,2] [,3]
#a 1 5 9
#e NA NA NA
#b 2 6 10
#c 3 7 11
A.K.
- Or
Hi,
If it is for the list:
lst1<- list(x,x,x)
lst1<-lapply(lst1,myfunc)
- Original Message -
From: arun
To: "Sparks, John James"
Cc: R help
Sent: Monday, April 29, 2013 12:13 PM
Subject: Re: [R] Function for Data Frame
Hi,
If I understand it correctly,
x<-myfu
Hi,
dat1<- read.table(text="
id t scores
2 0 1.2
2 2 2.3
2 3 3.6
2 4 5.6
2 6
Hi,
If I understand it correctly,
x<-myfunc(x)
x
# V2 V3
#1 2 3
#2 2 3
#3 2 2
#4 2 2
#5 1 1
A.K.
- Original Message -
From: "Sparks, John James"
To: r-help@r-project.org
Cc:
Sent: Monday, April 29, 2013 10:23 AM
Subject: [R] Function for Data Frame
Dear R Helpers,
I have
Hi,
Try this:
set.seed(24)
lst1<-lapply(1:4,function(x)
as.data.frame(matrix(sample(1:20,20,replace=TRUE),ncol=5)))
names(lst1)<- LETTERS[1:4]
res<-lapply(list(c("A","B"),c("C","D")), function(x) do.call(rbind,lst1[x]))
res
#[[1]]
# V1 V2 V3 V4 V5
#A.1 6 14 17 14 4
#A.2 5 19 6 14 1
#A.
Hi,
Your output dataset is bit confusing as it contains Sites that were not in the
input.
Using your input dataset, I am getting this:
dat1<- read.table(text="
Species Site Date
a 1 1
b 1 1
b 1 2
c 1 3
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat1$Present<- 1
dat2<-expand.grid(unique(dat1$S
1
#3 c 1 1 0
#4 a 1 2 0
#5 b 1 2 1
#6 c 1 2 0
#7 a 1 3 0
#8 b 1 3 0
#9 c 1 3 1
A.K.
From: Matthew Venesky
To: arun
Sent: Monday,
lmi 3641 3/23/2001 1 1
#14 Pseudacris kalmi 3641 4/27/2001 0 0
A.K.
From: Matthew Venesky
To: arun
Sent: Monday, April 29, 2013 3:54 PM
Subject: Re: [R] expanding a presence only dataset into presence/absence
Arun,
Hi,
May be this helps:
cat(paste(strsplit("abcd","")[[1]],collapse="\n"))
#a
#b
#c
#d
A.K.
- Original Message -
From: jpm miao
To: r-help
Cc:
Sent: Monday, April 29, 2013 9:41 PM
Subject: [R] Is there a function that print a string vertically (by adding
"\n")?
Hi,
I'd li
Hi,
May be this helps:
funcName<- function(df1, x){
whatCol=df1[[x]]
print("Got it")
print(whatCol)
}
funcName(df,"ColA")
#[1] "Got it"
#[1] 1 2 3 4 5
funcName(df,"ColB")
#[1] "Got it"
#[1] A B C D E
#Levels: A B C D E
A.K.
>I am trying to extract the 2nd column from a dataframe using a
1.5
#12 3 4 1.5 1.9 1.6
A.K.
____
From: GUANGUAN LUO
To: arun
Sent: Tuesday, April 30, 2013 9:17 AM
Subject: Re: how to add new rows in a dataframe?
I would replace the rows but not only the variable "scores". In reality , i
have 1
y = c("1", "2", '"', "a", "b", '"', "3", "4")
y
#[1] "1" "2" "\"" "a" "b" "\"" "3" "4"
A.K.
- Original Message -
From: Jie
To: "r-help@r-project.org"
Cc:
Sent: Tuesday, April 30, 2013 2:46 PM
Subject: [R] Quote as element of a vector/list
Dear All,
I would like to store
0 0 0 0 0 0 0 0 0 0
A.K.
From: Thu Pham
To: arun
Sent: Tuesday, April 30, 2013 3:13 PM
Subject: Re: select and do some calculations/manipulations on certain rows
based on conditions in R
Hi,
The column for y would be
y
0
1
0
0
1
0
0
On
Hi,
You could also do:
v<- read.table(text="
Name Year_1_value Year_2_value Year_3_value
A 1 2 3
B 2 7 19
C 3 4 2
D 10 7 6
E 4 4 5
F NA 3 6
",sep="",header=TRUE,stringsAsFactors=FALSE)
names(v)[-1]<-gsub("(.*\\d+)_.*$","\\1",names(v)[-1])
v2<- v
v1<-reshape(v,direction="long",varying=2:4,sep="_")
HI,
You could also do:
vec1<- c("Intensity","Intensity L", "Intensity H", "Intensity Rep1")
identical(setdiff(seq_along(vec1),grep("H|L",vec1)),as.integer(c(1,4)))
#[1] TRUE
A.K.
- Original Message -
From: Johannes Graumann
To: r-h...@stat.math.ethz.ch
Cc:
Sent: Wednesday, May 1, 2013
match(interaction(choice),interaction(coord))
#[1] 2 11 12
A.K.
- Original Message -
From: Enrico R. Crema
To: r-help@r-project.org
Cc:
Sent: Wednesday, May 1, 2013 7:54 AM
Subject: [R] selecting rows based on multiple criteria
Dear List,
I am struggling with the following problem
which(!is.na(merge(coord,choice,all=TRUE)[,4]))
#[1] 2 11 12
A.K.
- Original Message -
From: arun
To: Enrico R. Crema
Cc: R help
Sent: Wednesday, May 1, 2013 9:09 AM
Subject: Re: [R] selecting rows based on multiple criteria
match(interaction(choice),interaction(coord))
#[1] 2 11
HI,
One possible way would be to use paste()
chron(times.=paste0("15:00",":00"),format=c(times="h:m:s"))
#[1] 15:00:00
#or you could use
library(lubridate)
hm("15:00")
#[1] "15H 0M 0S"
A.K.
- Original Message -
From: Stephen Sefick
To: "r-help@r-project.org"
Cc:
Sent: Wednesday, M
attached):
[1] digest_0.6.3 memoise_0.1 tools_3.0.0
From: stephen sefick
To: arun
Cc: R help
Sent: Wednesday, May 1, 2013 1:55 PM
Subject: Re: [R] Chron format question h:m not working
Thanks for the quick replies. I have this working with a similar suggestion
Hi,
You could use:
library(plyr)
for(i in letters[24:26]) assign(i,mutate(get(i),V4=V2+V3))
x
# V1 V2 V3 V4
#1 1 2 3 5
#2 1 2 3 5
#3 1 2 2 4
#4 1 2 2 4
#5 1 1 1 2
y
# V1 V2 V3 V4
#1 1 2 3 5
#2 1 2 3 5
#3 1 2 2 4
#4 1 2 2 4
#5 1 1 1 2
A.K.
>Dear R Help
subset(df,subid %in% sample(myids, size=size))
> return(sample_regular)
>}
>
>Thank You for your assistance.
>-ST
- Original Message -
From: arun
To: R help
Cc:
Sent: Tuesday, April 30, 2013 9:00 AM
Subject: Re: R Function to extract columnNames
Hi,
May be this hel
Hi,
May be this helps:
dat1<- as.data.frame(table1)
dat2<- as.data.frame(table2)
names(dat2)<-c("V3","V4")
library(plyr)
res<-join(dat1,dat2,type="full")
res[is.na(res)]<- 0
res
# V1 V2 V3 V4
#1 1 1 0 0
#2 1 2 0 0
#3 0 0 0 1
#4 0 0 0 4
combinedtable<-as.matrix(res)
colnames(
Hi,
Assuming that your dataset is similar to the one below:
set.seed(25)
dat1<-
data.frame(Algae.Mass=sample(40:50,10,replace=TRUE),Seagrass.Mass=sample(30:70,10,replace=TRUE),Terrestrial.Mass=sample(80:100,10,replace=TRUE),Other.Mass=sample(40:60,10,replace=TRUE),Site.X.Treatment=rep(c("ALA1A","A
Hi,
If you are using Rstudio, please check this link
(http://support.rstudio.org/help/discussions/problems/850-ddply-misbehaving-in-rstudio-and-only-in-rstudio).
A.K.
- Original Message -
From: arun
To: R help
Cc: David Winsemius
Sent: Wednesday, May 1, 2013 9:49 PM
Subject: Re: R
#or
library(magic)
adiag(table1,table2) #rownames are preserved
# [,1] [,2] [,3] [,4]
#row1 1 1 0 0
#row2 1 2 0 0
#row3 0 0 0 1
#row4 0 0 0 4
A.K.
- Original Message -
From: Dennis Murphy
To: David Winsemius
Cc: arun ; R help
Sent
[Column]])|x[[Column]]==0)))
>+ myids<- mysel[mysel$missing==0,1]
>+ sample_regular<- subset(df,subid%in% sample(myids,size,replace=TRUE))
>+ return(sample_regular)
>+ }
>> retsample(mydf,"Col",5)
>Error in is.list(by) : 'by' is missing
-
t(t(k)/div)
# [,1] [,2]
#[1,] 1 2.0
#[2,] 2 2.5
#[3,] 3 3.0
A.K.
- Original Message -
From: Sachinthaka Abeywardana
To: "r-help@r-project.org"
Cc:
Sent: Thursday, May 2, 2013 2:28 AM
Subject: [R] Divide matrix columns by different numbers
Hi all,
I have a feeling t
1001 - 1100 of 3305 matches
Mail list logo