search for: mydt

Displaying 9 results from an estimated 9 matches for "mydt".

Did you mean: mydf
2007 Jan 19
1
naive bayes help
...ef)/(1+exp(x%*%truecoef)) # prob is the true probability of class 1 y <- rbinom(n+n.test,1,prob1) # separate the data into train and test sets mydata <- data.frame(y=y[1:n],x=x[1:n,]) mydata.test <- data.frame(y=y[n+(1:n.test)],x=x[n+(1: n.test),]) ########################## library(e1071) mydt.nb<-naiveBayes(y~ ., data=mydata) m.pr<-predict(mydt.nb, mydata[,-1], type="class") regards, Leah [[alternative HTML version deleted]]
2011 Nov 29
2
aggregate syntax for grouped column means
...") > head(myData) var1 var2 id 1 31.59 33.78 0m4 2 32.21 33.25 0m4 3 31.78 NA 0m4 4 31.34 32.05 0m5 5 31.61 32.59 0m5 6 31.61 NA 0m5 results1 <- aggregate(. ~ id ,data=myData,FUN=mean,na.rm=T) head(results1,1) # id var1 var2 # 1 0m11 30.79 32.27 library(data.table) mydt <- data.table(myData) setkey(mydt,id) results2 <- mydt[,lapply(.SD,mean,na.rm=TRUE),by=id] head(results2,1) # id var1 var2 # [1,] 0m11 30.84 32.27 library(plyr) results3 <- ddply(myData,.(id),colwise(mean),na.rm=TRUE) head(results3,1) # id var1 var2 # 1 0m11 30.84 32.27 &g...
2020 Oct 18
1
Resultado de la consola como un tibble
Hola, Bueno, puedes hacer el cálculo de una forma mucho más compacta y rápida. Esta forma es especialmente recomendable cuando tienes muchas columnas y muchas filas. > library(data.table) > myDT <- as.data.table(mtcars) > myDTlong <- melt(myDT, measure.vars=1:ncol(myDT)) > myDTlong[ , list(p_value = shapiro.test(value)$p.value, v_stat = shapiro.test(value)$statistic) , by = .(variable)] variable p_value v_stat 1: mpg 1.228814e-01 0.9475647 2: cyl 6...
2011 Aug 31
1
formatting a 6 million row data set; creating a censoring variable
...t;- function(x) { myvec <- rep(0,length(x)) lastInd <- length(myvec) myvec[lastInd] = 1 myvec } plyrSolution <- ddply(timeData, "id", transform, censor = makeCensor(mygroup)) # here is a data table solution # use makeCensor function from above library(data.table) mydt <- data.table(myData) setkey(mydt,id,mygroup) timeData <- mydt[,list(mytime=length(gender)),by=list(id,mygroup)] makeCensor <- function(x) { myvec <- rep(0,length(x)) lastInd <- length(myvec) myvec[lastInd] = 1 myvec } mycensor <- timeData[,list(censor=makeCensor(myg...
2010 Aug 09
2
coef(summary) and plyr
Dear all, I?m having trouble getting a list of regression variables back into a dataframe. mydf <- data.frame(x1=rnorm(100), x2=rnorm(100), x3=rnorm(100)) mydf$fac<-factor(sample((0:2),replace=T,100)) mydf$y<- mydf$x1+0.01+mydf$x2*3-mydf$x3*19+rnorm(100) dlply(mydf,.(fac),function(df) lm(y~x1+x2+x3,data=df))->dl here I?d like to use ldply(dl,coef(summary)) or something
2020 Oct 18
2
Resultado de la consola como un tibble
Buen día estimados Estoy tratando de hacer un tibble con los resultados de un apply que se muestran en la consola que me da R, no estoy seguro si eso se pueda hacer, pero me gustaría organizar los resultados de esa manera. mi código es: data("mtcars") Mtcars_matriz <- as.matrix(mtcars) apply(Mtcars_matriz, MARGIN =2, FUN = shapiro.test) DF2 <- tibble(Variable = NA, W = NA, Pvalue =
2007 Jan 18
0
help with niave bayes
...oef)/(1+exp(x%*%truecoef)) # prob is the true probability of class 1 y <- rbinom(n+n.test,1,prob1) # separate the data into train and test sets mydata <- data.frame(y=y[1:n],x=x[1:n,]) mydata.test <- data.frame(y=y[n+(1:n.test)],x=x[n+(1:n.test),]) ########################## library(e1071) mydt.nb<-naiveBayes(y~ ., data=mydata) m.pr<-predict(mydt.nb, mydata[,-1], type="class") regards, Leah [[alternative HTML version deleted]]
2011 Aug 24
2
data manipulation and summaries with few million rows
I have a data set with about 6 million rows and 50 columns. It is a mixture of dates, factors, and numerics. What I am trying to accomplish can be seen with the following simplified data, which is given as dput output below. > head(myData) mydate gender mygroup id 1 2012-03-25 F A 1 2 2005-05-23 F B 2 3 2005-09-08 F B 2 4 2005-12-07 F B 2
2001 Nov 16
6
case conversion and/or string comparison
This is no doubt trivial but after searching the help files and the web, I cannot seem to find it. 1) How do I convert 'hgt' into 'HGT' in R? 2) How should I have used the help facilities to find this? At the end of the day, all I want to do is case insensitive string matching... i.e. 'if ("HGT" == 'hgt') print('this should be true')' I tried