Displaying 20 results from an estimated 10000 matches similar to: "Removing time and min from Date"
2013 Aug 26
1
Loop for converting character columns to Numeric
Hi,
Suppose you created a dataframe like this:
set.seed(28)
?dat1<-as.data.frame(simplify2array(list(letters[1:5],sample(1:20,5,replace=TRUE),6:10)),stringsAsFactors=FALSE)
?str(dat1)
#'data.frame':??? 5 obs. of? 3 variables:
# $ V1: chr? "a" "b" "c" "d" ...
# $ V2: chr? "1" "2" "10" "18" ...
# $ V3: chr?
2012 Nov 21
1
update fit (removing insignificant variables)
HI,
I am not sure about the ?update() method.
You could try this:
set.seed(232)
mat1<-matrix(sample(1:100,80,replace=TRUE),ncol=8) #with 8 columns
dat1<-data.frame(mat1)
?names(dat1)[1]<-"Y"
?fit<-lm(Y~.,data=dat1)
res<-coef(summary(fit))
?res
#???????????????? Estimate Std. Error???? t value?? Pr(>|t|)
#(Intercept) 143.763081344 21.9902865? 6.53757200 0.02260698
2013 Jul 24
0
subtracting rows for unique
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(dat1,by(as.Date(Date,format="%d-%b-%y"),ID,FUN=function(x)
2013 Apr 21
1
Excluding observations
Hi Farnoosh,
set.seed(25)
Data.All.Var<- data.frame(ID= sample(LETTERS[1:10],25,replace=TRUE), value=rnorm(25),stringsAsFactors=FALSE)
set.seed(28)
Y.Out<- data.frame(ID=sample(LETTERS[1:5],25,replace=TRUE),value=rnorm(25),stringsAsFactors=FALSE)
unique(Y.Out$ID)
#[1] "A" "C" "E" "D" "B"
?unique(Data.All.Var$ID)
# [1] "E"
2012 Nov 13
4
for loop
HI,
You can do this in many ways:
dat1<-read.table(text="
med1,med2,med3????
?1,0,1??????
0,1,1???
2,0,0
",sep=",",header=TRUE)??
#1st method
library(reshape)
dat2<-melt(dat1)
dat3<-aggregate(dat2$value,by=list(dat2$variable),sum)
?colnames(dat3)<-c("name","sum(n11)")
?dat3
#? name sum(n11)
#1 med1??????? 3
#2 med2??????? 1
#3 med3??????? 2
2013 Apr 13
2
Comparison of Date format
Hi,
?In the example you provided, it looks like the dates in Date2 happens first.? So, I changed it a bit.?
DataA<- read.table(text="
ID,Status,Date1,Date2 ??? ??? ??????
1,A,3-Feb-01,15-May-01 ??? ???
1,B,15-May-01,16-May-01 ??? ???
1,A,16-May-01,3-Sep-01 ??? ??? ??? ??? ???
1,B,3-Sep-01,13-Sep-01 ??? ??? ??? ??? ???
1,C,13-Sep-01,26-Feb-04 ??? ??? ??? ??? ???
2012 Oct 23
3
frequency
Hello,
I have a data as follow:
ID Visit
xa1
xa2
yb1
yc23
yb33
I want to look at frequency of visit for ID and create a new column as response .
For example my response would be 2 for x and 3 for y.
I think I need to write a loop, but I don't know how.
I really appreciate your help.
Thanks a lot.
Best,Farnoosh Sheikhi
[[alternative HTML version deleted]]
2012 Dec 12
1
Subset of Data
Hi Arun,
I have a question about choosing a subset of data.
I have a matrix of 5000 in 3500.
I want to choose specific variables such as proc1 to proc1000 and Lab1 to Lab1600 and put it into a new matrix to run some correlation analysis.
Since I have 3500 variables, I don't know from what column my lab or procedures start.
I really appreciate your help.
Thanks.
Best,Farnoosh Sheikhi
2017 Jun 30
0
Different date formats in one column
Left as an exercise for the student.
--
Sent from my phone. Please excuse my brevity.
On June 29, 2017 7:25:36 PM EDT, Farnoosh Sheikhi <farnoosh_81 at yahoo.com> wrote:
>Thanks Jeff. This is a nice way of solving this problem. What about the
>cases with 0015-02-21?Many thanks.?Best,Farnoosh
>
>
>
>On Wednesday, June 28, 2017 10:49 PM, Jeff Newmiller
><jdnewmil at
2013 Sep 09
0
Duplicated genes
Hi,
May be you can try this:
dat1New<-? dat1[!(duplicated(dat1$gene)|duplicated(dat1$gene,fromLast=TRUE)),]
dat2<-dat1[duplicated(dat1$gene)|duplicated(dat1$gene,fromLast=TRUE),]
?lst1<-split(dat2,dat2$gene)
dat3<-unsplit(lapply(lst1,function(x) {x1<- sum(apply(x[,6:32],2,function(y) y[1]>=y[2]));x2<- sum(apply(x[,6:32],2, function(y) y[1]<=y[2])); if(x1>x2) x[1,] else
2013 Jan 28
2
Pivot
Hi,
I have a data set as follow:
X Z
x1 102
x2 102
x2 102
x2 77
x3 23
I need to pivot this data as follows and assign the values based on frequency of column Z:
X Z.102 Z.77 Z.23
x1 1 0 0
x2 21 0
x3 00 1
Thanks.
Best,Farnoosh Sheikhi
[[alternative HTML version deleted]]
2012 Nov 06
1
pivot table
Hello,
I have a data which looks like below: Some of the patients have multiple diagnosis.
ID(200 patients) Diag (100 unique Diag-200 in general) Proc (50 uniqe Proc) DOB (200) Gender (200)
a daig1
b diag2
c diag1
I want to reformat this data to :
ID diag1 diag 2 diag 3.. diagx proc1 proc2
2013 Feb 17
1
addition in the initial question
Dear Elisa,
Try this:
vec1<-c(33,18,13,47,30,10,6,21,39,25,40,29,14,16,44,1,41,4,15,20,46,32,38,5,31,12,48,27,36,24,34,2,35,11,42,9,8,7,26,22,43,17,19,28,23,3,49,37,50,45)
vec2<-vec1[1:26]
names(vec2)<-LETTERS[1:26]
label1<-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) x),lapply(seq(5,50,5),function(x) x),SIMPLIFY=FALSE),function(i)
2013 Jun 04
0
choose the lines2
Hi,
May be this helps:
dat1<- read.csv("dat7.csv",header=TRUE,stringsAsFactors=FALSE,sep="\t")
dat.bru<- dat1[!is.na(dat1$evnmt_brutal),]
fun2<- function(dat){??
????? lst1<- split(dat,dat$patient_id)
??? lst2<- lapply(lst1,function(x) x[cumsum(x$evnmt_brutal==0)>0,])
??? lst3<- lapply(lst2,function(x) x[!(all(x$evnmt_brutal==1)|all(x$evnmt_brutal==0)),])
2013 Jul 10
1
Kruskal.test
Hi,
Please dput() your example dataset.
dat1<- read.table(text="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?? 4?? 1???? 6??? 8?? 1??? 3??? 5??? 2??? 6??? 3",sep="",header=FALSE,stringsAsFactors=FALSE)
library(reshape)
?dat2<-melt(as.data.frame(t(dat1)),id.var="V1")[,-2]
2013 Mar 08
2
Zoo Data
Hi Jakob,
dat1<-read.table(text="
TIME, Value1, Value2
01.08.2011 02:30:00, 4.4, 4.7
01.09.2011 03:00:00, 4.2, 4.3
01.11.2011 01:00:00, 3.5, 4.3
01.12.2011 01:40:00, 3.4, 4.5
01.01.2012 02:00:00, 4.8, 5.3
01.02.2012 02:30:00, 4.9, 5.2
01.08.2012 02:30:00, 4.1, 4.7
01.12.2012 03:00:00, 4.7, 4.3
01.01.2013 01:00:00, 3, 4.3
01.01.2013 01:30:00, 3.8, 4.1
01.01.2013 02:00:00, 3.8,
2013 May 27
0
choose the lines
Hi,
Try this:
dat1<- read.csv("dat7.csv",header=TRUE,stringsAsFactors=FALSE,sep="\t")
dat.bru<- dat1[!is.na(dat1$evnmt_brutal),]
fun1<- function(dat){???
? ??? lst1<- split(dat,dat$patient_id)
??? lst2<- lapply(lst1,function(x) x[cumsum(x$evnmt_brutal==0)>0,])
??? lst3<- lapply(lst2,function(x) x[!(all(x$evnmt_brutal==1)|all(x$evnmt_brutal==0)),])
???
2012 Nov 12
1
reshape
Hi,
I have a R output that looks as follow:
Rad:0
Rad1:2
Rad3:3
I want to make a new matrix that looks like : sample size is 2400
Variable n11 n12
Rad 0 2400-0=2400
Rad1 2 2400-2
Rad3 3 2400-3
Thanks a lot for your time and help:)
Best,Farnoosh Sheikhi
[[alternative HTML version deleted]]
2017 Sep 25
0
Fw: passing different sample sizes
Your code is full of syntactic errors. What do you think 1.71(se) means?
After you clean up your code, something like this might be what you want:
out <- lapply(seq(40,500,by = 25), f)
To get plots, just stick in a plot statement after you define m and d.
Have you gone through any R tutorials? You seem to be confused about basics
that tutorials could help you with. This list is not meant
2013 Sep 25
1
Best and worst values for each date
Hi,
May be you can try this:
obj_name<- load("arun.RData")
Pred1<- get(obj_name[1])
Actual1<- get(obj_name[2])
library(reshape2)
dat<-cbind(melt(Pred1,id.vars="S1"),value2=melt(Actual1,id.vars="S1")[,3])? # to reshape to long form
colnames(dat)[3:4]<- c("Predict","Actual")
dat$variable<- as.character(dat$variable) #not that