[1:3], pch=1, col=1:3)
A.K.
On Friday, December 5, 2014 5:45 PM, farnoosh sheikhi
wrote:
Hi Arun,
I hope you are doing well.
I have a data set as follow:
my.df <- data.frame(ID=rep(c("A","B","C"), 5), TIME=rep(1:5, each=3), X=1:5)
I would like to get a scat
Hi Juvin,
The error "dim(X) must have a positive length" usually shows when you are
passing a vector to "apply", ie.
apply(1:5,2,mean)
#Error in apply(1:5, 2, mean) : dim(X) must have a positive length
Also, if your dataset originally has "1206" columns, it is not clear why you
n
Try
indx <- which(!!mat, arr.ind=TRUE)
v1 <-unname(sapply(split(indx[,2], indx[,1]),toString))
cat(paste(v1, collapse="\n"), sep="\n")
1, 2, 3, 6, 7, 8, 9
1, 2, 3, 6, 8, 9
1, 3, 4, 6, 7, 8, 9
1, 8
1, 3, 6, 7, 8, 9
1, 3, 4, 6, 8, 9
1, 3, 5, 9
A.K.
Hi,
Is there a way to map data from Bina
by = ID], ID+Visit~ Diff, value.var='Diff', length)
ID Visit 136 255 857
1: 1 2 1 0 0
2: 2 3 0 1 1
On Wednesday, February 11, 2015 5:47 PM, farnoosh sheikhi
wrote:
Hi Arun,
I have a data set that look s like below. I wanted to get a
Or
rapply(l,function(x) x[1])
#[1] 1 3 7
set.seed(42)
l1 <- replicate(1e6, list(sample(1:5,sample(8),replace=T)))
system.time(r1 <- sapply(l1, `[`, 1))
# user system elapsed
# 1.324 0.000 1.326
system.time(r2 <- rapply(l1, function(x) x[1]))
# user system elapsed
# 0.736 0.004
Hi,
If `dat` is the dataset:
dat[!(dat$ID==2 & as.numeric(gsub("-.*","",dat$Month))<5),]
ID Month Value
1 1 03-2014 1
2 1 04-2014 10
3 1 05-2014 50
6 2 05-2014 4
7 2 06-2014 2
A.K.
hello together, i have a short question, maybe you can help me.
I have a data.frame li
Try:
rbind(v2,unname(setNames(v1[,1],v1[,2])[v2]))
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
v2 "a" "a" "a" "a" "a" "c" "c" "c" "c" "c" "c" "c" "c" "c"
"1" "1" "1" "1" "1" "3" "3" "3" "3" "3" "3" "3" "3" "3"
[,15] [,16]
Not able to reproduce the problem.
str(q)
# POSIXlt[1:1], format: "2014-03-09 02:00:00"
is.na(q)
#[1] FALSE
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-unknown-linux-gnu (64-bit)
A.K.
On Wednesday, July 30, 2014 1:10 PM, John McKown
wrote:
"I'm so confused!" Why does is.na()
For the example, you gave:
x ##dataset
indx <- t(sapply(min(x$MTH_SUPPORT):(max(x$MTH_SUPPORT) - 2), function(x) c(x,
x +
2)))
res <- do.call(rbind, apply(indx, 1, function(.indx) {
x1 <- x[x$MTH_SUPPORT >= .indx[1] & x$MTH_SUPPORT <= .indx[2], ]
Period <- paste(.indx[1], .indx[2],
1 0.4617737
13 CB27A 201307-201309 1 0.4513274
14 CB27A 201308-201310 1 0.4613779
A.K.
On Thursday, July 31, 2014 12:34 AM, arun wrote:
For the example, you gave:
x ##dataset
indx <- t(sapply(min(x$MTH_SUPPORT):(max(x$MTH_SUPPORT) - 2), function(x) c(x,
x +
y, July 30, 2014 1:42 PM, farnoosh sheikhi
wrote:
Hi Arun,
I have two questions, I have a data like below:
dat1<-read.table(text="
Unit q1q2q3
A312
A2NA1
B224
BNA25
C32NA
C414
A32NA
",sep="",header=T,stringsAsFactors=F)
I want to get the average of each row by the numbe
If you have some variations of the order of numbers followed by chars,
library(stringr)
v1 <- c("absdfds0213451ab", "123abcs4145")
pattern=c("[A-Za-z]+", "\\d+")
do.call(`Map`,c(c,lapply(pattern, function(.pat) str_extract_all(v1, .pat
#[[1]]
#[1] "absdfds" "ab" "0213451"
#[[2]]
#[1] "
Try:
gsub(".*\\.(.*)\\..*","\\1", my.cache.list)
[1] "subject_test" "subject_train" "y_test" "y_train"
#or
library(stringr)
str_extract(my.cache.list, perl('(?<=\\.).*(?=\\.)'))
[1] "subject_test" "subject_train" "y_test" "y_train"
A.K.
On Thursday, July 31, 2014 11:05 AM,
Try:
If dat is the dataset.
library(stringr)
res <- str_extract(dat$Gene.Symbol, perl('[[:alnum:]]+(?= \\/)'))
res[!is.na(res)]
#[1] "CDH23"
A.K.
On Thursday, July 31, 2014 9:54 PM, Stephen HK Wong wrote:
Dear All,
I appreciate if you can help me out this. I have a data frame cont
Use ?split()
split(dat[,-4], dat$Year_Month) #dat is the dataset.
A.K.
Country Product Price Year_Month
AE 1 20 201204
DE 1 20 201204
CN 1 28 201204
AE 2 28 201204
DE 2
You could try:
library(stringr)
simplify2array(str_extract_all(xx, perl('(?<=[A-Z]|\\:)\\d+')))
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] "24" "24" "24" "24" "24" "24"
[2,] "57" "86" "119" "129" "138" "163"
A.K.
On Friday, August 1, 2014 10:49 AM, "Doran, Harold" wrote:
I have done an
Forgot about as.numeric.
sapply(str_extract_all(xx, perl('(?<=[A-Z]|\\:)\\d+')),as.numeric)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 24 24 24 24 24 24
[2,] 57 86 119 129 138 163
On Friday, August 1, 2014 10:59 AM, arun wrote:
You could try:
li
You could use:
library(dplyr)
library(tidyr)
x.df %>% group_by(Year, Group, Eye_Color) %>% summarize(n=n()) %>%
spread(Eye_Color,n, fill=0)
Source: local data frame [6 x 5]
Year Group blue brown green
1 2000 1 2 1 0
2 2000 2 0 0 2
3 2001 1 1
You could try data.table
#dat is the dataset
library(data.table)
v1 <- setNames(c("HT", "A", "B", "Aht", "Bht"), c("11", "10", "01", "1-", "-1"))
dat2 <- setDT(dat1)[, lapply(.SD, function(x) v1[paste(x, collapse="")]),
by=CloneID]
A.K.
On Monday, August 4, 2014 5:55 AM, raz wrote:
Dear a
You could try:
lv <- levels(unique(unlist(df)))
as.data.frame(t(apply(df, 2, function(x) table(factor(x, levels=lv)
+ - 0
i1 10 0 0
i2 10 0 0
i3 0 10 0
i4 0 9 1
i5 10 0 0
i6 1 9 0
i7 9 0 1
i8 4 2 4
i9 7 1 2
A.K.
On Tuesday, August 5, 2014 5:36 AM, Alain D. wrote:
Dear R-
You could try:
x1$V2[1] <- "TCLA1"
x[outer(rownames(x), colnames(x), FUN=paste) %in%
as.character(interaction(x1, sep=" "))] <- 1
x
TCLA1 VPS41 ABCA13 ABCA4
AKT3 1 0 0 0
AKTIP 0 1 0 0
ABCA13 0 0 0 0
ABCA4 0 0 0 0
A.
A similar post was found in stackoverflow
(http://stackoverflow.com/questions/25328311/how-to-avoid-change-string-to-number-automaticlly-in-r),
which already got an accepted reply.
A.K.
On Friday, August 15, 2014 2:18 PM, Wenlan Tian wrote:
I was trying to save some string into a matrix, bu
Hi Tom,
You could try:
library(stringr)
str_extract(x, perl("(?<=[A-Za-z]{4}/).*(?=/[0-9])"))
#[1] "S01-012"
A.K.
On Friday, August 15, 2014 12:20 PM, Tom Wright wrote:
Hi,
Can anyone please assist.
given the string
> x<-"/mnt/AO/AO Data/S01-012/120824/"
I would like to extract "S01-012"
Try:
format(as.Date("05/07/2014", "%m/%d/%Y"), "%m")
#[1] "05"
#or
strptime("05/07/2014", "%m/%d/%Y")$mon+1
#[1] 5
A.K.
How to extract a Month from Date object?
almost 13 peoples visited my Question with out replying in New to R , i have
task yaar
don't mind plz could you HELP ME
How t
Hi,
Use ?format
format(d, "%m/%d/%Y")
#[1] "09/01/2014"
A.K.
On Monday, September 1, 2014 5:26 AM, Velappan Periasamy
wrote:
d=Sys.Date()
"2014-09-01"
How to convert this "2014-09-01" to "09/01/2014" format?
(ie y-m-d to m/d/y format)
thanks
veepsirtt
If the `ids` are ordered as shown in the example, perhaps you need
tbl <- table(df$id)
rep(seq(as.Date("2000-01-01"), length.out=length(tbl), by=1), tbl)
[1] "2000-01-01" "2000-01-01" "2000-01-01" "2000-01-01" "2000-01-01"
[6] "2000-01-02" "2000-01-02" "2000-01-02" "2000-01-02"
You could try
library(dplyr)
data1 %>%
rowwise() %>%
mutate(oldflag=as.Date(max(mrjdate,cocdate, inhdate, haldate,
na.rm=TRUE), origin='1970-01-01'))
Source: local data frame [7 x 6]
Groups:
idmrjdatecocdateinhdatehaldateo
ith that warning.
data1 <- data1[rowSums(is.na(data1[,-1]))!=4,]
data1 %>%
rowwise()%>%
mutate(oldflag= as.Date(max(mrjdate, cocdate, inhdate, haldate,
na.rm=TRUE), origin='1970-01-01')
A.K.
On Sunday, November 9, 2014 9:16 AM, "Muhuri, Pradip (SAMHSA/CB
Try
range(data2$oiddate[complete.cases(data2$oiddate) & is.finite(data2$oiddate)])
#[1] "2006-09-01" "2011-11-04"
If you look at the `dput` output, it is `Inf` for oiddate
dput(data2$oiddate)
structure(c(14078, -Inf, 15260, 13796, 13392, 15252, 15282), class = "Date")
A.K.
On Monday, Nov
Hi,
Try this:
set.seed(24)
df<- data.frame(x=sample(seq(0.25,4.25,by=.05),1e5,replace=TRUE),y=
sample(seq(0.10,1.05,by=.05),1e5,replace=TRUE),z=rnorm(1e5))
#Used a shorter vector
x1<- c(1.05,2.85,3.40,4.25,0.25)
y1<- c(0.25,0.10,0.90,0.25,1.05)
res<-do.call(rbind,lapply(seq_along(x1),function
Hi,
set.seed(24)
mat1=matrix(rnorm(12),3)
set.seed(28)
mat2=matrix(rnorm(12),3)
indx<- mat1<1 & mat2<1
mat1[indx]<-NA
mat2[indx]<-NA
mat1
# [,1] [,2] [,3] [,4]
#[1,] NA NA NA 0.002311942
#[2,] NA NA NA NA
#[3,] NA NA NA 0.598269113
mat2
# [,1] [,2] [,
Hi,
May be this helps:
dat1# dataset
dat1[,2]<-gsub("\\d+$","00",dat1[,2])
dat1
# Date Time
#1 01/01/2013 00:09:00
#2 01/02/2013 00:10:00
#3 01/03/2013 00:11:00
#4 01/04/2013 00:12:00
#5 01/05/2013 00:13:00
#6 01/06/2013 00:15:00
#7 01/07/2013 00:16:00
#8 01/08/2013 00:17:00
#
t 8 of the 28 missing... the first row
missing is 3.05,1.70 . i looked up the documentation for subset but i
cant see why it would skip ones...
thanks
- Original Message -
From: arun
To: R help
Cc:
Sent: Wednesday, July 3, 2013 7:37 AM
Subject: Re: Subsetting multiple rows of a
Hi,
carbon.fit = expand.grid(list(x=seq(0, 5, 0.01), y=seq(0, 5, 0.01)))
dim(carbon.fit)
#[1] 251001 2
xtNew<-sprintf("%.2f",xt)
ytNew<- sprintf("%.2f",yt)
carbon.fit[]<- lapply(carbon.fit,function(x) sprintf("%.2f",x))
res<-do.call(rbind,lapply(seq_along(xtNew),function(i)
subset(carb
Hi,
You could try:
day<-as.Date(c("2008-04-12","2011-07-02","2011-09-02","2008-04-12","2008-04-12"))
indx<-gsub("-.*","",day)
day[indx>="2007" & indx<="2009"]
#[1] "2008-04-12" "2008-04-12" "2008-04-12"
#or
library(xts)
xt1<- xts(seq_along(day),day)
index(xt1["2007/2009"])
#[1] "2008-04-12" "200
Hi,
You could use:
d1<- data.frame(a,b)
k1<-data.frame(a=k)
library(plyr)
join(k1,d1,by="a")[,2]
#[1] 4 4 6 6 7 7 6
A.K.
- Original Message -
From: Andras Farkas
To: r-help@r-project.org
Cc:
Sent: Thursday, July 4, 2013 2:09 PM
Subject: [R] help on selecting values of an object
Dear
row.names(carbon.fit),stringsAsFactors=FALSE)
#changed here
res1<-merge(dat1,carbon.fit1,by=c("x","y"))
row.names(res1)<- res1[,3]
res1<- res1[,-3]
A.K.
- Original Message -
From: William Dunlap
To: arun ; Shaun ♥ Anika
Cc: R help
Sent: Thursday, July 4, 2013 8:0
Hi,
May be this helps:
If you had showed your solution, it would be easier to compare.
res<-data.frame(lapply(sapply(MyDF[,c(2,4)],function(x)
{x1<-which(c(0,diff(x))<0);x1[length(x1)==0]<-0;x1}),`[`,1))
res
# TNH BIX
#1 3 9
#Speed
set.seed(24)
MyDFNew<-
data.frame(TNH=sample(0:1,1e6,
Hi,
May be this helps:
dat1<- read.table(text="
P1_prom Nom
1 -6.17 Pt_00187
2 -6.17 Pt_00187
3 -6.17 Pt_00187
4 -6.17 Pt_00187
5 -6.17 Pt_00187
6 -6.17 Pt_01418
7 -5.77 Pt_01418
8 -5.37 Pt_01418
9 -4.97 Pt_01418
10 -4.57 Pt_01418
",sep="",header=TRUE,stringsAsFactors=FALSE)
library(zoo)
dat1
Hi,
May be this helps.
dat1<- read.table(text="
Col1,Col2
High value,9
Low value,0
High value,7
Low value,0
Low value,0
No data,0
High value,8
No data,0
",sep=",",header=TRUE,stringsAsFactors=FALSE)
dat1$Col2[dat1$Col1=="No data"]<- NA
dat1
# Col1 Col2
#1 High value 9
#2 Low value
Hi,
Using the example from ?geeglm()
summary(gee1)$corr
# Estimate Std.err
#alpha 0.957 0.00979
A.K.
- Original Message -
From: nt1006
To: r-help@r-project.org
Cc:
Sent: Friday, July 5, 2013 9:40 AM
Subject: [R] geeglm
How to extract the Std.err and the alpha estimated value
Hi,
You could also try ?data.table()
x<- read.table(text="a b c
1 2 3
3 3 4
2 4 5
1 3 4
",sep="",header=TRUE)
library(data.table)
xt<- data.table(xt)
setkey(xt,a)
subset(xt,b==3)
# a b c
#1: 1 3 4
#2: 3 3 4
iord <- order(x$a)
subset(x[iord, ], b == 3)
# a
Hi,
I am not sure how your dataset looks like. If it is like the one below:
(otherwise, please provide a reproducible example using ?dput())
dat1<- read.table(text="
datetime
10/02/2010
02:30
11/02/2010
04:00
14/02/2010
06:30
",sep="",header=TRUE,stringsAsFactors=FALSE)
lst1<-split(dat1,(seq_al
Hi,
vec1<- structure(c(.
vec1
#[1] -22.576608,17.07859 -24.621739,17.959728 -26.567955,18.134651
#[4] -22.832516,17.183304 -21.980459,16.91328
#43 Levels: -17.394217,15.886574 -17.406994,14.393463 ... -28.017742,18.745594
G1<-sapply(strsplit(as.character(vec1),","),`[`,1)
G2<-sapply(strsp
,1],format="%d/%m/%Y %H:%M")
head(time1)
# date
#1 2008-11-20 12:23:00
#2 2008-11-21 00:33:00
#3 2008-11-21 12:29:00
#4 2008-11-22 00:29:00
#5 2008-11-22 12:39:00
#6 2008-11-23 00:50:00
A.K.
From: laila Aranda Romero
To: arun
Sent:
Hi,
May be this helps:
gsub(".*\\w+\\s+(.*)\\s+.*","\\1",test)
#[1] "9,36" "9,36" "9,66" "9,66" "9,66" "10,04" "10,04" "10,04" "6,13"
#[10] "6,13" "6,13"
A.K.
- Original Message -
From: PIKAL Petr
To: r-help
Cc:
Sent: Tuesday, July 9, 2013 5:45 AM
Subject: [R] regular expre
Hi,
May be this helps:
gsub("_"," ",gsub("(.*)_.*","\\1",DATA_names))
#[1] "A ugkg" "S mgkg" "Cl mgkg"
sapply(gsub("_"," ",gsub("(.*)_.*","\\1",DATA_names)),f)
$`A ugkg`
A ~ (mu * g ~ kg^{
-1
})
$`S mgkg`
S ~ (mg ~ kg^{
-1
})
$`Cl mgkg`
Cl ~ (mg ~ kg^{
-1
})
A.K.
- Original
se(text=gsub("_"," ",gsub(pattern,"~(.(\\1))~",name)))[[1]]
do.call(bquote, list(bquoteExpr, env))
}
sapply(DATA_names,f1)
$A_ugkg_FA
A ~ (mu * g ~ kg^{
-1
}) ~ FA
$S_mgkg_XRF
S ~ (mg ~ kg^{
-1
}) ~ XRF
$Cl_mgkg_XR
Cl ~ (mg ~ kg^{
-1
}) ~ XR
A.K.
_
Hi,
?kruskal.test()
a<- c(2,4,5,2,7)
b<- c(2,2,6)
c<- c(3,7,9,3)
kruskal.test(list(a,b,c))
#
# Kruskal-Wallis rank sum test
#
#data: list(a, b, c)
#Kruskal-Wallis chi-squared = 2.003, df = 2, p-value = 0.3673
A.K.
Hi
I need an expression in R to apply a kruskal.test to this data (for exa
Hi
You could use:
gsub("([[:alnum:]]+-)([[:alnum:]]+-)(.*)","\\1\\2zzz",name)
#[1] "hsa-miR-zzz" "hsa-miR-zzz" "hsa-let-zzz"
A.K.
- Original Message -
From: Gundala Viswanath
To: "r-h...@stat.math.ethz.ch"
Cc:
Sent: Wednesday, July 10, 2013 3:02 AM
Subject: [R] Replacing part of del
231, df = 2, p-value = 0.9403
A.K.
____
From: Vera Costa
To: arun
Sent: Wednesday, July 10, 2013 6:38 AM
Subject: Re: Kruskal.test
Thank you.
And if I have
a a a a a b b b c c c c
2 4 5 2 7 2 2 6 3 7 9 3
3 3
t.org
Cc:
Sent: Wednesday, July 10, 2013 1:48 AM
Subject: Re: [R] Filter Dataframe for Alarm for particular column(s).
Hi Arun,
Thanks for the solution it really works !. But how can we avoid even lappy()
and sappy().
Actually any way to do with ts() ?
Thanks,
Antony.
From: arun
Hi,
You could try:
mat1<-matrix(dat3[rowSums(dat3[,2:3])!=dat3[,4],1],ncol=1,dimnames=list(NULL,"MW_EEsDue_ERRORS"))
mat1
# MW_EEsDue_ERRORS
#[1,] 1882
#[2,] 1884
#[3,] 1885
A.K.
#Let's say I have the following data set:
dat3 = data.frame(A_CaseID = c(
cation"
#[6] "end_location"
A.K.
From: laila Aranda Romero
To: arun
Sent: Wednesday, July 10, 2013 6:21 PM
Subject: RE: [R] Need hep for converting date data in POSIXct
Hi,
The code:
library(argosfilter)
setwd("C:/Users/Usuario/
Hi,
May be this helps:
dat1<- read.table(text="
ID date
1 4/12/2008
1 4/13/2008
1 5/11/2008
2 3/21/2009
2 4/22/2009
2 8/05/2009
",sep="",header=TRUE,stringsAsFactors=FALSE)
library(mondate)
M1<- mondate(dat1[,2])
M2<- mondate("01/01/2008")
dat1$month<-as.numeric(abs(floor(MonthsBetween(M1,M2
Hi,
May be this helps:
dat1<- read.table(text="
142,QUANTIZE_CAL_MIN_BAND_10,1
143,QUANTIZE_CAL_MAX_BAND_11,65535
144,QUANTIZE_CAL_MIN_BAND_11,1
145,END_GROUP,MIN_MAX_PIXEL_VALUE
146,GROUP,RADIOMETRIC_RESCALING
147,RADIANCE_MULT_BAND_1,1.2483E-02
148,RADIANCE_MULT_BAND_2,1.2730E-02
",sep=",",header
Hi,
Try this:
files1<-read.csv("files.csv",header=TRUE,stringsAsFactors=FALSE)
str(files1)
#'data.frame': 2 obs. of 2 variables:
# $ Col1: chr "ANA110915004A_3PERIOD_TmAvg-rdata.csv"
"ANA110915006A_3PERIOD_TmAvg-rdata.csv"
# $ Col2: chr "Pre-DA" "DA-10^-6"
files1
#
Hi,
May be this helps:
require(MASS)
require(ggplot2)
iris.lda<-lda(Species ~ Sepal.Length + Sepal.Width + Petal.Length +
Petal.Width, data = iris)
datPred<-data.frame(Species=predict(iris.lda)$class,predict(iris.lda)$x)
library(ellipse)
dat_ell <- data.frame()
for(g in levels(datPred$Species))
Hi,
No problem.
The default should be 0.95
?ellipse()
level: The confidence level of a pairwise confidence region. The
default is 0.95, for a 95% region. This is used to control
the size of the ellipse being plotted. A vector of levels
may be used.
A.K.
- O
hursday, July 11, 2013 3:54 PM
Subject: Re: [R] create new matrix from user-defined function
Dan and Arun, thank you very much for your replies. They are both very helpful
and I love to get different versions of an answer so I can learn more R code.
You both used indexing to refer to the col
ombie, Burnette N"
To: arun
Cc: R help
Sent: Thursday, July 11, 2013 4:40 PM
Subject: RE: [R] create new matrix from user-defined function
You understood me perfectly, and I agree is it easier to index using numbers
than names. I'm just afraid if my dataset gets too big I'll mess up
HI,
Try this:
set.seed(485)
dat1<- as.data.frame(matrix(sample(0:10,26*10,replace=TRUE),ncol=26))
mean(dat1$V21[dat1$V2==1|dat1$V2==0])
#[1] 3.8
#or
with(dat1,mean(V21[V2==1|V2==0]))
#[1] 3.8
A.K.
I have data in 26 columns, I'm trying to get a mean for column 21 only for the
participants that
A.K.
What values would I substitute by real data. I did everything the way
you posted, and I got 3.8 as well. So I'm curious what values I would
change to get the mean for the actual data?
- Original Message -
From: arun
To: R help
Cc:
Sent: Thursday, July 11, 2013 9:21 PM
Hi,
apple<- read.table(text="
Fam.name,Item,AMT.SALE.NET.PROMO,X.CY..QTY.SALE.TOT
9475,Imported Fruits,22110276001,0,436
9499,Imported Fruits,22110277001,0,236
9523,Imported Fruits,22110278001,0,71
",sep=",",header=TRUE,stringsAsFactors=FALSE)
str(apple)
#'data.frame': 3 obs. of 4 variables:
Hi,
Try:
set.seed(41)
vec1<- sample(1:50,12000,replace=TRUE)
tail(vec1,-1000)
length(tail(vec1,-1000))
#[1] 11000
A.K.
- Original Message -
From: Olivier Charansonney
To: r-help@r-project.org
Cc:
Sent: Friday, July 12, 2013 6:06 AM
Subject: [R] Needing help for excluding vector elem
know is
too high to be the mean for this data set.
Thanks
- Original Message -
From: arun
To: R help
Cc:
Sent: Friday, July 12, 2013 8:21 AM
Subject: Re: Help with IF command strings
Hi,
Not sure I understand your question.
Suppose `data1` is your real data, but if the column na
Hi,
library(car)
recode(x,"'x'=1;'y'=2;'z'=3")
#[1] 1 1 1 2 2 2 3 3 3
#or
as.numeric(factor(x))
#[1] 1 1 1 2 2 2 3 3 3
A.K.
- Original Message -
From: Trevor Davies
To: "r-help@r-project.org"
Cc:
Sent: Friday, July 12, 2013 5:56 PM
Subject: Re: [R] replace multiple values in vector
_EEsDueTotal
# 1 1881 2 5 7
# 2 1882 2 5 9
# 3 1883 1 4 5
# 4 1884 4 1 6
# 5 1885 6 6 112
From: arun k
Hi,
May be this helps:
dat1<- read.table(text="
ID county date company
1 x 1 comp1
2 y 1 comp3
3 y 2 comp1
4 y 3 comp1
5 x 2 comp2
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat2<- dat1
dat1$answer<-unsplit(lap
Hi,
as.integer(dat$COUNTRY) # would be the easiest (Rui's solution).
Other options could be also used:
library(plyr)
as.integer(mapvalues(dat$COUNTRY,levels(dat$COUNTRY),seq(length(levels(dat$COUNTRY)
# [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4
#or
match(dat$COUNTRY,levels(dat$COUNTRY))
Hi,
"when the value of Debut of lines i = value Fin of lines i-1"
That part is not clear esp. when it is looked upon with the expected output
(df2). Also, in your example dataset:
df1$contrat[grep("^CDD",df1$contrat)]
#[1] "CDD détaché ext. Cirad" "CDD détaché ext. Cirad" "CDD détaché ext. Cirad
I tried it on a slightly bigger dataset:
A1 <- matrix(t(expand.grid(1:90, 15, 16)), nrow = 3)
B1 <- combn(90, 3)
which(is.element(columnsOf(B1), columnsOf(A1)))
# [1] 1067 4895 8636 12291 15861 19347 22750 26071 29311 32471 35552 38555
#[13] 41481
which(apply(t(B1),1,paste,collapse="")%in%appl
Hi,
One way would be:
which(apply(t(B),1,paste,collapse="")%in%apply(t(A),1,paste,collapse=""))
#[1] 105 196 274 340 395
B[,105]
#[1] 1 15 16
B[,196]
#[1] 2 15 16
B1<-B[,!apply(t(B),1,paste,collapse="")%in%apply(t(A),1,paste,collapse="")]
dim(B1)
#[1] 3 555
dim(B)
#[1] 3 560
#or
B2<-B[,
Hi,
May be this helps:
dat1<- read.table(text="
Country, Pet
France, Dog
France, Cat
France, Dog
Canada, Cat
Canada, Cat
Japan, Dog
Japan, Cat
Italy, Cat
",sep=",",header=TRUE,stringsAsFactors=FALSE)
dat1[with(dat1,as.numeric(ave(Pet,Country,FUN=function(x)
length(unique(x)>1,]
# Country
library(plyr)
M.1[,1:2]<-do.call(rbind,alply(replicate(3,M.2),3,function(x) x))
#or
M.1[,1:2]<-matrix(aperm(replicate(3,M.2),c(1,3,2)),ncol=2)
A.K.
- Original Message -
From: Thiem Alrik
To: "mailman, r-help"
Cc:
Sent: Sunday, July 14, 2013 9:48 AM
Subject: [R] Matrix column flip
Hi,
You could try this: (if I understand it correctly)
dat1<- read.table(text="
year id var ans
2010 1 1 1
2010 2 0 0
2010 1 0 1
2010 1 0 1
2011 2 1 1
2011 2 0 1
2011 1 0 0
2011 1 0 0
",sep="",header=TRUE,stringsAsFactors=FALSE)
dat1$newres<-with(dat1,ave(var,id,ye
01/09/1995 29/02/2000
1 26/01/1995 31/08/2001
2 05/09/2012 31/12/2013
3 01/09/2004 31/08/2007
7 01/09/2001 31/08/2004
8 01/09/2007 04/09/2012
A.K.
From: Arnaud Michel
To: arun
Cc: R help ; jholt...@gmail.com; Rui Barradas
Sent: Sunday, July 14
meric(factor(Geo$confianza))
with(Geo, plot(long,lat.comp,col=col1))
A.K.
From: laila Aranda Romero
To: arun
Sent: Sunday, July 14, 2013 3:28 PM
Subject: RE: [R] Need hep for converting date data in POSIXct
Arun,
I contact you again because I have ano
in,1),stringsAsFactors=FALSE)))}))
row.names(res)<- 1:nrow(res)
df2[11,8]<- "31/12/2013"
names(res)[1]<- "Mat"
identical(res,df2)
#[1] TRUE
A.K.
- Original Message -
From: arun
To: Arnaud Michel
Cc: R help
Sent: Sunday, July 14, 2013 2:39 PM
Subject
Hi,
Not sure about the format for the 2nd part.
df1<- ##data
library(plyr)
df2<-ddply(df1,.(name,cat),summarize,
cbind(t.test(val,df1$val)$statistic,t.test(val,df1$val)$p.value))
df3<-cbind(df2[,1:2],data.frame(df2[,3]))
colnames(df3)[3:4]<- c("t-val","p.val")
library(reshape2)
df3m<- melt(df3
Hi,
May be I misunderstood ur question.
The output David got could be also obtained by:
#df1 dataset
library(plyr)
df2<-ddply(df1,.(cat),function(x) if(min(table(x$name))>1){x1<-
t.test(val~name,x);cbind(t=x1$statistic,p.value=x1$p.value)})
df2
# cat t p.value
#1 p17826658
Hi,
May be this also works.
basename(file_path_sans_ext("/the/path/to/afile.txt"))
#[1] "afile"
A.K.
- Original Message -
From: Rui Barradas
To: Witold E Wolski
Cc: r-help@r-project.org
Sent: Monday, July 15, 2013 10:32 AM
Subject: Re: [R] file.stem?
Hello,
You can use ?basename to
HI Irucka,
May be this is what you wanted:
pat<-paste(paste0("http://www.",siter[,1],"..rdb";),collapse="|")
pat
[1]
"http://www.02437100..rdb|http://www.02439500..rdb|http://www.02441500..rdb|http://www.02446500..rdb|http://www.02467000..rdb|
---
#or
pat1<-paste("http://www.";, siter[,1], "..rdb", sep="", collapse = "|")
identical(pat,pat1)
#[1] TRUE
A.K.
- Original Message -
From: arun
To: Irucka Embry
Cc: R help
Sent: Monday, July 15, 2013 2:47 PM
Subject: Re: converti
Hi,
If I understand it correctly,
df1<- read.table(text="
sample1 sample2 sample3 sample4 sample5
a P P I P P
b P A P P A
c P P P P P
d P P P P P
e M P M A P
f P P P P P
g P P P A P
h P P P P P
",sep="",header=TRUE,stringsAsFactors=FALSE)
df1[rowSums(df1=="P")==ncol(df1),]
# sample1 samp
))=="P") ), ])
# user system elapsed
#351.492 0.040 352.164
row.names(res2)<- row.names(res3)
attr(res3,"row.names")<- attr(res2,"row.names")
identical(res2,res3)
#[1] TRUE
A.K.
- Original Message -
From: arun
To: Chirag Gupta
Cc: R help
Se
HI,
2-0.7==0.3
#[1] FALSE
##May be u meant
2-0.7==1.3
#[1] TRUE
Possibly R FAQ 7.31
Also, check
http://rwiki.sciviews.org/doku.php?id=misc:r_accuracy
all.equal(2-0.7,1.3)
#[1] TRUE
all.equal(1-0.7,0.3)
#[1] TRUE
(1-0.7)<(0.3+.Machine$double.eps^0.5)
#[1] TRUE
p <- c(0.2, 0.4, 0.6, 0.8, 1)
HI,
?as.integer() #documentation
Note that current implementations of R use 32-bit integers for
integer vectors, so the range of representable integers is
restricted to about +/-2*10^9: ‘double’s can hold much larger
integers exactly.
as.numeric(c(75533, 4756922556, 88210, 67151221
HI,
Try:
x1<-scale(x,center=TRUE,scale=TRUE)
str(x1)
# num [1:15, 1:10] -0.2371 -0.5606 -0.8242 1.5985 -0.0164 ...
# - attr(*, "scaled:center")= num [1:10] 50.2 50 49.8 49.8 50.3 ...
#- attr(*, "scaled:scale")= num [1:10] 1.109 0.956 0.817 0.746 1.019 ...
attr(x1,"scaled:center")<-NULL
attr(x1,
is.numeric(center))
# attr(x, "scaled:center") <- center
#if (is.numeric(scale))
# attr(x, "scaled:scale") <- scale
x
}
x2<-scale1(x,center=TRUE,scale=TRUE)
str(x2)
# num [1:15, 1:10] -0.2371 -0.5606 -0.8242 1.5985 -0.0164 ...
identical(x1,x2)
#[1] T
HI,
May be this helps:
printer1<- file("out1.txt","w")
write(sprintf("This is line %d.\n",1),printer1,append=TRUE)
write("This is line 2",printer1,append=TRUE)
close(printer1)
#or
printer1<- file("out1.txt","w")
writeLines("This is line",con=printer1,sep="\n")
writeLines("This is line 2",con=p
Hi,
YOu could try.
?split()
split(ats,ats$Project_NBR)
You also mentioned about two columns.
split(ats,list(ats$col1, ats$col2))
You should have provided an example dataset using ?dput() ( dput(head(data,10))
) for testing.
Also,
gsub("^-[^-]*-","","-005-190")
#[1] "190"
A.K.
Problem: I hav
at is I may write something to a file.
And then I want to add to the same line a new string:
" The same line." Like this.
printer = file("out.txt","w")
write(sprintf("This is line %d.",1),printer,append=T)
write(" The same line.",printer,append=T
xample that's similar to what I have:
project boro
123 m
134 k
123 m
123 m
543 q
543 q
134 k
Basically I am trying to subset the data frame according to
project and boro with the name of the subset being boro-project (ex.
m123, k134)
I hope this provid
Arnaud Michel
To: Rui Barradas ; R help ; arun
Cc:
Sent: Wednesday, July 17, 2013 4:03 PM
Subject: Re: [R] simplify a dataframe
Thank you for the question (1)
Sorry for the imprecision for the question (2) :
Suppose the date frame df
df1 <- data.frame(
Debut =c ( "24/01/1995", "
96
A.K.
- Original Message -
From: arun
To: Arnaud Michel
Cc: R help ; Rui Barradas
Sent: Wednesday, July 17, 2013 4:14 PM
Subject: Re: [R] simplify a dataframe
Hi,
You could try:
df1[,1:2]<-lapply(df1[,1:2],as.character)
df2New<- data.frame(Deb=unique(with(df1,ave(Debut,INDX,FU
HI,
Not sure whether this is what you wanted.
vec1<- 1:7
fun1<- function(x,nr) {((x-1)%/%nr)+1}
fun1(vec1,2)
#[1] 1 1 2 2 3 3 4
fun1(vec1,3)
#[1] 1 1 1 2 2 2 3
split(vec1,fun1(vec1,2))
A.K.
- Original Message -
From: Witold E Wolski
To: r-help@r-project.org
Cc:
Sent: Wednesday,
Sorry, there was a mistake:
fun1 should be:
fun1<- function(x,nr) {((seq_along(x)-1)%/%nr)+1}
vec3<- c(4,5,7,9,8,5)
fun1(vec3,2)
#[1] 1 1 2 2 3 3
split(vec3,fun1(vec3,2))
A.K.
- Original Message -
From: arun
To: Witold E Wolski
Cc: R help
Sent: Wednesday, July 17, 2013 6
Hi,
Not sure if this is what you wanted:
#If columns are arranged in the same order in both data.frames.
lst1<-lapply(seq_len(ncol(StatsUTAH)),function(i)
{x1<-cbind(StatsUTAH[,i],sStatsUTAH[,i]);row.names(x1)<-row.names(StatsUTAH);colnames(x1)<-c("zeroNO","zeroYES");x1})
names(lst1)<- colnames(
Hi,
m1<- matrix(NA,5,5)
m1[upper.tri(m1)]<-c(2,3,8,4,9,14,5,10,15,20)
One way would be:
m1[lower.tri(m1)]<-t(m1)[lower.tri(t(m1))]
m1
# [,1] [,2] [,3] [,4] [,5]
#[1,] NA 2 3 4 5
#[2,] 2 NA 8 9 10
#[3,] 3 8 NA 14 15
#[4,] 4 9 14 NA 20
#[5,]
1 - 100 of 3327 matches
Mail list logo