similar to: How to get variable names in a function?

Displaying 20 results from an estimated 1000 matches similar to: "How to get variable names in a function?"

2005 Feb 17
5
Again: Variable names in functions
Hello, still I have difficulties with variable names in functions. I know the famous example form help for deparse/substitute but I will give a simpler one to explain my problem. I know from Reid Huntsinger (Tue, 8 Feb 2005 12:39:32 -0500) that: "Semantically, R is pass-by-value, so you don't really have the names, just the values. In implementation, though, R *does* pass names, in part
2004 Nov 30
6
How to know if a bug was recognised
Hello! A problem with special characters seemed to me to be a bug. I sent a mail to R-windows at r-project.org concerning the problem (see below). How can I find out, if this is considered as a bug or an error of myself? Which part of FAQs or documentation did I miss to find the answer? thanks in advance Heinz T??chler -------------------- copy of abovementioned mail ---------- to: R-windows
2005 Sep 08
3
change in read.spss, package foreing?
Dear All, it seems to me that the function read.spss of package foreign changed its behaviour regarding factors. I noted that in version 0.8-8 variables with value labels in SPSS were transformed in factors with the labels in alphabetic order. In version 0.8-10 they seem to be ordered preserving the order corresponding to their numerical codes in SPSS. However I could not find a description of
2005 Sep 08
3
change in read.spss, package foreing?
Dear All, it seems to me that the function read.spss of package foreign changed its behaviour regarding factors. I noted that in version 0.8-8 variables with value labels in SPSS were transformed in factors with the labels in alphabetic order. In version 0.8-10 they seem to be ordered preserving the order corresponding to their numerical codes in SPSS. However I could not find a description of
2005 Feb 04
5
How to access results of survival analysis
Hello, it seems that the main results of survival analysis with package survival are shown only as side effects of the print method. If I compute e.g. a Kaplan-Meier estimate by > km.survdur<-survfit(s.survdur) then I can simply print the results by > km.survdur Call: survfit(formula = s.survdur) n events median 0.95LCL 0.95UCL 100.0 58.0 46.8 41.0 79.3 Is
2009 Sep 28
4
How to assess object names within a function in lapply or l_ply?
Dear All, to produce output of several columns of a data frame, I tried to use lapply and also l_ply. In both cases, I would like to print a header line containing also the name of the respective column in the data frame. For example, I would like the following lapply(data.frame(a=1:3, b=2:4), function(x) print(deparse(substitute(x)))) to produce: [1] "a" [1] "b" and
2005 Aug 02
3
how to print a data.frame without row.names
Dear All, is there a simple way to print a data.frame without its row.names? example: datum <- as.Date(c("2004-01-01", "2004-01-06", "2004-04-12")) content <- c('Neujahr', 'Hl 3 K.', 'Ostern') df1 <- data.frame(datum, content) print(df1) datum content 1 2004-01-01 Neujahr 2 2004-01-06 Hl 3 K. 3 2004-04-12 Ostern Can I get
2005 Aug 10
5
how to write assignment form of function
Dear All, where can I find information about how to write an assigment form of a function? For curiosity I tried to write a different form of the levels()-function, since the original method for factor deletes all other attributes of a factor. Of course, the simple method would be to use instead of levels(x) <- newlevels, attr(x, 'levels') <- newlevels. I tried the following: ##
2006 May 24
3
How to make attributes persist after indexing?
Dear All! For descriptive purposes I would like to add attributes to objects. These attributes should be kept, even if by indexing only part of the object is used. I noted that some attributes like levels and class of a factor exist also after indexing, while others, like comment or label vanish. Is there a way to make an arbitrary attribute to be kept after indexing? This would be especially
2005 Apr 02
4
factor to numeric in data.frame
Dear All, Assume I have a data.frame that contains also factors and I would like to get another data.frame containing the factors as numeric vectors, to apply functions like sapply(..., median) on them. I read the warning concerning as.numeric or unclass, but in my case this makes sense, because the factor levels are properly ordered. I can do it, if I write for each single column
2009 Apr 08
2
factor, as.factor and levels
Dear All, to my surprise as.factor does not accept a levels argument. Maybe I did not read the documentation well enough. See the example below. I wanted to use ch1 as factor in the newdata argument of survfit, so I assumed that I could write as.factor(ch1, levels=ch1), since the order should be kept. But as.factor(ch1, levels=ch1) results in the error: Error in as.factor(ch1, levels = ch1)
2005 Mar 29
3
From FAQ 7.21 to a command like apply(sapply(list(f1,f2,f3),is.na),2,sum)
Dear all, Last December there was a thread regarding the famous FAQ 7.21 "How can I turn a string into a variable?" and asking what people want to do with these strings. My, certainly trivial application would be as follows: Assume I have a data.frame containing besides others also the columns f1, f2, ..., fn and I want to create a command like: apply(sapply(list(f1,f2,f3),is.na),2,sum)
2006 Jul 27
2
How to get the name of the first argument in an assignment function?
Dear All! If I pass an object to an assignment function I cannot get it's name by deparse(substitute(argument)), but I get *tmp* and I found no way to get the original name, in the example below it should be "va1". Is there a way? Thanks, Heinz ## example 'fu1<-' <- function(var, value) { print(c(name.of.var=deparse(substitute(var))))} fu1(va1) <- 3 name.of.var
2006 May 23
4
How to call a value labels attribute?
Dear All, after searching on CRAN I got the impression that there is no standard way in R to label values of a numerical variable. Since this would be useful for me I intend to create such an attribute, at the moment for my personal use. Still I would like to choose a name which does not conflict with names of commonly used attributes. Would value.labels or vallabs create conflicts? The
2004 Nov 30
1
Attn Heinz Tuechler: Re: problem with special characters (ä,ö,ü)
[I tried to send this message privately, but the return address bounced.] I think this has been fixed in R-patched, but I doubt if the fix has been tested in Win98. Could you please download a copy from <http://cran.r-project.org/bin/windows/base/rpatched.html> and confirm that it has been fixed? Duncan Murdoch On Sat, 27 Nov 2004 23:31:23 +0100, Heinz Tuechler <tuechler at gmx.at>
2010 Dec 31
3
survexp - example produces error
Dear All, reposting, because I did not find a solution, maybe someone could check the example below. It's taken from the help page of survdiff. Executing it, gives the error "Error in floor(temp) : Non-numeric argument to mathematical function" best regards, Heinz library(survival) ## Example from help page of survdiff ## Expected survival for heart transplant patients based
2008 Nov 06
3
Umlaut read from csv-file
Dear All! Reading character strings containing an "umlaut" from a csv-file I find a (to me) surprising behaviour in R 2.8.0, that I did not notice in R 2.7.2. A comparison by "==" results in FALSE, while grep does find the aggreement. See the example below. The crucial line is x=="div 1-2 Ver?nderungen", with the result [1] FALSE in R 2.8.0 but [1] TRUE in R
2023 Jan 13
1
return value of {....}
> 09.01.2023 18:05:58 akshay kulkarni <akshay_e4 at hotmail.com>: > > We are living in the 21st century world, and the R-core team might,I suppose, have a definite reason ... > Maybe compatibility reasons with S and R-versions from the 20st century? But maybe, you would have expected some reason even then. best regards, Heinz
2006 Jul 04
2
unique deletes names - intended?
Dear All, as shown in the example, unique() deletes names of vector elements. Is this intended? Of course, one can use indexing by !duplicated() instead. Greetings, Heinz ## unique deletes names v1 <- c(a=1, b=2, c=3, e=2, a=4) unique(v1) # names deleted v1[!duplicated(v1)] # names preserved platform i386-pc-mingw32 arch i386
2006 Mar 15
5
Surv object in data.frame
Dear All, a Surv object I put in a data frame behaves somehow unexpected (see example). If I do a Cox regression on the original Surv object it works. If I put it in a data.frame and do the regression on the data frame it does not work. Seemingly it has to do with the class attribute, because if I change the class attribute to let "Surv" appeare first, again it works. Is this known?