similar to: lattice subscripts with both condition and group

Displaying 9 results from an estimated 9 matches similar to: "lattice subscripts with both condition and group"

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)] mydt[,
2024 Sep 22
1
store list objects in data.table
Well, you may have good reasons to do things this way -- and you certainly do not have to explain them here. But you might wish to consider using R's poly() function and a basic nested list structure to do something quite similar that seems much simpler to me, anyway: x <- rnorm(20) df <- data.frame(x = x, y = x + .1*x^2 + rnorm(20, sd = .2)) result <- with(df,
2024 Sep 22
2
store list objects in data.table
Thanks everyone for their responses. My data is organized in a data.table.? My goal is to perform analyses according to some groups.? The results of analysis are objects.? If these objects could be stored as elements of a data.table, this would help downstream summarizing of results. Let me try another example. carsdt <- setDT(copy(mtcars)) carsdt[, unique(cyl) |> length()] #[1] 3
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]
2007 Jan 18
0
help with niave bayes
Hello I have a rather simple code and for some reason it produces an error message. If someone can tell me why and how to fix it, I would be very greatful. Thank you in advance. ##### create data set.seed(10) n <- 200 # number of training points n.test <- 200 # number of test points p<-2 # dimension of input space z <-
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
2007 Jan 19
1
naive bayes help
Hello I have a rather simple code and for some reason it produces an error message. If someone can tell me why and how to fix it, I would be very greatful. Thank you in advance. ##### create data set.seed(10) n <- 200 # number of training points n.test <- 200 # number of test points p<-2 # dimension of input space z <-
2011 Nov 29
2
aggregate syntax for grouped column means
I am calculating the mean of each column grouped by the variable 'id'. I do this using aggregate, data.table, and plyr. My aggregate results do not match the other two, and I am trying to figure out what is incorrect with my syntax. Any suggestions? Thanks. Here is the data. myData <- structure(list(var1 = c(31.59, 32.21, 31.78, 31.34, 31.61, 31.61, 30.59, 30.84, 30.98, 30.79, 30.79,
2011 Aug 31
1
formatting a 6 million row data set; creating a censoring variable
List, Consider the following data. gender mygroup id 1 F A 1 2 F B 2 3 F B 2 4 F B 2 5 F C 2 6 F C 2 7 F C 2 8 F D 2 9 F D 2 10 F D 2 11 F D 2 12 F D 2 13 F D 2 14 M A 3 15 M A 3 16 M A 3 17