HI,
#dat1: data
Combn1<-combn(colnames(dat1)[2:5],2)
#For the first part, may be this helps:
library(plyr)
res<-lapply(split(Combn1,col(Combn1)),function(x)
{x1<-cbind(Var1=colnames(dat1[,x])[1],Var2=colnames(dat1[,x])[2],dat1[,x],Method=dat1[,6]);colnames(x1)[3:4]<-
c("V1","V2"); ddply(x1,.(Met
Hi,
dat<-read.table(text="
1 0 1 1 1 1
0 0 1 0 0 1
1 0 0 0 0 0
2 1 1 2 1 1
",sep="",header=FALSE)
which(sapply(seq_len(nrow(dat)),function(i)
wilcox.test(unlist(dat[i,]))$p.value)>0.05) #there will be warnings() though
#[1] 2 3
table(sapply(seq_len(nrow(dat)),functi
Hi,
You could try:
Chisq1<-do.call(cbind,lapply(c(0.05,0.001),function(i)
{x1<-sapply(seq_len(nrow(Specc)),function(i)
chisq.test(as.table(unlist(Specc[i,-c(1:3)])))$p.value); sum(x1
To: arun
Sent: Friday, July 19, 2013 1:25 PM
Subject: Re: Kruskal.test
Thank you.
But I need to const
HI,
sum(var1,var2,var3,var4,var5,na.rm=TRUE)
#[1] 8
A.K.
- Original Message -
From: Jin Choi
To: "r-help@r-project.org"
Cc:
Sent: Saturday, July 20, 2013 12:37 AM
Subject: [R] Adding across columns ignoring NA
I am having difficulty finding a solution to devising an R code to do th
Hi,
May be this helps:
df1<- read.table(text="
t1 t2 t3 t4
len1 AA AA PP AP
len2 FALSE AA PP MM
len3 PP AA AA AP
len4 PP AM MP PP
len5 AA FALSE AP PP
len6 PP AA AA AA
",sep="",header=TRUE,stringsAsFactors=FALSE)
df1[df1[,1]=="PP" & (rowSums(df1[,-1]!="PP")==(ncol(df1)-1)),]
# t1
Hi,
set.seed(28)
dat1<- as.data.frame(matrix(sample(1:20,100,replace=TRUE),ncol=10))
set.seed(49)
dat2<- as.data.frame(matrix(sample(40:80,100,replace=TRUE),ncol=10))
lapply(seq_len(ncol(dat1)),function(i) {lm(dat2[,i]~dat1[,i])})
A.K.
- Original Message -
From: iza.ch1
To: r-help@r-pr
Hi,
You could try:
cumsum(c(1,abs(diff(as.numeric(factor(v1))
# [1] 1 1 1 2 2 3 3 3 3 4
A.K.
- Original Message -
From: Arnaud Michel
To: PIKAL Petr
Cc: R help
Sent: Monday, July 22, 2013 11:41 AM
Subject: Re: [R] Calculate interaction for a big dataframe
Thank you Petr
paste i
May be this helps:
split(XXX,cumsum(c(TRUE,diff(as.numeric(XXX$electrode))<0)))
A.K.
- Original Message -
From: "dennis1...@gmx.net"
To: r-help@r-project.org
Cc:
Sent: Monday, July 22, 2013 10:09 AM
Subject: [R] How to split two levels several times?
Hi,
I have a small problem wit
set.seed(28)
dat1<- as.data.frame(matrix(sample(1:20,100,replace=TRUE),ncol=10))
set.seed(49)
dat2<- as.data.frame(matrix(sample(40:80,100,replace=TRUE),ncol=10))
sapply(seq_len(ncol(dat1)),function(i) {x1<-
summary(lm(dat2[,i]~dat1[,i]));x1$coef[,1]})
# [,1] [,2] [
Hi,
myvector<- c(3,2,7,4,1)
names(myvector)<-paste0("name",1:5)
names(myvector)[myvector>=3 & myvector<=5]
#[1] "name1" "name4"
#or
names(myvector)[myvector%in% 3:5]
#[1] "name1" "name4"
#or
names(myvector)[!is.na(match(myvector,3:5))]
#[1] "name1" "name4"
A.K.
Hello all,
I am new to R bu
Hi,
May be this helps:
Master<-read.table(text="
SID B2A B2B B2C C2A C2B C2C C118A C118B C118C
001 0.01 0.5 -0.4 1.2 -1.8 0.3 -0.3 0.4 0.5
002 0.01 0.5 -0.4 0.5 -0.4 1.2 -1.8 0.3 -0.3
003 0.04 0.05
In that case:
Master1<- Master
Master1$zGPA<-sapply(seq_len(nrow(Master1[,-1])),function(i)
weighted.mean(Master1[i,-1],Units))
Master1$zGPA
#[1] 0.035121951 -0.003902439 0.097804878
all.equal(Master,Master1)
#[1] TRUE
A.K.
From: Robert Lynch
To
Hi,
I tried this without the changing the class, but there was no warning.
str(release_freq)
#'data.frame': 62 obs. of 4 variables:
# $ d_release: Factor w/ 31 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
# $ m_release: Factor w/ 2 levels "5","6": 1 1 1 1 1 1 1 1 1 1 ...
# $ y_release
Hi,
Try:
set.seed(25)
X<- matrix(sample(1:50,3*140,replace=TRUE),nrow=140)
#either
res1<-do.call(rbind,lapply(split(as.data.frame(X),((seq_len(nrow(X))-1)%/%10)+1),function(x)
apply(x,2,mean)))
#or
res2<-t(sapply(split(as.data.frame(X),((seq_len(nrow(X))-1)%/%10)+1),colMeans))
identical(res1,res
Hi,
It is better to provide a reproducible example using ?dput()
df1<- read.table(text="
sim X1 X2 X3 sim.1 X1.1 X2.1 X3.1
1 5 4 5 1 4 3 7
1 4 3 2 1 7 4 1
1 3 9 4 1 5
Hi Michael,
It is not clear how you read the dataset. It looks like a dataframe.
df1<- read.table(text='
"","x"
"A1",2
"A2",5
"A3",4
"A4",6
"A5",24
"A6",7
"A7",12
"A8",3
"A9",5
',sep=",",header=TRUE,row.names=1)
vec1<-unlist(df1)
names(vec1)<- row.names(df1)
names(vec1)[vec1%in% 3:
)<- 1:nrow(res)
head(res,2)
# m sim X1 X2 X3
#1 1 1 5 4 5
#2 1 1 4 3 2
A.K.
- Original Message -
From: arun
To: Andrea Lamont
Cc: R help
Sent: Tuesday, July 23, 2013 12:00 PM
Subject: Re: [R] flexible approach to subsetting data
Hi,
It is better to provide a reproducibl
If you have more columns:
names(df1)<-paste0(gsub("\\..*","",names(df1)),"_",rep(1:2,each=4)) #change
`rep` accordingly
reshape(df1,direction="long",varying=1:ncol(df1),sep="_",timevar="m")[,-6]
A.K.
- Original Message -
ec2)[vec2%in% seq(3,5,by=0.1)]
#[1] "A2" "A3" "A8" "A9"
#If I change
vec2[3]<- 4.46
names(vec2)[vec2%in% seq(3,5,by=0.1)]
#[1] "A2" "A8" "A9"
names(vec2)[round(vec2,1)%in% seq(3,5,by=0.1)]
#[1] "A2" "A3&q
Hi,
It is better to use ?dput().
a1<-array(c(0.1416,0.1049,0.1328,0.12235,0.11890,0.15510,0.14225,0.09295,0.13350,0.16875,0.09900,0.14560),c(3,2,2))
dimnames(a1)<- list(c("T0","T1","T2"),c("B6","B9"),c("minus","plus"))
library(plyr)
library(reshape2)
res<-melt(adply(a1,c(1,2)),id.vars=c("X1","X2")
Hi,
vec1<- factor(1:5,levels=1:10)
vec1
#[1] 1 2 3 4 5
#Levels: 1 2 3 4 5 6 7 8 9 10
vec2<-droplevels(vec1)
levels(vec2)
#[1] "1" "2" "3" "4" "5"
vec2
#[1] 1 2 3 4 5
#Levels: 1 2 3 4 5
A.K.
Hi all,
I am having a bit of trouble using the levels() function.
I have a factor with many element
Hi Michel,
You could try:
df1New<-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=min)),])
row.names(df1New)<-1:nrow(df1New)
df2New<-droplevels(TEST[with(TEST,ave(seq_along(Matricule),Matricule,FUN=max)),])
row.names(df2New)<-1:nrow(df2New)
identical(df1New,df1)
#[1] TRUE
ident
Hi,
Try:
dat1<- read.table(text="
ID Date x2 x1 x3
56 25-Jun-01 10 2 126
56 29-Oct-01 10 2 140
56 18-Mar-02 10 2 445
56 6-Jun-03 10 2 224
56 16-Jan-04 10 2 NA
58 10-Jan-02 10.8 1 715
58 26-Dec-03 10.8 1 NA
",sep="",header=TRUE,stringsAsFactors=FALSE)
unlist(with(da
Hi,
It works in small dataset.
rt<- structure(list(sim = c(1L, 1L, 1L, 2L, 2L, 2L), txt.y.obs = c(5L,
4L, 3L, 6L, 7L, 9L), cont.y.obs = c(4L, 3L, 9L, 4L, 8L, 6L),
ID = 1:6, obs.txt = c(5L, 2L, 4L, 8L, 4L, 7L), TE = c(5L,
7L, 4L, 3L, 5L, 8L), X1 = c(1L, 1L, 1L, 2L, 2L, 2L), sim.1 = c(4L,
shape(rtNew,direction="long",varying=1:ncol(rtNew),sep="_",timevar="m")
A.K.
- Original Message -
From: arun
To: Andrea Lamont
Cc: R help ; David Carlson
Sent: Wednesday, July 24, 2013 11:53 PM
Subject: Re: [R] flexible approach to subsetting data
Hi,
I
an a écrit :
> On 25-07-2013, at 08:35, Arnaud Michel wrote:
>
>> But I just noticed that the two solutions are not comparable :
>> the change concern only Nom and Prenom (solution Berend) and not also Sexe
>> or Date.de.naissance orother variables (solution Arun) that can
HI,
You could try:
my.data<- structure...
pe<-round(pe,0)
peMax<-as.data.frame(sapply(paste0("a",1:4),function(x) {x1<-my.data[,x];
unsplit(lapply(split(x1,x1),function(y) {x2<-row.names(pe)[pe[,x]%in% y];
x3<-x2[which.max(as.numeric(gsub("\\D+","",x2)))];rep(x3,length(y))}),x1)}),stringsAsFactor
May be this also helps:
XXX: dataset
rl<-rle(as.character(XXX$electrode))
dat<-do.call(rbind,lapply(seq_along(rl$lengths),function(i){x1<-if(rl$values[i]=="electrode1"
& (rl$lengths[i]%/%3>1)) rep(3,rl$lengths[i]%/%3) else
rl$lengths[i];data.frame(Len=x1,Val=rl$values[i])}))
lst1<-split(cums
Hi,
You may try this (didn't get time to test this extensively)
indx<-which(tt$response!="buy")
tt$newcolumn<-0
tt[unlist(lapply(seq_along(indx),function(i) {x1<-if(indx[i]==nrow(tt))
indx[i] else seq(indx[i]+1,indx[i+1]-1);x2<-rbind(tt[indx[1:i],],tt[x1,]);
if(any(x2$response=="sample"))
row.n
HI,
Not sure about what your expected output would be. Also 'CEBPA' was not
present in the Data.txt.
gset<- read.table("Names.txt",header=TRUE,stringsAsFactors=FALSE)
temp1<- read.table("Data.txt",header=TRUE,stringsAsFactors=FALSE)
lst1<-split(temp1,temp1$Names)
mat1<-combn(gset[-1,1],2) #rem
uy 2 0
6 3 sample 3 1
7 3 sample 2 1
8 3 buy 1 0
9 4 sample 1 1
10 4 buy 4 0
A.K.
____
From: vanessa van der vaart
To: arun
Sent: Thursday, July 25
Hi,
You may try:
library(psych)
?block.random()
Also, look this link
http://personality-project.org/revelle/syllabi/205/block.randomization.pdf
A.K.
- Original Message -
From: mina orang
To: r-help@r-project.org
Cc:
Sent: Friday, July 26, 2013 4:26 AM
Subject: [R] a very urgunt and i
trode4" "electrode3" "electrode1" "electrode3"
#[16] "electrode2" "electrode3" "electrode4" "electrode1" "electrode4"
#[21] "electrode2" "electrode4" "electrode3"
A.K.
Hi Rui & A
- Original Message -
From: "dennis1...@gmx.net"
To: Rui Barradas ; r-help@r-project.org
Cc:
Sent: Friday, July 26, 2013 6:07 AM
Subject: Re: [R] How to split two levels several times?
Hi Rui & Arun,
really thanks for investing so much time to deal with this problem! The co
ot;electrode4")
#Using previous dataset XXX, XXX1, XXX2
fun1(XXX,"electrode",3,"electrode1")
fun1(XXX1,"electrode",3,"electrode1")
fun1(XXX2,"electrode",3,"electrode1")
A.K.
- Original Message -
From: arun
To: "denni
2. I will get back to you once I run it.
A.K.
From: Manisha
To: arun
Sent: Friday, July 26, 2013 11:09 AM
Subject: Re: Pairwise comparison between columns, logic
Hi Arun,
I ran the script on a larger dataset and I seem to be running into this
following error:
Error: All inputs to rbind.f
ot; "NPM1_RUNX1" "NPM1_ASXL1" "NPM1_KDM6A"
#[6] "FLT3_TP53" "FLT3_EZH2" "FLT3_KRAS" "FLT3_ASXL1" "FLT3_KDM6A"
#[11] "IDH1_TP53" "IDH1_KRAS" "NRAS_IDH2" "NRAS_KRAS&qu
On some slightly different datasets:
tt1<-structure(list(subj = c(1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5,
6, 6, 6, 7, 7, 7, 8, 8, 8), response = structure(c(2L, 2L, 1L,
2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L,
1L, 2L, 1L), .Label = c("buy", "sample"), class = "factor"),
HI,
Using the example in ?combine
library(randomForest)
rf1 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
rf2 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
rf3 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
rf.all <- combine(rf1, r
HI,
set.seed(28)
dat1<- as.data.frame(matrix(sample(c(NA,1:20),100,replace=TRUE),ncol=10))
set.seed(49)
dat2<- as.data.frame(matrix(sample(c(NA,40:80),100,replace=TRUE),ncol=10))
lapply(seq_len(ncol(dat1)),function(i) {lm(dat2[,i]~dat1[,i])}) #works bcz the
default setting removes NA
Regarding
.2.2
loaded via a namespace (and not attached):
[1] plyr_1.8 tools_3.0.1
BTW, It is better to ?dput() the example dataset.
A.K.
- Original Message -
From: iza.ch1
To: arun
Cc: R help
Sent: Saturday, July 27, 2013 4:46 PM
Subject: Re: Re: [R] linear fit function with NA values
Hi
sample 4 1
18 7 buy 3 1
19 7 buy 4 1
20 8 buy 5 0
21 8 sample 4 1
22 8 buy 2 1
A.K.
____
From: vanessa van der vaart
To: arun
Cc: David Winsemi
buy 2 1
#14 6 buy 4 1
#15 6 sample 5 0
#16 6 sample 5 0
#17 7 sample 4 1
#18 7 buy 3 1
#19 7 buy 4 1
#20 8 buy 5 0
#21 8 sample 4 1
#22 8
ate and sorted these
10. unique(unlist( #unlist the list and choose only the unique elements
11. dat[unique(unlist(,newColumn]<-1 # assign those rows that fits the
condition in newColumn as 1.
Hope it helps.
Regards,
A.K.
From: vanessa
Hi,
?max
?min
max(mydates)
#[1] "2007-06-22"
min(mydates)
#[1] "2004-02-13"
max(mydates)-min(mydates)
Time difference of 1225 days
max(as.numeric(mydates))-min(as.numeric(mydates))
#[1] 1225
A.K.
- Original Message -
From: Peter Maclean
To: "r-help@r-project.org"
Cc:
Sent: Sunday,
Hi,
This link may help:
http://stackoverflow.com/questions/14476961/why-do-i-get-position-dodge-requires-constant-width-even-though-widths-are-con
A.K.
- Original Message -
From: David Arnold
To: r-help@r-project.org
Cc:
Sent: Sunday, July 28, 2013 5:41 PM
Subject: [R] ggplot position
Hi,
system("names=(X Y); echo ${names[0]}")
#sh: 1: Syntax error: "(" unexpected
#this worked for me:
system("bash -c 'names=(X Y); echo ${names[0]}'")
#X
A.K.
- Original Message -
From: Dario Strbenac
To: "r-help@r-project.org"
Cc:
Sent: Sunday, July 28, 2013 10:00 PM
Subject: [
Hi,
de<- structure(c(NA, NA, NA, NA, NA, NA, NA, NA, 0.27500571, -3.07568579,
-0.42240954, -0.26901731, 0.01766284, -0.8099958, 0.20805934,
0.03036708, -0.26928087, 1.20925752, 0.38012008, -0.41778861,
-0.49677462, -0.13248754, -0.54179054, 0.35788624, -0.41467591,
-0.59234248, 0.73642396, -0.
sh sheikhi
To: "smartpink...@yahoo.com"
Sent: Monday, July 29, 2013 4:37 PM
Subject: Aggregate
Hi Arun,
I have a question about aggregation in R.
I have the following data set:
ID Group1
1 1
1 0
1 1
1 0
2 1
2 1
2 0
2 1
5 1
5 1
5 1
5 0
I want to aggregate the data fo
To add:
library(reshape2)
dcast(dat1,ID~Group1,length,value.var="Group1") # ID would be a column
# ID No Yes
#1 1 2 2
#2 2 1 3
#3 5 1 3
A.K.
- Original Message -
From: David Carlson
To: 'arun' ; 'farnoosh sheikhi'
Cc: 'R help
Hi,
Try:
library(Epi)
stat.table(tension,list(count(),mean(breaks)),data=warpbreaks)
# ---
# tension count() mean(breaks)
#---
#L 18 36.39
#M 18 26.39
#H 18 21.67
#-
Hi,
If the rows are already ordered:
x1<- as.data.frame(x)
x[with(x1,ave(seq_along(V2),V2,FUN=function(x) !x%in%min(x)))==1,]
# [,1] [,2] [,3]
#[1,] "1/5/13" "15" "25"
#[2,] "1/9/13" "15" "28"
#[3,] "2/5/13" "18" "35"
#[4,] "2/9/13" "18" "38"
#otherwise
x[with(x1,unlist(tapply(as.Date(V1,
Just a note:
If the dataset is not ordered, this could result in:
set.seed(24)
xNew<-x[sample(1:nrow(x),6,replace=FALSE),]
idxN<-which(c(TRUE,diff(as.integer(xNew[,2]))!=0))
xNew[-idxN,]
#[1] "2/1/13" "18" "30"
xNew1<-xNew[order(xNew[,2],xNew[,1]),]
idx<-which(c(TRUE,diff(as.integer(xN
x[rowSums(!x<0)==ncol(x),] #if you don't want x<0
# a b c d e
#3 2 3 3 4 3
#5 4 5 5 6 4
#or
x[rowSums(!x==-1)==ncol(x),]
# a b c d e
#3 2 3 3 4 3
#5 4 5 5 6 4
A.K.
- Original Message -
From: Dimitri Liakhovitski
To: r-help
Cc:
Sent: Tuesday, July 30, 2013 10:06 AM
Subject: [R]
)+4*(V2!=-1)+8*(V3!=-1)+16*(V4!=-1)+32*(V5!=-1)))
res3<-x1[indx==max(indx),]
})
# user system elapsed
# 0.268 0.008 0.274
identical(res1,res3)
#[1] TRUE
A.K.
- Original Message -
From: arun
To: Dimitri Liakhovitski
Cc: R help
Sent: Tuesday, July 30, 2013 10:30 AM
Subject
Hi,
Please use ?dput() for the example data
sunrise<- structure(list(day_frac = c("Santiago", "Ourense", "Vigo", "Ferrol",
"Santiago", "Ourense", "Vigo", "Ferrol", "Santiago", "Ourense",
"Vigo", "Ferrol"), time = structure(c(1372935664, 1372935605,
1372935846, 1372935458, 1373022101, 13730220
Hi,
Did you checked after removing "e" from "formate"?
ortho$test.dat <- as.Date(ortho$xray.date, formate="%d-%b-%y")
A.K.
- Original Message -
From: Liz Hare
To: r-help@r-project.org
Cc:
Sent: Tuesday, July 30, 2013 12:00 PM
Subject: [R] as.Date with characters error
Hello,
I'm tr
Hi,
Try using trim=TRUE, in ?format()
options(digits=4)
df2 <- data.frame(x = rnorm(11), y = rnorm(11), id = 1:11)
df2$id2 <- apply(df2, 1, function(dfi) format(dfi["id"], trim=TRUE,scientific
= FALSE))
df2$id2[0:100010]
# [1] "0" "1" "2" "3" "4" "999
ached):
[1] plyr_1.8 tools_3.0.1
- Original Message -
From: Mathieu Basille
To: arun
Cc: R help
Sent: Tuesday, July 30, 2013 2:29 PM
Subject: Re: [R] 'format' behaviour in a 'apply' call depending on
'options(digits = K)'
Thanks Arun for your ans
Just type
acf
ccf
on R prompt
A.K.
- Original Message -
From: Cathy Lee Gierke
To: r-help@r-project.org; r-core-ow...@r-project.org
Cc:
Sent: Tuesday, July 30, 2013 4:02 PM
Subject: [R] acf and ccf
Greetings,
Is it possible to see the source code for the acf and ccf functions? I
s, snames = colnames(x)), class = "acf")
Check this link:
http://stackoverflow.com/questions/14035506/how-to-see-the-source-code-of-r-internal-or-primitive-function
A.K.
____
From: Cathy Lee Gierke
To: arun
Sent: Tuesday, July 30, 2013 5:04 PM
Subject:
Hi,
It is not clear which OS you are using. Most probably, the "Directory" column
would be "factor".
table1<- read.table(text="
ID Directory
1 /home/arunksa111/Documents
2 /home/arunksa111/Trial
3 ~/Trial1
4 ~Trial2
",sep="",header=TRUE,stringsAsFactors=FALSE)
setwd(table1$Directory[2])
getw
Hi,
May be this helps:
set.seed(24)
dat1<- data.frame(ID=1:500,value=rnorm(500))
res<- split(dat1,dat1$ID%%2)
A.K.
- Original Message -
From: ravi.raghava1
To: r-help@r-project.org
Cc:
Sent: Wednesday, July 31, 2013 3:46 AM
Subject: [R] Using If loop in R how to extract even and odd i
Hi,
May be this helps:
set.seed(24)
dat1<- data.frame(ID=1:500,value=rnorm(500))
indx<-round(quantile(as.numeric(row.names(dat1)),probs=c(0.05,0.20,0.50,1)))
indx1<-findInterval(row.names(dat1),indx,rightmost.closed=TRUE)
dat1$SEGMENT<- as.character(factor(indx1,labels=c("Top 5%","5 to 20","20 to
E)
dat1$SEGMENT<- as.character(factor(indx1,labels=c("Top 5%","5 to 20","20 to
50", "Bottom 50")))
A.K.
Hi Arun Kirshna,
I have tested your method and it will work for me.
I only run into one problem. Before I want to do this operation I have sorted
my da
HI,
Please use ?dput()
mat1<- as.matrix(read.table(text="
D0989 D9820 D5629 D4327 D2134
GID_1 1 0 0 1 0
GID_2 0 1 1 0 0
GID_4 0 0 1 0 0
GID_5 1 1 0 0 0
GID_7 0 1 0
Hi,
May be this helps:
set.seed(25)
mt1<- matrix(sample(c(NA,1:40),20*200,replace=TRUE),ncol=200)
set.seed(487)
mt2<- matrix(sample(c(NA,1:80),20*200,replace=TRUE),ncol=200)
res<- sapply(seq_len(ncol(mt1)),function(i)
cor(mt1[,i],mt2[,i],use="complete.obs",method="pearson"))
A.K.
Hello,
May be this helps:
l1<- list('a',1)
l2<- list('b',2)
l3<- list('c',3)
df1<-data.frame(mapply(`c`,l1,l2,l3,SIMPLIFY=FALSE),stringsAsFactors=FALSE)
colnames(df1)<-paste0("X",1:2)
str(df1)
#'data.frame': 3 obs. of 2 variables:
# $ X1: chr "a" "b" "c"
# $ X2: num 1 2 3
A.K.
- Origin
uot;IslandB"),function(x) {x1<-
mat1[match(gsub(".*\\s+","",get(x)),row.names(mat1)),];!!colSums(x1)}))
# D0989 D9820 D5629 D4327 D2134
#IslandA TRUE TRUE FALSE TRUE FALSE
#IslandB FALSE TRUE TRUE FALSE TRUE
# "*1" will replace TRUE with 1 and FA
Hi,
Not clear about your desired output.
source("ou.txt")
split(ou,ou$V1) #split based on values of "V1" (1 and 0)
#or
#may be you wanted 1 followed by 0 in one block, again 1 followed by 0 in
second block etc..
#In that case:
lst1<-split(ou,cumsum(c(TRUE,diff(ou$V1)==1)))
A.K.
On Wed, Jul
Hi,
In that case:
lst1<-split(ou,cumsum(c(TRUE,diff(ou$V1)==1)))
lst2<-lapply(lst1,function(x) x[x$V1==1,])
A.K.
From: Dominic Roye
To: arun
Sent: Wednesday, July 31, 2013 7:17 PM
Subject: Re: [R] Split in blocks
Hi,
The thing is that beca
dA","IslandB"),function(x) {x1<-
mat1[match(gsub(".*\\s+","",get(x)),mat1[,1]),-1];(!!colSums(x1))*1}))
# D0989 D9820 D5629 D4327 D2134
#IslandA 1 1 0 1 0
#IslandB 0 1 1 0 1
A.K.
__
10 D0462 D0463 D0473 D0475 D0488 D0489 D0492 D0493 D0504
#IslandA 0 0 0 0 0 0 0 0 0 0 0 0
#IslandB 0 0 0 0 0 1 0 0 0 0 1 0
# D0536
#IslandA 0
#IslandB 1
A.K.
__
0 1 0 0 0 0
#Conti_Malay 0 0 0 0 0 1 0 0 0 0
#Island_Sumatra 0 0 0 0 0 0 0 0 0 1
# D0493 D0504 D0536
#Conti_Australia 0 0 1
#Conti_Malay 1 0 1
#Island_Sumatra
2 82 185 72 304 175 208
#XLOC_03 2000 361 867 438 195 80 109
#XLOC_04 143 30 67 37 66 49 54
#XLOC_05 0 0 0 0 0 0 0
#XLOC_06 0 0 0 0 1 0 0
A.K.
Fro
sed
#0.012 0.000 0.011
system.time(dat2[,-1] <- sapply(round(dat2[,-1], 0), as.integer))
# user system elapsed
# 0.440 0.000 0.441
identical(dat1,dat2)
#[1] TRUE
A.K.
- Original Message -
From: David Carlson
To: 'Vivek Das' ; 'arun' ; 'R help'
D0407 D0409 D0410 D0462 D0463 D0473 D0475 D0488 D0489 D0492
#Conti_Australia 0 0 1 0 0 0 0 0 0 0
#Conti_Korea 0 0 0 0 0 0 0 0 0 0
#Conti_Malay 0 0 0 1 0 0 0 0 0 0
#
You could try:
set.seed(25)
mt1<- matrix(sample(c(NA,1:40),20*200,replace=TRUE),ncol=200)
colnames(mt1)<- paste0("X",1:200)
set.seed(487)
mt2<- matrix(sample(c(NA,1:80),20*200,replace=TRUE),ncol=200)
colnames(mt2)<- colnames(mt1)
res<-lapply(colnames(mt1),function(x) {x1<-data.frame(mt1[,x],mt2[
Hi,
You could remove it by:
vec1<- c( "","1003PI_pilot0101", "1003PI_pilot0102","1003PI_pilot0103",
"1003PI_pilot0104", "1003PI_pilot0105", "1003PI_pilot0107")
vec1[vec1!=""]
#[1] "1003PI_pilot0101" "1003PI_pilot0102" "1003PI_pilot0103" "1003PI_pilot0104"
#[5] "1003PI_pilot0105" "1003PI_pilot0107
You could also try:
x1<-matrix(0,5,5)
indx<-which(!is.na(x1),arr.ind=TRUE)
x1[indx[indx[,1]!=indx[,2],]]<- as.vector(x)
#Speed comparison:
set.seed(48)
m1<- matrix(sample(1:40,4500*4499,replace=TRUE),ncol=4500)
m2<- matrix(0,4500,4500)
system.time({
indx<- which(m2==0,arr.ind=TRUE)
m2[indx[indx[
matrix(0,4500,4500)
m3[upper.tri(m3)] <- m1[upper.tri(m1)]
m3[lower.tri(m3)] <- m1[lower.tri(m1, diag=TRUE)]
})
#user system elapsed
# 4.208 0.572 4.790
identical(m2,m2New)
#[1] TRUE
identical(m2,m3)
#[1] TRUE
A.K.
- Original Message -
From: arun
To: Martin Bathold
Hi,
May be you should try ?data.table().
Please use ?dput().
dat1<- read.table(text="
Area Sex Year y
Bob F 2011 1
Bob F 2011 2
Bob F 2012 3
Bob M 2012 3
Bob M 2012 2
Fred F 2011 1
Fred F 2011 1
Fred F 2012 2
Fred M 2012 3
Fred M 2012 1
",sep="",header=TRUE,stringsAsFactors=FALSE)
library(dat
#actually, this would be more compact
data.frame(split(z[,-1],z$x))
A.K.
- Original Message -
From: arun
To: Brijesh Gulati
Cc: R help
Sent: Sunday, August 4, 2013 1:27 PM
Subject: Re: [R] question: data.frame data conversion
Hi,
May be:
z<-data.frame(x,y,stringsAsFactors=FA
Hi,
May be:
z<-data.frame(x,y,stringsAsFactors=FALSE)
simplify2array(split(z[,-1],z$x))
# a b
#[1,] 1.0 1.01
#[2,] 1.2 1.03
#[3,] 1.1 1.00
as.data.frame(simplify2array(split(z[,-1],z$x)))
A.K.
- Original Message -
From: Brijesh Gulati
To: r-help@r-project.org
Cc:
Sent: Su
t; "b" "b" "b" "c" "c" "1" ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:2] "x" "y"
A.K.
- Original Message -
From: Brijesh Gulati
To: 'arun'
Cc: 'R help'
HI,
May be this helps:
MyString1 <- c("Sun Sep 01 00:20:00 EDT 2013", "Sun Dec 01 00:00:00 EST 2013")
as.POSIXct(gsub("EDT|EST","",MyString1), format="%a %b %d %H:%M:%S %Y")
#[1] "2013-09-01 00:20:00 EDT" "2013-12-01 00:00:00 EST"
as.Date(gsub("EDT|EST","",MyString1), format="%a %b %d %H:%M:%S
You could also try:
z$id<-with(z,ave(x,x,FUN=seq))
library(reshape2)
dcast(z,id~x,value.var="y")[-1]
# a b c
#1 1.0 1.01 2
#2 1.2 1.03 3
#3 1.1 1.00 NA
A.K.
- Original Message -
From: Rui Barradas
To: Brijesh Gulati
Cc: r-help@r-project.org
Sent: Sunday, August 4, 2013 3:47
XLOC_10 7 1 5 3 0 1
#XLOC_11 63 10 19 15 92 228
#I don't have an account in stackoverflow. So, it is must be somebody else.
A.K.
____
From: Vivek Das
To: arun
Sent: Monday, August 5, 2013 6:31 AM
Subject: Remo
Hi,
You could use this, but it would be slow.
"""
# I know functions like e.g. 'apply' but don't know how to use them for
the solution of the following problem:
"""
lst1<-split(seq_along(b),rep(unlist(a),unlist(a)))
res<-cbind(r,sapply(lst1,function(i)
{x1<-b[,i];sapply(split(as.matrix(r),row(r)
HI,
Please use ?dput() to show a reproducible example.
set.seed(45)
dat1<- data.frame(date=
format(seq(as.Date("01-01-1947",format="%m-%d-%Y"),as.Date("02-01-1947",format="%m-%d-%Y"),by=1),"%m/%d/%Y"),value=sample(1800:2400,32,replace=FALSE))
dat1[c(TRUE,(diff(dat1$value)< -100) | (diff(d
0.0 0.12 0.00 0.00 0
A.K.
From: Vivek Das
To: arun
Sent: Monday, August 5, 2013 1:05 PM
Subject: Re: Removing the rows where all the elements are 0
Hi Arun,
This seems to work only if the values are perfect 0 but if there are values in
rows like
/1947 2018
12 01/12/1947 2319
13 01/13/1947 1981
17 01/17/1947 2364
18 01/18/1947 1882
26 01/26/1947 1839
27 01/27/1947 2344
28 01/28/1947 2229
30 01/30/1947 1923
32 02/01/1947 2379
- Original Message -
From: "Bosch, Darrell"
To: arun
Cc:
Sent: Monday, August 5,
6
x3<- na.omit(x2)
dim(x3)
#[1] 19678 6
cl<-c(rep(0,3),rep(1,2))
origin<-c(rep(1,5))
library(RankProd)
RP.out <-
RPadvance(x3[,-1],cl,origin,gene.names=as.character(x3[,1]),num.perm=200)
A.K.
From: Vivek Das
To: arun
Sent: Tuesday, A
dat1<- read.table(text="
Name State_Code
Tom 20
Harry 56
Ben 05
Sally 04
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat2<- do.call(cbind,list(NorthEast,MidWest,South,West,Other))
colnames(dat2)<- c("NorthEast","MidWest","South","West","Other")
dat2<- as.data.frame(dat2)
Hi,
You can save it in file. I copy and paste:
Subtype,Gender,Expression
A,m,-0.54
A,f,-0.8
B,f,-1.03
C,m,-0.41
on the "gedit" and save it as "data1.csv". You might be able to do the same
with notepad.
x <- read.csv("data1.csv",header=T,sep=",")
x2 <- read.csv("data2N.csv",header=T,sep=",")
HI,
Not sure about your expected result.
library(plyr)
data2New<-join_all(lapply(setdiff(names(data1), names(data2)),function(x)
{data2[,x]<-NA; data2}))
data1New<-join_all(lapply(setdiff(names(data2),
names(data1)),function(x){data1[,x]<-NA;data1}))
data1New
# a b c d e z f g
#1 1 5
20 24 NA NA
A.K.
A.K.
From: Steven Ranney
To: arun
Cc: R help
Sent: Thursday, August 8, 2013 2:21 PM
Subject: Re: [R] Creating new vectors from other dataFrames
This is exactly what I'm looking for. Each dataFrame will have those column
Hi,
Try:
df$POT2_TX<- df$POT_TX
df[,6:7]<- lapply(df[,6:7],function(x) as.numeric(as.character(sub(",",".",x
str(df)
#'data.frame': 10 obs. of 7 variables:
# $ IDANT : int 37837 37838 37839 37840 37841 37842 37843 40720 40721 40722
# $ N_TX : int 6 6 6 4 1 1 1 2 2 1
# $ TILT
Hi,
May be this gets you started:
plot(1,1,xlim=0:1,ylim=0:1)
text(0.6,0.8, expression(M3:~italic(Homo)~paste(",", " 5 areas, 2 areas
max",sep="")))
text(0.6,0.4, expression(M4:~italic(Pan)~paste(",", " 3 areas, 2 areas
max",sep="")))
A.K.
- Original Message -
From: Nick Matzke
To: R
Hi,
You may try:
dat1<- structure(list(Date.Time = c("C", "C", "C"), Unit = c(23L, 23L,
22L), Value = c(207L, 82L, 894L)), .Names = c("Date.Time", "Unit",
"Value"), class = "data.frame", row.names = c("27/06/13 02:35:01",
"27/06/13 02:50:01", "27/06/13 03:05:01"))
dat2<-data.frame(Date.Time=row
101 - 200 of 3327 matches
Mail list logo