Displaying 14 results from an estimated 14 matches for "mydt".
Did you mean:
mydf
2024 Sep 21
3
store list objects in data.table
I am trying to store regression objects in a data.table
df <- data.frame(x = rnorm(20))
df[, "y"] <- with(df, x + 0.1 * x^2 + 0.2 * rnorm(20))
mydt <- data.table(mypower = c(1, 2), myreg = list(lm(y ~ x, data = df),
lm(y ~ x + I(x^2), data = df)))
mydt
#?? mypower??? myreg
#???? <num>?? <list>
#1:?????? 1 <lm[12]>
#2:?????? 2 <lm[12]>
But mydt[1, 2] has only the coeffients of the first regression. mydt[2,
2] has re...
2024 Sep 28
1
lattice xyplot with cumsum() function inside
This code gives unexpected result.
library(data.table)
library(lattice)
set.seed(123)
mydt <- data.table(date = seq.Date(as.IDate("2024-01-01"), by = 1,
length.out = 50), xgroup = "A", x = runif(50, 0, 1))
mydt <- rbindlist(list(mydt, data.table(date = mydt$date, xgroup = "B", x = runif(50, 0, 3))))
mydt[, `:=`(xcumsum = cumsum(x)), by = .(xgroup)]
myd...
2024 Sep 22
1
store list objects in data.table
...list(
degree = i, reg =lm(y ~ poly(x, i, raw = TRUE))
)
)
)
As you can see, 'result' is a list, each component of which is a list
of two with names "degree" and "reg" giving the same info as each row
of your 'mydt'. You can use lapply() and friends to access these
results and fiddle with them as you like, such as: "extract the
coefficients from the second degree fits only", and so forth. Also
note that individual components of nested lists can be extracted by
giving a vector to [[ instead of re...
2024 Sep 22
2
store list objects in data.table
...= i, reg =lm(y ~ poly(x, i, raw = TRUE))
> )
> )
> )
>
> As you can see, 'result' is a list, each component of which is a list
> of two with names "degree" and "reg" giving the same info as each row
> of your 'mydt'. You can use lapply() and friends to access these
> results and fiddle with them as you like, such as: "extract the
> coefficients from the second degree fits only", and so forth. Also
> note that individual components of nested lists can be extracted by
> giving a vector...
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...
2024 Nov 05
0
lattice subscripts with both condition and group
...? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
library(lattice) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
library(latticeExtra) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
mydt2024 <- data.table( ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? date = rep(as.Date(c("2024-11-01", "2024-11-04")), c(8, 8)), ? ? ? ? ? ? ? ? ? ? ? ??
? ? day_forward = rep(1:8, 2), ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? news_cl...
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