search for: nam

Displaying 20 results from an estimated 344 matches for "nam".

Did you mean: name
2013 Feb 26
3
Merging value labels into indicator variable.
I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9. I want to make an indicator variable that will take value 1 if NAM=7 or NAM=8 or NAM=9. How can I do that? I usually do: Var001<- ifelse(NAM==7,1,0) for the simplest case. [[alternative HTML version deleted]]
2016 Aug 05
2
Extra copies of objects in environments when using $ operator?
My understanding is that R will not make copies of lists if there is only one reference to the object. However, I've encountered a case where R does make copies, even though (I think) there should be only one reference to the object. I hope that someone could shed some light on why this is happening. I'll start with a simple example. Below, x is a list with one element, and changing that
2017 Aug 09
2
Fill in empty spaces modified
...lve the new example with base R functions only. I thought of splitting the first column to multiple lists and use one of the apply functions, but was not successful. Would apprecaite some hints on how to go about it. Thanks as always in advance?EK The posted data frame from the original posting: names val 1 Mandy 1 2 2 3 John 2 4 2 My modified data frame: val <- c(1,2,3,4,5,6,7,8) nam <- c("mandy","", "John","","","","Zara","") df1 <- data.frame(nam,val) nam val 1 mandy 1 2...
2013 Jul 24
1
Understanding modification in place
...t;Global") x <- 1:3 .Internal(inspect(x)) x[2] <- 1L .Internal(inspect(x)) message("In function") (function() { x <- 1:3 .Internal(inspect(x)) x[2] <- 1L .Internal(inspect(x)) })() If I run it from the command line, I get: Global @1050bb840 13 INTSXP g0c2 [MARK,NAM(1)] (len=3, tl=0) 1,2,3 @1050bb840 13 INTSXP g0c2 [MARK,NAM(1)] (len=3, tl=0) 1,1,3 In function @1050bb190 13 INTSXP g0c2 [NAM(1)] (len=3, tl=0) 1,2,3 @1050bb190 13 INTSXP g0c2 [NAM(1)] (len=3, tl=0) 1,1,3 i.e. both modifications occur in place. If I put it in a file and source() it, I get: Glob...
2009 Jan 30
3
paste together object names to pass it on to a function
...t I simply don't understand well enought how to work with text/strings: I have a rather compelx data structure, a big list with several sub-lists/dataframes and for certain calculations (which I do in loops), I only need a certain group of sub-lists/dataframes, which I want to specify with a name vector and paste together the object name and pass it on to a function. Here an (hopefully) instructive example #Data Example gnuff<-list() gnuff$IHD$LE<-66 gnuff$LUNG$LE <-55 #This is the list, where I collect data for different diseases at the second level of the list #Now I want to...
2013 Jan 11
4
count combined occurrences of categories
...ount the number of times where I have combined occurrences of the categories of 2 variables.   For instance, in the dataframe below, i would like to know how many times each author (au1, au2, au3 represent the first, second, third author) is associated with each of the category of the variable 'nam'. The position of the author does not matter.   nam <- c('da', 'ya', 'da', 'da', 'fr', 'fr', 'fr', 'da', 'ya', 'fr') au1 <- c('deb', 'art', 'deb', 'seb', 'deb', 'deb...
2013 Jan 24
1
Copy on assignment and .Internal(inspect())
...ternal(inspect(x)) in order to detect vector copying. Take for example the following silly code: f <- function() { x = seq(10) print(.Internal(inspect(x))) for(i in seq(10)) { x[i] <- x[i] + 1 print(.Internal(inspect(x))) } } The output of f() was: @bd7acf0 13 INTSXP g0c4 [NAM(1)] (len=10, tl=0) 1,2,3,4,5,... [1] 1 2 3 4 5 6 7 8 9 10 @bdd6f80 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,2,3,4,5,... [1] 2 2 3 4 5 6 7 8 9 10 @ba66278 14 REALSXP g0c6 [NAM(1)] (len=10, tl=0) 2,3,3,4,5,... [1] 2 3 3 4 5 6 7 8 9 10 @ba661e0 14 REALSXP g0c6 [NAM(1)] (...
2016 Aug 05
0
Extra copies of objects in environments when using $ operator?
...the assignment: > e <- new.env(parent = emptyenv()) > e$x <- list(1) > tracemem(e$x) > # [1] "<0x1148c1708>" > e$x[[1]] <- 2 > # tracemem[0x1148c1708 -> 0x11b2fc1b8]: Currently e$x marks values as immutable if they have any references by setting NAMED to 2. You can see this with > e <- new.env(parent = emptyenv()) > e$x <- list(1) > .Internal(inspect(e)) @30b2498 04 ENVSXP g0c0 [NAM(1)] <0x30b2498> ENCLOS: @2600e98 04 ENVSXP g0c0 [MARK,NAM(2)] <R_EmptyEnv> HASHTAB: @2e41540 19 VECSXP g0c7 [] (len=29, tl=1)...
2019 Jul 17
2
ALTREP wrappers and factors
...ing the wrapper avoided this issue. Here is my initial ALTREP integer vector: > fc0 <- factor(c("a", "a", "b")) > > y <- matter::as.matter(as.integer(fc0)) > y <- matter:::as.altrep(y) > > .Internal(inspect(y)) @7fb0ce78c0f0 13 INTSXP g0c0 [NAM(7)] matter vector (mode=3, len=3, mem=0) Here is what I get without a wrapper: > fc1 <- structure(y, class="factor", levels=levels(x)) > .Internal(inspect(fc1)) @7fb0cae66408 13 INTSXP g0c2 [OBJ,NAM(2),ATT] (len=3, tl=0) 1,1,2 ATTRIB: @7fb0ce771868 02 LISTSXP g0c0 [] TAG:...
2009 Apr 28
8
duplicate 'row.names' are not allowed
Hi everyone,   I have got the following problem:   x1 <- rnorm(10,5,1) x2 <- runif(10,0,1) nam1 <- paste("A",1:4,sep=".") nam2 <- paste("A",6:9,sep=".") nam <- c(nam1,"A.4",nam2,"A.9") mydata <- data.frame(x1,x2) rownames(mydata) <- nam Error in `row.names<-.data.frame`(`*tmp*`, value = c("A.1", "A.2...
2019 Jul 18
0
ALTREP wrappers and factors
...mpletely solve your problem. The duplication occurs since your variable y has more than 1 reference number( Please see highlighted), so even you have a wrapper, any changes on the value of the wrapper still can trigger the duplication. > .Internal(inspect(y)) > @7fb0ce78c0f0 13 INTSXP g0c0 *[NAM(7)]* matter vector (mode=3, len=3, > mem=0) My guess is that *matter:::as.altrep* function assigned the variable *y* to a local variable so that it increases the reference number. For example: *This would not cause a duplication* > > a=c(1,2,3) > > .Internal(inspect(a)) > @0x0...
2010 Nov 19
1
how to save object created by assign()
Hi there, When I run the following code, I could get correct objects (with correct values): for(i in 1:6) { #-- Create objects 'r.1', 'r.2', ... 'r.6' -- nam <- paste("r",i, sep=".") assign(nam, 1:i) # save(nam, file = paste(nam, "RData", sep = ".")) } I hope to save the object 'r.1', 'r.2', ..., 'r.6' using the above commented line, however, I just got 'r.1.RData&...
2003 Mar 06
1
Problems with variable types.
Hi all, I have problems in a dataframe variables types. Look: from a loop function: for(...){ ... dados.fin <- rbind(dados.fin, c(L=j, A=j^2, Nsp=nsps, N=length(amosfin$SP), AmT="am",NAm=nam, AMST=amst)) dados.fin <- rbind(dados.fin, c(L=j, A=j^2, Nsp=nsp, N=nbicho, AmT="tot", NAm=nam, AMST=amst)) ... } da...
2007 Dec 30
2
refering to variable names in lm where the variable name is in another variable
I am trying to refer to a variable name in a lm regression where the variable name is in another variable, but it does seem to work. Here is an example: y<-rnorm(10) dat<-data.frame(x1=rnorm(10),x2=rnorm(10),x3=rnorm(10)) nam<-c('x1','x2','x3') library(gtools) com<-combinations(3,2,1:3) mod<-lm(y...
2011 Nov 24
1
Confused about NAMED
Hi, I expected NAMED to be 1 in all these three cases. It is for one of them, but not the other two? > R --vanilla R version 2.14.0 (2011-10-31) Platform: i386-pc-mingw32/i386 (32-bit) > x = 1L > .Internal(inspect(x)) # why NAM(2)? expected NAM(1) @2514aa0 13 INTSXP g0c1 [NAM(2)] (len=1, tl=0) 1 > y...
2019 Jul 23
3
Any plans for ALTREP lists (VECSXP)?
...atter_list :: out-of-memory list (1.1 MB real | 543.3 MB virtual) > system.time(y <- as.list(x)) user system elapsed 1.116 2.175 5.053 > system.time(z <- as.altrep(x)) user system elapsed 36.295 4.717 41.216 > .Internal(inspect(y)) @108255000 19 VECSXP g1c7 [MARK,NAM(7)] (len=34840, tl=0) @7f9044d9fc00 14 REALSXP g1c7 [MARK] (len=1129, tl=0) 404.093,404.096,404.099,404.102,404.105,... @7f9044d25e00 14 REALSXP g1c7 [MARK] (len=890, tl=0) 409.924,409.927,409.931,409.934,409.937,... @7f9044da6000 14 REALSXP g1c7 [MARK] (len=1878, tl=0) 400.3,400.303,400.306,...
2004 Nov 29
2
problem with using transace
>I am trying to use the Hmisc function transace to transform predictors > > test<-cbind(flowstress,pressres,alloy) > xtrans<-transace(x,binary=pressres',monotonic='flowstress', categorical='alloy') > > >and I am getting the following message?? >Error in ace(x[, -i], x[, i], monotone = im, categorical = ic) : > unused argument(s) (monotone ...)
2004 Feb 20
2
passing object names in a vector to save?
Hi! Like to write quite a lot (ca 100) of objects from my envirovment with save. The names of the objects are in a list nam. nam<-dir() nam<-grep("E",nam,value=T) length(nam) 20 for(x in nam) { #reads the objects and assigns the names. assign(x,simFromEmboss(Simmatrix(),x)) nnam<-paste(x,".rda",sep="") print(nnam) save(x,file=nnam) } I...
2013 Mar 02
1
Expressions in lattice conditional variables
...0, TRUE) x <- c(runif(100), 10*runif(100)) y <- x + c(runif(100)/10, runif(100)) N <- tapply(x, llist(var, trt), function(x) sum(!is.na(x))) print(N) vn <- vector('expression', length(var)) for(v in unique(var)) { i <- var == v n <- tapply(!is.na(x[i]), trt[i], sum) nam <- names(n) w <- sprintf('paste(%s," (", n[%s]==%g,~~n[%s]==%g,")")', v, nam[1], n[1], nam[2], n[2]) cat(w, '\n') vn[var == v] <- parse(text=w) n <- sprintf('%s (n%s=%g, n%s=%g)', v, nam[1],n[1], nam[2],n[2])...
2019 Jul 19
2
ALTREP wrappers and factors
...framework and identifying places we may need more tooling. Comments inline. On Thu, Jul 18, 2019 at 12:22 PM King Jiefei <szwjf08 at gmail.com> wrote: > > If that is the case and you are 100% sure the reference number should be 1 > for your variable *y*, my solution is to call *SET_NAMED *in C++ to reset > the reference number. Note that you need to unbind your local variable > before you reset the number. To return an unbound SEXP, the C++ function > should be placed at the end of your *matter:::as.altrep *function. I don't > know if there is any simpler way to...