Hi,
You can also try:
res2<-rowSums(x==word)
res1<-sapply(where,length)
res1[]<- sapply(res1,as.numeric)
identical(res1,res2)
#[1] TRUE
A.K.
- Original Message -
From: Rui Barradas
To: Sudip Chatterjee
Cc: r-help@r-project.org
Sent: Friday, March 8, 2013 4:26 PM
Subject: Re: [R]
HI,
Try this:
df<-data.frame(name=c("a","b","c"),type=c(1,2,3),rtn=do.call(cbind,list(list(1:3,4:6,7:10
str(df)
#'data.frame': 3 obs. of 3 variables:
# $ name: Factor w/ 3 levels "a","b","c": 1 2 3
# $ type: num 1 2 3
# $ rtn :List of 3
# ..$ : int 1 2 3
#..$ : int 4 5 6
.#.$ : i
Hi,
You could also try:
df1<-data.frame(name=c("a","b","c"),type=c(1,2,3),rtn=as.array(list(1:3,4:6,7:10)))
A.K.
- Original Message -
From: Kevin Zembower
To: r-help@r-project.org
Cc:
Sent: Friday, March 8, 2013 7:49 PM
Subject: [R] data.frame with variable-length list
Hello,
I'm
Hi,
You could try this:
library(lubridate)
res<-as.Date(dmy(format(Date-8, "%d-%m-%Y"))+months(Vec))
res
#[1] "2013-03-01" "2014-04-01" "2014-01-01" "2013-07-01"
A.K.
- Original Message -
From: Christofer Bogaso
To: r-help
Cc:
Sent: Saturday, March 9, 2013 6:41 AM
Subject: [R] Calc
ount both "Oranges" and "oranges"
str_count(tolower(dat1$Data),"oranges")
#[1] 1 2 2
#otherwise
str_count(dat1$Data,"oranges")
#[1] 1 1 2
A.K.
____
From: Sudip Chatterjee
To: Rui Barradas
Cc: arun ; R help
Sent: Satur
7
#2012-12-01 03:00:00 4.7 4.3
#2013-01-01 02:30:00 3.9 4.2
#2013-01-01 03:00:00 3.7 4.5
#2013-01-01 03:30:00 3.5 4.1
A.K.
- Original Message -
From: Jakob Hahn
To: arun
Cc:
Sent: Saturday, March 9, 2013 10:04 AM
Subject: Re: Zoo Data
Hi Arun,
z1[seq(
ns selected
A.K.
From: Joanna Zhang
To: arun
Sent: Saturday, March 9, 2013 10:38 PM
Subject: Re: max row
I think something is wrong with EN, it should not be integer. Let me check.
On Sat, Mar 9, 2013 at 9:36 PM, arun wrote:
In the example set you gave, both N and EN are the same. th
Hi,
For the first case:
lst2<-lapply(x.list, calcnorm2, x.list)
lapply(lst2,function(x) do.call("c",x))
#[[1]]
#[1] 0.0 31.75257
#[[2]]
#[1] 31.75257 0.0
A.K.
For the second case:
lst1<-as.list(data.frame(t(apply(x,1,calcnorm2.const,x
names(lst1)<- NULL
lst1
#[[1]]
#[1]
HI,
Try this:
dat1<- read.table(text="
V1,V2,V3,V4,V5,V6,V7
chr1,564563,564598,564588 564589,1336,+,134
chr1,564620,564649,564644 564645,94,+,10
chr1,565369,565404,565371 565372,217,+,8
chr1,565463,565541,565480 565481,1214,+,15
chr1,565653,565697,565662 565663,1031,+,28
chr1,565861,565922,
You could also do:
simplify2array(x.list)[2,]
#[1] 0.1 3.0
A.K.
- Original Message -
From: Jorge I Velez
To: ishi soichi
Cc: r-help
Sent: Monday, March 11, 2013 6:57 AM
Subject: Re: [R] take two columns from a set of lists
Is the following that you are looking for?
unlist(lapply(x.l
HI,
Not sure whether it helps or not.
You could use ?merge()
dat1<-as.data.frame(as.table(tapply(x$value, list(x$group, x$year),
FUN=length)),stringsAsFactors=FALSE)
dat2<-expand.grid(group=LETTERS[1:2],year=2001:2005)
names(dat1)[1:2]<- names(dat2)
res<-merge(dat1,dat2,by=c("group","year"),a
148 0.3365796
#2 2 2 5 4 0.8167625 0 9 6.549713 0.2002258 0.4405518 0.2038955
#3 3 2 5 4 0.8573750 0 9 7.285250 0.2002258 0.4218750 0.2038955
#4 2 2 6 4 0.8167625 0 10 6.732950 0.1689405 0.4558468 0.2121882
#5 3 2 6 4 0.8573750 0 10 7.427875 0.168940
_P0L cterm1_P0H
# [7] N EN BH BL AH AL
#<0 rows> (or 0-length row.names)
6
fun1(10,0.15,0.25,0.05,0.06,0.07,0.07,0.15,0.20,0.5,0.4)
#Joining by: m1, n1, cterm1_P0L, cterm1_P1L, cterm1_P0H, cterm1_P1H
# m1 n1 m n cterm1_P0L cterm1_P0H N EN
I guess you are referring to names()
vec1# dataset
vec1[names(vec1)>1820]
head(vec1[names(vec1)>1820])
# 1821 1822 1823 1824 1825 1826
#1.4250 1.0990 1.0070 1.1795 1.3855 1.4065
A.K.
- Original Message -
From: catalin roibu
To: r-help@r-project.org
Cc:
Sent: Tuesday, M
Hi,
You could also do:
library(reshape2)
dcast(dat,V1~V2,value.var="V3",max,fill=0)
# V1 b1 b2 b3
#1 a1 4 0 0
#2 a2 0 2 0
#3 a3 5 0 3
A.K.
- Original Message -
From: Rui Barradas
To: avinash sahu
Cc: r-help@r-project.org
Sent: Tuesday, March 12, 2013 7:10 PM
Subject: R
Hi,
You could use:
library(stringr)
?str_sub()
lapply(2:3,function(i) if(i==2) str_sub(x,end=i) else str_sub(x,i))
#[[1]]
#[1] "a1" "a2" "a1"
#[[2]]
#[1] "b1" "b2" "b2"
A.K.
- Original Message -
From: Johannes Radinger
To: r-help@r-project.org
Cc:
Sent: Wednesday, March 13, 2013 4
HI,
tempdf<-read.table(text="
name,var1,var2,abb
Tom Cruiser,1,6,TomCru
Bread Pett,2,5,BrePet
Arnold Schwiezer,3,7,ArnSch
",sep=",",header=TRUE,stringsAsFactors=FALSE)
substr(tempdf$name, 4, 6) #as some of the firstnames differ in the number of
characters
#[1] " Cr" "ad " "old"
substr(gsub
b1" "0b" "b2" "40"
let1<-unique(unlist(strsplit(gsub("\\d+","",x1),"")))
split(unlist(strsplit(gsub("(\\w\\d+)(\\w\\d+)","\\1 \\2",x1)," ")),let1)
#$a
#[1] "a1" "a10" "a2"
Hi,
Try this:
data1<-data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2))
data1<-within(data1, {trip.id<- cumsum(c(1,abs(diff(beh;
Seq<-ave(row,trip.id,FUN=seq)})
data1
# row beh Seq trip.id
#1 1 1 1 1
#2 2 1 2 1
#3 3 1 3 1
#4 4 2 1 2
#5
Hi,
Try this:
a1<-a
a1[rowSums(is.na(a1))==1][ is.na(a1[rowSums(is.na(a1))==1])]<-0
library(matrixStats) c1<- cbind(a,rowDiffs(a1))
c1
# [,1] [,2] [,3]
#[1,] 2 5 3
#[2,] 3 8 5
#[3,] 4 NA -4
#[4,] NA 8 8
#[5,] NA NA NA
identical(c,c1)
#[1] TRUE
A.K.
HI,
Try this:
mydf1<- mydf
mydf1[]<-lapply(1:3,function(i) {mydf[which(i== myindex),i]<-1; mydf[,i]})
mydf1
# c1 c2 c3
#1 1 NA NA
#2 NA 1 NA
#3 NA NA 1
#4 NA 1 NA
#5 1 NA NA
identical(mydf1,mygoal)
#[1] TRUE
A.K.
- Original Message -
From: Dimitri Liakhovitski
To: r-help
Cc
57738 0.7695212 1.2963822
#362 362 4.539952 0.1371580 0.7409566 1.3431055
#363 363 2.133320 0.1179060 0.7325064 1.3905679
#364 364 1.499514 0.1238591 0.7223855 1.3318688
#365 365 1.136719 0.1312868 0.7449733 1.3561590
#366 366 1.004139 NaN NaN 0.5610225
A.K.
Hi,
May be this helps:
dat1<- read.table(text="
a b c d e
1 12 15 65 6
1 65 85 36 5
2 69 84 35 8
2 45 78 65 8
",sep="",header=TRUE)
library(data.table)
dat2<- data.table(dat1)
dat2[,head(sapply(.SD,sum)/sapply(.SD,sum)[4],-1),by="a
x<- "`Year_Month)201103`"
gsub("[`]","",x)
#[1] "Year_Month)201103"
A.K.
- Original Message -
From: Tammy Ma
To: "r-help@r-project.org"
Cc:
Sent: Thursday, March 14, 2013 4:23 AM
Subject: [R] how to change "`Year_Month)201103`" into "Year_Month)201103" using
R?
HI,
I have the pat
library(stringr)
str_pad(Vec,5,"right")
#[1] "sada " "asdsa" "sa "
#or
str_pad(Vec,max(nchar(Vec)),"right")
#[1] "sada " "asdsa" "sa "
str_count(str_pad(Vec,5,"right"),"")
#[1] 5 5 5
A.K.
- Original Message -
From: Christofer Bogaso
To: r-help
Cc:
Sent: Thursday, March 14, 20
In addition to Marc's suggestion:
sprintf("%-5s",Vec)
#[1] "sada " "asdsa" "sa "
formatC(Vec,width=-5)
#[1] "sada " "asdsa" "sa "
formatC(Vec,width=5)
#[1] " sada" "asdsa" " sa"
format(Vec,justify="right")
#[1] " sada" "asdsa" " sa"
A.K.
- Original Message -
From: Marc Schwart
HI,
1.
date1<-c("5 jan 2013", "1 jan 2013")
date1<-as.Date(date1,format="%d %b %Y")
date1[1]-date1[2]
#Time difference of 4 days
2.
If you only have the week number of year without any other information, it
would be difficult to predict which day that would be.
You could get the week numb
HI,
Not sure whether this helps.
If you take out the grep(",par.obj,..), it works without any warning.
eval(parse(text=paste(
"dt2 <- dt[", "grep('", par.fund, "', fund) & ",
"grep('", par.func, "', func)",
", sum(amount), by=c('code', 'year')]" , sep="")))
dt[grep('^1.E$',fund) & grep('^1.
dat1<- read.table(text="
Product Price Year_Month PE
A 100 201012 -2
A 98 201101 -3
A 97 201102 -2.5
B 110 201101 -1
B 100 201102 -2
B
Hi,
You could try this for multiple intersect:
dt[Reduce(function(...) intersect(...),
list(grep(par.fund,fund),grep(par.func,func),grep(par.obj,obj))),sum(amount),by=c('code','year')]
# code year V1
#1: 1001 2011 123528
#2: 1001 2012 97362
#3: 1002 2011 103811
#4: 1002 2012 97179
dt
HI,
Try this:
T1<- paste0("c",1:5)
T2<- paste0("k",1:5)
as.vector(outer(T1,T2,paste,sep=","))
# [1] "c1,k1" "c2,k1" "c3,k1" "c4,k1" "c5,k1" "c1,k2" "c2,k2" "c3,k2" "c4,k2"
#[10] "c5,k2" "c1,k3" "c2,k3" "c3,k3" "c4,k3" "c5,k3" "c1,k4" "c2,k4" "c3,k4"
#[19] "c4,k4" "c5,k4" "c1,k5" "c2,k5" "c3,k5"
HI,
Try this:
set.seed(25)
arr1<- array(sample(c(1:40,NA),60,replace=TRUE),dim=c(5,4,3))
arr1[,,sapply(seq(dim(arr1)[3]),function(i) all(!is.na(arr1[,,i])))]
# [,1] [,2] [,3] [,4]
#[1,] 2 13 34 17
#[2,] 19 3 15 39
#[3,] 4 25 10 16
#[4,] 7 22 5 7
#[5,] 12
Hi,
Try:
data.frame(Forecast=with(PeriodSKUForecast,tapply(Forecast,SKU,head,1)))
# Forecast
#A1 99
#K2 207
#X4 63
#or
aggregate(Forecast~SKU,data=PeriodSKUForecast,head,1)
# SKU Forecast
#1 A1 99
#2 K2 207
#3 X4 63
#or
library(plyr)
ddply(PeriodSKUForecas
Hi,
If you can dput() a small part of your dataset e.g.
dput(head(yourdataset),20)), it would be helpful.
Otherwise,
dat1<- data.frame(ID=rep(1:3,times=c(3,4,2)),col2=rnorm(9))
aggregate(.~ID,data=dat1,head,1)
# ID col2
#1 1 -0.0637622
#2 2 1.1782429
#3 3 0.4670021
A.K.
- O
Forgot to cc: to list
- Forwarded Message -
From: arun
To: Marc Schwartz
Cc: Barry King ; Cc: Barry King
Sent: Friday, March 15, 2013 3:41 PM
Subject: Re: [R] Help finding first value in a BY group
Thanks Marc for catching that.
You could also use ?ave()
#unsorted
ply(names(new.list),function(x) lapply(new.list[x],function(y)
boxplot(FDR~z,data=y,xlab="Charge",ylab="FDR",main=x)))
dev.off()
}
z.boxplot(ListFacGroup)
A.K.
From: Vera Costa
To: arun
Sent: Friday, March 15, 2013 2:08 PM
Subject: Re: new q
HI,
Try this:
Date1<- seq(as.Date("2012-09-10",format="%Y-%m-%d"),length.out=20,by="day")
set.seed(25)
value<- sample(c(1:5,NA),20,replace=TRUE)
library(xts)
x1<- xts(value,Date1)
colSums(is.na(x1))
#[1] 3
which(is.na(x1))
#[1] 4 6 13
set.seed(38)
value2<- sample(c(5:8,NA),20,replace=TRUE)
x
Hi,
Y1<- 1:4
Y2<- 5:8
sqrt(var(Y1)+var(Y2)^2)-4*((var(Y1)*(var(Y2)-cov(Y1,Y2)^2)))
#[1] 9.515593
A.K.
- Original Message -
From: Miguel Eduardo Delgado Burbano
To: r-help@r-project.org
Cc:
Sent: Sunday, March 17, 2013 11:47 AM
Subject: [R] help with simple function
hello all
I am w
Hi,
Try this:
set.seed(25)
mat1<-
matrix(cbind(sample(1:15,20,replace=TRUE),sample(16:30,20,replace=TRUE)),ncol=2)
nrow(mat1[sapply(seq_len(nrow(mat1)),function(i)
any(seq(mat1[i,1],mat1[i,2])==12)),])
#[1] 17
set.seed(25)
mat2<-
matrix(cbind(sample(1:15,1e5,replace=TRUE),sample(16:30,1e5,rep
user system elapsed
# 0.500 0.000 0.502
res1
#[1] 80070
A.K.
____
From: Jim Silverton
To: arun
Sent: Monday, March 18, 2013 10:08 AM
Subject: Re: [R] Counting confidence intervals
thanks arun!!
On Mon, Mar 18, 2013 at 10:06 AM, arun wrote:
Hi,
Hi,
library(reshape2)
dcast(tmp.n,X1~X2,value.var="Y")
# X1 0 2 4
#1 0 83 12 14
#2 1 107 25 27
#3 2 47 14 28
#4 3 27 4 13
#5 4 38 9 18
#6 99 1 0 0
A.K.
- Original Message -
From: "plessthanpointohf...@gmail.com"
To: r-help@r-project.org
Cc:
Sent: Monday, March 18,
;,ylab="FDR",main=x)))
}
z.boxplot(ListFacGroup)
A.K.
From: Vera Costa
To: arun
Sent: Monday, March 18, 2013 1:59 PM
Subject: Re: new question
For example, if I run you code without "pdf" and "dev.off" I have what I
HI,
Not sure whether this is what you wanted.
library(reshape2)
result.dcast<-dcast(meltTest,A+D~H,value.var="M")
attr(result.reshape,"reshapeWide")<-NULL
row.names(result.reshape)<-1:nrow(result.reshape)
identical(result.reshape,result.dcast)
#[1] TRUE
result.dcast
# A D I J K L
#1 B E 1
Hi,
set.seed(25)
df1<-
as.data.frame(matrix(sample(LETTERS[1:10],20,replace=TRUE),ncol=5),stringsAsFactors=FALSE)
df1
# V1 V2 V3 V4 V5
#1 E B A J F
#2 G J C F H
#3 B G D G E
#4 I D D B H
str(df1)
#'data.frame': 4 obs. of 5 variables:
# $ V1: chr "E" "G" "B" "I"
# $ V2:
X18 X19 X20
#1 A C D E F G H I K L M N P Q R S T V W Y
A.K.
From: Sahana Srinivasan
To: arun
Sent: Tuesday, March 19, 2013 8:42 AM
Subject: Re: [R] Copying rows in data frames
This is the file I am reading in. The dput() comman
F G H I K L M N P Q R S T V W Y
A.K.
From: Sahana Srinivasan
To: arun
Sent: Tuesday, March 19, 2013 9:15 AM
Subject: Re: [R] Copying rows in data frames
Yes, I did want to copy the column names from the first data frame to the
secon
QQQFYLLLGNLLSPDNVVR 1-n_acPro/ 3 2 2 2
#6 APGTAEK 2 1 1 0
#7 aVGNAVPCGAR 1-n_acPro/ 2 1 1 1
___
----
levels(group)
#[1] "A" "C"
levels(group)=="A"
#[1] TRUE FALSE
a[,group=="A"]
# A AB
#[1,] 1 6
#[2,] 2 7
#[3,] 3 8
#[4,] 4 9
#[5,] 5 10
a[,group=="C"]
# C CD
#[1,] 11 16
#[2,] 12 17
#[3,] 13 18
#[4,] 14 19
#[5,] 15 20
a[,match(group,levels(group))==1]
# A AB
#[1,] 1 6
#[2,] 2 7
Hi,
set.seed(24)
dat1<- data.frame(a=1:5,b=2:6,e=sample(c(0,1,2),5,replace=TRUE))
merge(within(subset(dat2,e>0),d<-a+b),within(subset(dat2,e==0),f<-a-b),all=TRUE)
# a b e d f
#1 1 2 0 NA -1
#2 2 3 0 NA -1
#3 3 4 2 7 NA
# 4 5 1 9 NA
#5 5 6 1 11 NA
A.K.
- Original Message -
From:
Hi,
lst1<- lapply(letters[1:3],function(i)
{df1<-data.frame(my_df[i],my_df["dat"]); res<-ddply(df1,.(df1[[i]]),function(x)
c("mean"=mean(x$dat),"n"=nrow(x)));names(res)[1]<-i;res<-res[res[,1]==1,]})
res1<-Reduce(function(...) merge(...,all=TRUE),lst1)
res1[is.na(res1)]<-"*"
res1
# mean n a
Hi,
Try:
f<-c(1,2)
d[-seq_along(f),]
# a b
#[1,] 3 8
#[2,] 4 9
#[3,] 5 10
A.K.
- Original Message -
From: Andras Farkas
To: r-help@r-project.org
Cc:
Sent: Wednesday, March 20, 2013 5:53 PM
Subject: [R] remove specific number of rows from a matrix
Dear All,
sorry, got stuck
dat2<-as.data.frame(matrix(1:20,ncol=5))
colnames(dat2)<- c("aa","dummy1","dummy2","bb","cc")
paste(colnames(dat2),collapse="+")
#[1] "aa+dummy1+dummy2+bb+cc"
A.K.
- Original Message -
From: "Yuan, Rebecca"
To: R help
Cc:
Sent: Thursday, March 21, 2013 11:15 AM
Subject: [R] easy wa
ol(c(3,2)) and see if that helps. (not tested)
A.K.
____
From: Vera Costa
To: arun
Sent: Thursday, March 21, 2013 11:24 AM
Subject: Re: new question
Hi.
Thank you your help and sorry only answer now.
Ok, the boxplots is ok. But I need too by group... on par(mfrow(c(2,2))), I can
names(new.list),function(x) lapply(new.list[x],function(y)
boxplot(FDR~z,data=y,xlab="Charge",ylab="FDR",main=x)))
}
z.boxplot(ListFacGroup)
pdf("Veraboxplot.pdf")
z.boxplot(ListFacGroup)
z.boxplotgroup(ListFacGroup)
Joining by: Seq, Mod, z, score, FDR, Count, E, C, po
12-06-22)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached ba
Hi,
set.seed(45)
test1<-data.frame(columnA=rnorm(7,45),columnB=rnorm(7,10)) #used an example
probably similar to your actual data
apply(test1,2,function(x) sprintf("%.1f",median(x)))
#columnA columnB
# "44.5" "10.2"
par(mfrow=c(1,2))
lapply(test1,function(x) {b<-
boxplot(x,range=0,horizontal=T
Hi,
Just a modified version with colnames as titles
set.seed(45)
test1<-data.frame(columnA=rnorm(7,45),columnB=rnorm(7,10))
par(mfrow=c(1,2))
lapply(seq_len(ncol(test1)),function(i) {b<-
boxplot(test1[,i],range=0,horizontal=TRUE,main=colnames(test1[i]),
boxwex=0.5); mtext(sprintf("%.1f",b$s
.7737809 0.000 0.03 0.03 0.15 0.20 0.1 0.4 0.6458095 17
# EN BH BL AH AL
#1 11.77746 0.12159579 0.3846999 0.09567271 0.03198315
#2 16.20665 0.09819012 0.2550532 0.09581478 0.04088503
#3 11.59196 0.15166360 0.3943098 0.08405337 0.05317206
#4 13.90488 0.140316
___
From: eliza botto
To: "smartpink...@yahoo.com"
Sent: Friday, March 22, 2013 8:26 AM
Subject:
Dear Arun,
I hope you are fine.
the attached text file has my recent question and excel file contains the
data.
thanks in advance
Elisa
_
494 0.07470420 0.05284197
#2 11.38388 0.1694641 0.3624458 0.07208597 0.06036395
A.K.
From: Zjoanna
To: r-help@r-project.org
Sent: Friday, March 22, 2013 3:54 PM
Subject: Re: [R] Reading dataset in R
Hi,
I also need to read this format of file in R, it is a
HI,
Try this:
set.seed(15)
lst<-
list(matrix(sample(1:15,20,replace=TRUE),ncol=5),matrix(sample(4:20,20,replace=TRUE),ncol=5),matrix(sample(8:25,20,replace=TRUE),ncol=5))
library(abind)
arr1<-abind(lst,along=3)
apply(arr1,c(1,2),median)
# [,1] [,2] [,3] [,4] [,5]
#[1,] 17 13 19 12 7
Hi,
Try this:
Vec[grepl("\\(",Vec)]<-paste0("-",gsub("[()]","",Vec[grepl("\\(",Vec)]))
as.numeric(Vec)
# [1] 0.036578077 -1.097386482 -0.812507787 0.577806996 -0.452456601
#[6] -1.890081260 -1.871609376 0.005521704 -0.476919233 -2.413301888
A.K.
- Original Message -
From: Christofer
.07718537 0.1865207 0.08079875 0.02243240
#2 20.18355 0.07718537 0.1865207 0.08079875 0.02243240
#3 18.55295 0.08482219 0.1996013 0.09569044 0.03361565
#4 18.55295 0.08482219 0.1996013 0.09569044 0.03361565
#5 18.55295 0.19596330 0.1996013 0.04906038 0.03361565
#6 18.55295 0.19596330 0.1996013 0.
#33 25 16.42697 0.1201138 0.1933632 0.09321455 0.03367957
#35 25 16.42697 0.1553998 0.1933632 0.06490110 0.03367957
A.K.
From: Joanna Zhang
To: arun
Sent: Monday, March 25, 2013 12:13 PM
Subject: Re: Read text file in R
Great! When I tried to extract the min of
Hi,
You could also try:
library(plyr)
df1<- df
df2<- df
df$y<-revalue(df$y,c("e"="others","f"="others","g"="others"))
df$y
#[1] a b c d others others others
#or
df1$y<-mapvalues(df1$y,from=c("e","f","g"),to=rep("others",3))
levels(df1$y)
#[1] "a" "b" "c" "d"
K.
From: eliza botto
To: "smartpink...@yahoo.com"
Sent: Monday, March 25, 2013 3:50 AM
Subject: RE: Distance calculation
Dear Arun,
I have a slight problem with this coding for the calculation of distance
matrix. The text files contains that prob
Hi,
library(plyr)
df1<-count(df)
rep(df1[,1],df1[,2]*100)
count(as.character(rep(df1[,1],df1[,2]*100)))
# x freq
#1 A 200
#2 B 200
#3 C 200
#4 D 400
#5 F 400
A.K.
- Original Message -
From: Katherine Gobin
To: r-help@r-project.org
Cc:
Sent: Tuesday, March 26, 2013 4:12 AM
Subjec
HI,
You could also try this:
set.seed(25)
values1<-rnorm(10)
values2<-rnorm(10)
values3<-rnorm(10)
mycombos<-expand.grid(1:10,1:10,1:10,1:10)
mycombos1<- mycombos
mycombos<-mycombos[!(mycombos$Var1 == mycombos$Var2),]
mycombos<-mycombos[!(mycombos$Var1 == mycombos$Var3),]
mycombos<-mycombos[!(m
r system elapsed
# 1.684 0.000 1.688
system.time(sumNew1<-rowSums(sapply(mycombos2,function(x) values1[x])))
# user system elapsed
# 0.561 0.024 0.585
A.K.
- Original Message -
From: arun
To: Dimitri Liakhovitski
Cc: R help ; Jorge I Velez
Sent: Tuesday, March 26
6834 0.000
#2 0. 0. 0. 611.1167 0.000
#3 0. 0. 0. 854.3765 0.000
#4 857.6834 611.1167 854.3765 0. 579.756
#5 0. 0. 0. 579.7560 0.000
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
If the OP wanted a list output and if the data is what it looks like, may be
this helps.
dat1<-read.table(text="
ID Prod1 Prod2 Prod3 Prod4 Prod5
01 A - B - C
02 - F - G -
03 H - -
00
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
Sent: Tuesday, March 26, 2013 1:53 PM
Subject: RE: a similar question
Dear Arun,
Few day ago I asked a question about Subtracted the data in row in a special
format.
Peak1
f separating the significant from others ( x1[2,5]<- 8).
lst3<-lapply(lst2,function(x)
{x1<-list(x[!x[,1]<0.05,],x[x[,1]<0.05,]);names(x1)<-rep(colnames(x),each=2);x1})
lst3[[5]]
#$Counts_a2c3
#[1] 1 1 1 1 1
#$Counts_a2c3
#[1] 0.01963066
A.K.
From: Vera Costa
Hi,
You could try:
dat1<- read.table(text="
a b c d
TRUE TRUE TRUE TRUE
FALSE FALSE FALSE TRUE
FALSE TRUE FALSE FALSE
",sep="",header=TRUE)
dat2<-dat1
dat2[]<-t(apply(1*!dat1,1,function(x)
unlist(lapply(split(x,cumsum(c(0,abs(diff(x),cumsum
dat2
# a b c d
#1 0 0 0 0
#2
HI,
Just a correction:
:
dat2[]<-t(apply(!dat1,1,function(x)
unlist(lapply(split(x,cumsum(c(0,abs(diff(x),cumsum #should also work
A.K.
- Original Message -
From: arun
To: Camilo Mora
Cc: R help
Sent: Wednesday, March 27, 2013 9:09 AM
Subject: Re: [R] conditio
000 1.512 7.031 3.662 13.030
#2 1.512 0.000 7.109 4.880 18.731
#3 7.031 7.109 0.000 0.056 1.280
#4 3.662 4.880 0.056 0.000 0.584
#5 13.030 18.731 1.280 0.584 0.000
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
Sent: Wednesday, March
txt<- "LOI ."
gsub("[.]","%",txt)
#[1] "LOI %"
A.K.
From: Shane Carey
To: r-help@r-project.org
Sent: Wednesday, March 27, 2013 12:09 PM
Subject: [R] find and replace characters in a string
Hi,
I have a string of text as follows "LOI ."
How do I replace th
.1929718 2.9954189 0.4094026 0.000 0.8571442
#5 3.7746302 4.5442329 0.8108279 0.8571442 0.000
A.K.
From: eliza botto
To: "smartpink...@yahoo.com"
Sent: Wednesday, March 27, 2013 12:07 PM
Subject: RE: a similar question
Dear Arun,
The last
2 0 0 0 1
#z 0 0 0 0 1 0 0 0 1 0 0 0 1
dat1
# a b c d e f g h i j k l m
#w TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE
#y FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE
#z TRUE TRUE T
umsum
dat2New[rowSums(is.na(dat2New))!=0 &
rowSums(is.na(dat2New))!=ncol(dat2New),]<-NA
dat2New
# a b c d e f g h i j k l m
#w 0 0 0 0 0 1 2 3 4 0 0 0 0
#x NA NA NA NA NA NA NA NA NA NA NA NA NA
#y 1 2 3 4 5 0 0 1 2 0 0 0 1
#z 0 0 0 0 1 0 0 0 1 0 0
E TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE
#z TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE FALSE
#u TRUE TRUE FALSE FALSE NA NA TRUE FALSE NA TRUE FALSE FALSE TRUE
A.K.
- Original Message -
From: Camilo Mora
To: arun
Cc: R help
Sent: W
47
#2 16831727 -27356539 -18408896
# Trans_no.10.Sell.USD Trans_no.11.Buy.CHF Trans_no.12.Sell.USD
#1 -48273317 5435002 -4647643
#2 -54892776 5652627 -5279506
# Trans_no.13.Sell.USD
#1
1-n_acPro/ 3 0 0 1 0
#24 aAADGDDSLYPIAVLIDELR 1-n_acPro/ 2 0 0 1 0
2nd question: I am not sure I understand it correctly.
A.K.
From: Vera Costa
To: arun
Sent: Wednesday, March 27, 2013 7:07 PM
Subject: Re: new question
Hi.
With
Hi Katherine,
May be this helps:
df[!duplicated(lapply(df,summary))]
# id x y z
#1 1 15 36 D
#2 2 21 38 B
#3 3 14 55 A
#4 4 21 11 F
#5 5 14 5 H
#6 6 38 18 P
#or
df[,colnames(unique(as.matrix(df),MARGIN=2))]
# id x y z
#1 1 15 36 D
#2 2 21 38 B
#3 3 14 55 A
#4 4 21 11 F
#5 5 14
Hi,
Try this:
Spec <- function(lista,FDR_k) {
list.new<-lapply(lista,function(x) within(x,{spec<- as.character(spec)}))
split.list<-split(list.new,names(lista))
#Data needed with FDR
To: arun
Sent: Thursday, March 28, 2013 9:43 AM
Subject: Re: new question
I don't
16.073 0.086514 0.19448 0.092756 0.038431
#3 15.607 0.131028 0.18599 0.064031 0.042514
#4 15.607 0.131028 0.18599 0.064031 0.042514
#5 15.140 0.193348 0.19418 0.043383 0.039667
#6 15.140 0.193348 0.19418 0.043383 0.039667
A.K.
From: Joanna Zhang
T
o: arun
Sen
HI,
Just a correction:
indx<-rep(rep(c(TRUE,FALSE),each=2),23)
A.K.
- Original Message -
From: arun
To: Joanna Zhang
Cc: R help
Sent: Thursday, March 28, 2013 11:38 AM
Subject: Re: [R] Read text file in R
con<-file("RRoutall.txt")
Lines1<- readLines(con)
close
help
Sent: Thursday, March 28, 2013 10:18 AM
Subject: Re: [R] new question
Hi,
Try this:
Spec <- function(lista,FDR_k) {
list.new<-lapply(lista,function(x) within(x,{spec<- as.character(spec)}))
split.list<-split(list.new,names(lista))
#Data needed with FDR
To: arun
Sent: Th
NS NA 0.3173105
#2 NS NA 0.3173105
# V5.Count_c2t2_Flag V6.Count_c3t2 V6.Count_c3t2_Flag
#1 NS 0.3173105 NS
#2 NS 0.3173105 NS
A.K.
- Original Message -
From
Hi Arun,
Do you know if there is a way to change font size in R editor? The font size is
so small
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting
4 0 0 0
#2 4 4 0 1 0
#3 4 4 0 2 0
#4 4 4 0 3 0
#5 4 4 0 4 0
#6 4 4 1 0 1
Also, just by looking at your code, you have "flag" and "flap".
A.K.
____
From: Joanna Zhang
To: arun
Sent: Friday, March 29,
Forgot:
colnames(final)<- c("m1","n1","x1","y1")
before;
final1<-within(final,{flag<-ifelse(x1/m1>y1/n1, 1,0)})
- Original Message -
From: arun
To: Joanna Zhang
Cc: R help
Sent: Friday, March 29, 2013 1:47 PM
Subject: Re: if clause
Yes, that is better.
I just copied the same function that the OP used.
A.K.
From: David Winsemius
To: arun
Cc: Joanna Zhang ; R help
Sent: Friday, March 29, 2013 4:46 PM
Subject: Re: [R] if clause in data frame
On Mar 29, 2013, at 10:47 AM, arun
;n",lty=1,sub=i,main="Seasonal Flux Sum",
xlab="Calendar Year Timesteps",ylab="Total Flux (kg/season)");
matlines(x[,1],x[,-1],type="l",lty=1:2,lwd=1,col=1:2)})
dev.off()
A.K.
From: Irucka Embry
To: smartpink...
l(lst1,type="full")
head(join_all(lst1,type="full"))
# m1 n1 x1 y1 flag P12 P11 p12 p11
#1 4 4 0 0 0 0.00 0.00 NA NA
#2 4 4 0 1 0 0.25 0.00 NA NA
#3 4 4 0 2 0 0.50 0.00 NA NA
#4 4 4 0 3 0 0.75 0.00 NA NA
#5 4 4 0 4 0 1.00 0.00 NA
Hi Adam,
I hope this is what you wanted:
dat1<- read.csv("example.csv",sep="\t",stringsAsFactors=FALSE)
str(dat1)
#'data.frame': 102 obs. of 5 variables:
# $ species : chr "B. barbastrellus" "E. nilssonii" "H. savii" "M. alcathoe"
...
# $ period : chr "dusk" "dusk" "dusk" "dusk" ...
# $
Hi,
1*is.na(match(scm,c("keine"," ")))
# [1] 0 0 0 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1
#or
1*(!scm%in%c("keine"," "))
#[1] 0 0 0 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1
A.K.
- Original Message -
From: Hermann Norpois
To: r-help@r-project.org
Cc:
Sent: Friday, March 29, 2013 3:01 PM
Subject:
Hi,
Not sure if this is what you wanted:
activity<-
data.frame(Name=paste0("activity",LETTERS[1:5]),stringsAsFactors=FALSE)
dates1<-
data.frame(dat=as.Date(c("2013-02-01","2013-02-04","2013-02-05"),format="%Y-%m-%d"))
merge(dates1,activity)
# dat Name
#1 2013-02-01 activityA
#2 2
gsub("\\,.*","",x)
#[1] "foo" "bar" "qux"
A.K.
- Original Message -
From: Gundala Viswanath
To: "r-h...@stat.math.ethz.ch"
Cc:
Sent: Monday, April 1, 2013 10:13 PM
Subject: [R] How to remove all characters after comma in R
I have the following list of strings:
x <- c("foo, foo2, foo
Hi,
May be this helps.
list.files()
#[1] "file1.txt" "file2.txt" "file3.txt"
lapply(list.files(),function(x)
{x1<-read.table(x,header=TRUE);x2<-gsub("txt","png",x);png(x2);plot(col2~col1,data=x1,type="l");dev.off()})
A.K.
- Original Message -
From: David Lyon
To: "r-help@r-project.or
801 - 900 of 3327 matches
Mail list logo