search for: lvls

Displaying 15 results from an estimated 15 matches for "lvls".

Did you mean: lvds
2012 Feb 28
1
group calculations with other columns for the ride
Hello, I can get the median for each factor, but I'd like another column to go with each factor. The nm column is a long name for the lvls column. So unique work except for the order can get messed up. Example: x = data.frame(val=1:10,lvls=c('cat2',rep("cat1",4),rep("cat2",4),'cat1'),nm=c('longname2',rep("longname1",4),rep("longname2",4),'longname1')) x val lvls...
2011 Jan 26
1
aggregate(as.formula("some formula"), data, function) error when called from in a function
...n works fine. agg2 <- function(test=FALSE) { # create a factor y dat <- data.frame(y=sample(LETTERS[1:3],100,replace=TRUE)) # create a factor x dat$x <- sample(letters[1:4],100,replace=TRUE) # make a column of 1s and zeros # 1 when that row has that level of y # 0 otherwise lvls <- levels(dat$y) dat$ya <- 1*(dat[,1] == lvls[1]) dat$yb <- 1*(dat[,1] == lvls[2]) dat$yc <- 1*(dat[,1] == lvls[3]) # this works fine if you give the exact function agg1 <- aggregate(cbind(ya,yb,yc)~x,data=dat,sum) # and fine if you accept fo <- as.formula("cbin...
2012 Oct 24
1
Getting ordered factor levels from C
I'm working on an R package in C and can't seem to get the same level information about a factor that the R console displays. If I define a factor as: lvls <- factor(c('red','blue','blue','green','red'), c('blue','green','red'), ordered=TRUE) When I get the "levels" attribute in C, I get back the the first vector, not the second. If I run attr(lvls,"levels") in R,...
2005 Jun 26
4
Mixed model
...ollowing previous correspondence . Dataset <- read.table("C:/Program Files/R/rw2011/data/miss/model1a.dat", header=TRUE, sep="\t", na.strings="NA", dec=".", strip.white=TRUE) attach(Dataset) require (nlme) with(Dataset, table(runnb, id, grp)) b.lvls <- table(Dataset$runnb) nb <- length(b.lvls) fit <- vector(mode="list", nb) for(i in 1:nb) fit[[i]]<- lme (trans1 ~ Index1 + grp, random = ~ 1 | id / grp , data = Dataset, na.action = "na.exclude") This (abov...
2018 May 16
2
Bilateral matrix
...is automatically if your cross classifying variables are factors with levels all the cities (sorted, if you like): > x <- sample(letters[1:5],8, rep=TRUE) > y <- sample(letters[1:5],8,rep=TRUE) > xtabs(~ x + y) y x c d e a 1 0 0 b 0 0 1 c 1 0 0 d 1 1 1 e 1 1 0 > lvls <- sort(union(x,y)) > x <- factor(x, levels = lvls) > y <- factor(y, levels = lvls) > xtabs( ~ x + y) y x a b c d e a 0 0 1 0 0 b 0 0 0 0 1 c 0 0 1 0 0 d 0 0 1 1 1 e 0 0 1 1 0 Cheers, Bert Bert Gunter "The trouble with having an open mind is that people k...
2004 Feb 05
2
correction to the previously asked question (about merging factors)
I have two factors l1, l2, and I'd like to merge them. (Remark: The factors can not be converted to charaters) Function c() does not give me the result I want: > l1 = factor(c('aaaa', 'bbbb')) > l2 = factor(c('ccc', 'dd')) > lMerge = factor(c(l1, l2)) > lMerge [1] 1 2 1 2 Levels: 1 2 > I'd like to merge l1 and l2 and to get lMerge
2004 Feb 05
0
correction to the previously asked question (about mergin g factors)
...t; > Spencer Graves wrote: > > > What about the following: > > > F1 <- factor(c("b", "a")) > > > F2 <- factor(c("c", "b")) > > > k1 <- length(F1) > > > k2 <- length(F2) > > > F12.lvls <- unique(c(levels(F1), levels(F2))) > > > F. <- factor(rep(F12.lvls[1], k1+k1), levels=F12.lvls) > > > F.[1:k1] <- F1 > > > F.[-(1:k1)] <- F2 > > > F. > > [1] b a c b > > Levels: a b c > > > > This saves converting t...
2018 May 17
0
Bilateral matrix
...th levels all the cities (sorted, if you like): > > > x <- sample(letters[1:5],8, rep=TRUE) > > y <- sample(letters[1:5],8,rep=TRUE) > > > xtabs(~ x + y) > y > x c d e > a 1 0 0 > b 0 0 1 > c 1 0 0 > d 1 1 1 > e 1 1 0 > > > lvls <- sort(union(x,y)) > > x <- factor(x, levels = lvls) > > y <- factor(y, levels = lvls) > > > xtabs( ~ x + y) > y > x a b c d e > a 0 0 1 0 0 > b 0 0 0 0 1 > c 0 0 1 0 0 > d 0 0 1 1 1 > e 0 0 1 1 0 > > Cheers, > Bert > &g...
2009 Sep 08
3
Mapping factors to a new set of factors
Hello, I am trying to map a factor variable within a data frame to a new variable whose entries are derived from the content of the original variable and there are fewer factors in the new variable. That is, I'm trying to set up a surjection. After first thinking that this would be a common operation and would have a quite simple interface, I can not seem to find one, nor any similar posts
2011 Mar 14
3
ideas on sorting
Hi, I have a character vector as below: a<-c('10','3R','4','4R','5','5R','6','6R','7','8','9','7R','1','10R','11'
2011 May 02
2
Lasso with Categorical Variables
Hi! This is my first time posting. I've read the general rules and guidelines, but please bear with me if I make some fatal error in posting. Anyway, I have a continuous response and 29 predictors made up of continuous variables and nominal and ordinal categorical variables. I'd like to do lasso on these, but I get an error. The way I am using "lars" doesn't allow for the
2013 Feb 08
2
Count of Histogram Bins using Shingles with lattice
I know that I can get a count of histogram bins in base R with plot=FALSE. However, I'd like to do the same thing with lattice. The problem is that I've set up shingles, and I'd like to get the count within each bin within each shingle. plot=FALSE doesn't seem to do it. [[alternative HTML version deleted]]
2018 May 16
0
Bilateral matrix
Dear Bert and Huzefa, Apologies for the late reply, my account got hacked and I have just managed to recover it. Thank you very much for your replies and the solutions. Both work well. I was wondering if there was any way to ensure (force) that all possible combinations show up in the output. The full dataset has 25 cities but of course people have not moved from Boston to all the other 24
2005 May 25
4
mixed model
Hello all, I have problem with setting up random effects. I have a model: y=x1+x2+x1*x2+z1+z1*x2 where x1, x2, x1*x2 are fixed effects and z1, z1*x2 are random effects (crossed effects) I use library(nlme) 'lme' function. My question is: how I should set up random effects? I did lme(y~x1+x2+x1:x2, data=DATA, random=~z1+z1:x2, na.action='na.omit') but it did not work.
2018 May 08
3
Bilateral matrix
or in base R : ?xtabs ?? as in: xtabs(~previous_location + current_location,data=x) (You can convert the 0s to NA's if you like) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, May 8, 2018 at 9:21 AM, Huzefa