similar to: Weired problem when passing arguments using ...?

Displaying 20 results from an estimated 50000 matches similar to: "Weired problem when passing arguments using ...?"

2009 Aug 20
2
Problem passing a statistical model as an argument
Dear Colleagues: I would like to write a front end for a modeling function, but run into trouble when passing a weights argument. y <- 1:5 x <- c(1,3,2,5,4) w <- function(formula, ...) lm(formula, ...) lm(y ~ x, weights=c(1,1,1,2,2)) w(y ~ x) w(y ~ x, weights=c(1,1,1,2,2)) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in w <-
2010 Oct 25
2
Question on passing the subset argument to an lm wrapper
Hello, How would you go about handling the following situation? This is on R 2.12.0 on Ubuntu 32-bit. I have a wrapper function to lm. I want to pass in a subset argument. First, I just thought I'd use "...". ## make example reproducible set.seed(123) df1 <- data.frame(age = rnorm(100, 50, 10), bmi = rnorm(100, 30, sd = 2)) ## create a wrapper using
2008 Aug 25
1
"unexpected symbol" error?
Hi. I am getting an "unexpected symbol" error, which I haven't gotten before. I have checked my data and searched the FAQ. I hoping someone has a suggestion on what I might be doing wrong? Thanks! A. Gray Fisheries Consultant Here's the code I'm using and the error: > 0708smolts <- read.csv("C:\Documents and Settings\ayesha\My
2008 Aug 06
2
Index alternative to nasty FOR loop?
Dear R wizards, I have a folder containing 1000 files. For each file, I need to extract the first row of each file, paste it to a new file, then write out that file. Then I need to repeat this operation for each additional row (row 2, then row 3, etc) for 23 rows in each file. I can do this with a for loop (as below). Is there a way to use some of the indexing power of R to get around this
2008 Jan 07
2
How should I improve the following R code?
I'm looking for a way to improve code that's proven to be inefficient. Suppose that a data source generates the following table every minute: Index Count ------------ 0 234 1 120 7 11 30 1 I save the tables in the following CSV format: time,index,count 0,0:1:7:30,234:120:11:1 1,0:2:3:19,199:110:87:9 That is, each line represents a table, and I
2008 Jan 04
3
slow access to matrix dimnames
hello, i have been trying to convert my data frames to matrices in the hopes of speeding up some of my more complicated scripts. to assist with this, i am trying to create a "matrix column operator" like $: "%$%" = function(data,field) { as.numeric(data[,grep(field,unlist(dimnames(data)[2]))]) } the idea here is that you can use a matrix like a dataframe:
2009 Jan 06
8
for loop and if problem
Hi, I'm heaving difficulties with a dataset containing gene names and positions of those genes. Not such a big problem, but each gene has multiple exons so it's hard to say where de gene starts and where it ends. I want the starting and ending position of each gene in my dataset. Attached is the dataset: http://www.nabble.com/file/p21312449/genlistchrompos.csv genlistchrompos.csv Column
2010 Jul 05
1
Memory problem in multinomial logistic regression
Dear All I am trying to fit a multinomial logistic regression to a data set with a size of 94279 by 14 entries. The data frame has one "sample" column which is the categorical variable, and the number of different categories is 9. The size of the data set (as a csv file) is less than 10 MB. I tried to fit a multinomial logistic regression, either using vglm() from the VGAM package or
2009 Jul 15
2
Passing additional arguments through '...'
Hi, I know this is a simple question, but I've been having problems passing additional arguments through '...'. It is not matching the arguments correctly if the permanent argument of the function begins with the same letter as the additional argument. The following example will help show what I mean: fun.tester <- function(abc,...){ + print(abc) + } But if I input:
2010 Jun 11
4
setting the current working directory to the location of the source file
AFAIK a script run through source() does not have any legit way to learn about it's own location. I need this to make sure that the script will find its datafiles after I move the whole directory. (The datafiles are in the same directory.) Here is a hack I invented to work around it: print(getwd()) source_pathname = get("ofile",envir = parent.frame()) source_dirname =
2010 Jun 26
3
converting result of substitute to 'ordidnary' expression
Dear R users, As substitute() help page points out: Substituting and quoting often causes confusion when the argument is 'expression(...)'. The result is a call to the 'expression' constructor function and needs to be evaluated with 'eval' to give the actual expression object. And indeed I am confused. Consider: > dat <- data.frame(x=1:10,
2010 Jun 26
3
converting result of substitute to 'ordidnary' expression
Dear R users, As substitute() help page points out: Substituting and quoting often causes confusion when the argument is 'expression(...)'. The result is a call to the 'expression' constructor function and needs to be evaluated with 'eval' to give the actual expression object. And indeed I am confused. Consider: > dat <- data.frame(x=1:10,
2007 May 31
1
Conditional logistic regression for "events/trials" format
Dear R users, I have a large individual-level dataset (~700,000 records) which I am performing a conditional logistic regression on. Key variables include the dichotomous outcome, dichotomous exposure, and the stratum to which each person belongs. Using this individual-level dataset I can successfully use clogit to create the model I want. However reading this large .csv file into R and running
2010 Jun 13
5
Count of unique factors within another factor
I have a data frame with two factors (sampling 'unit', 'species'). I want to calculate the number of unique 'species' per 'unit.' I can calculate the number of unique values for each variable separately, but can't get a count for each ?unit?. > data=read.csv("C:/Desktop/sr_sort_practice.csv") > attach(data) > data[1:10,] unit species 1
2010 Jun 23
2
possibility to determine whether a script is "sourced"?
Dear R community, I am running some rather large scripts either by executing single blocks of them separately or by executing them at once via source('script.R') Now there is a lot of code in those scripts that I only want to run when I run them manually, so I wonder whether there is any way to automatically find out whether the script is run manually stepwise or whether it is run via
2007 Oct 26
1
Problems with scan() in a tab-sep .txt file with cells that have '///' (three frontslashes)
Hello all, I'm using the following scan() parameters on a tab-separated text file that was generated by R. temp_file <- scan(file = outfile, sep="\t", what = character(), skip = 1, nlines = 1) The problem is that within some cells, there are cases where there are three frontslashes ( /// ). However, the file itself is tab-separated, and the exact problem is that even if I
2010 Jul 14
2
How to define a function (with '<-') that has two arguments?
Hi All, The last line if the following code returns the error right below this paragraph. Essentially, I use the operator %:% to retrieve a variable in a nested frame. Then I want to use the same operator (with '<-') to change its value. I'm not sure if this is possible in R with %:% operator. Would you please help and let me how to correct the code if it is possible? Error in
2010 Jun 01
5
How to make R automatic?
Hello, I have a question about how R can run automatically. Here is the story: A file called "data.csv" will be generated every couple of minutes in a folder (overwrite itself). What I want R to do is: 1) scan the folder to find the file. 2) if the file is a newly generated file, process the file 3) output some file identifier on the screen, such as the time when the file was
2008 Dec 11
3
check if a certain ... argument has been passed on to my user-defined function
Hi, How can I check if a certain ... argument has been passed on to my user-defined function or not? foo <- function(data, ...) { ### here I want to check whether xlab was passed with the ... arguments ### or if the ... arguments did not contain an xlab argument } I tried missing(xlab) , exists(xlab) and several other things but did not find a solution. TIA, Mark
2008 Nov 30
1
selectively importing functions etc. from files
Hi, If I want to import the contents of a R file into another one, I can do source("foo.R") However, this imports everything from foo.R, including all functions and global variables. Is there a way of selectively importing individual functions etc., in a similar fashion to Python's from foo import bar ? Thanks in advance. Please cc me on any reply.