Displaying 20 results from an estimated 200 matches similar to: "replacing ugly for loops"
2011 Sep 08
6
Searching the console
Is there any way to search the console during an interactive session? I've
looked and looked, and can not find one. In some add-on package, maybe?
Sorry to be so basic, but help would be greatly appreciated.
andrewH
--
View this message in context: http://r.789695.n4.nabble.com/Searching-the-console-tp3797884p3797884.html
Sent from the R help mailing list archive at Nabble.com.
2011 Aug 01
1
Inserting column in between -- "better" way?
Folks:
I consider my reply below rather clumsy: One has to keep track of
index numbers other than that which is inserted and must separately
change column names. Is there as "essentially better" way to do this,
either via base R or via an R package. I leave it to you to define
"essentially better."
Thanks.
Cheers,
Bert
On Mon, Aug 1, 2011 at 10:17 AM, Bert Gunter
2012 Nov 03
8
Can you turn a string into a (working) symbol?
Dear folks--
Suppose I have an expression that evaluates to a string, and that that
string, were it not a character vector, would be a symbol. I would like a
function, call it doppel(), that will take that expression as an argument
and produce something that functions exactly like the symbol would have if I
typed it in the place of the function of the expression. It should go as
far along the
2013 Jan 15
2
Sparse dataframes?
Dear Folks--
Is there a data frame analog to sparse matrices? I am working with a panel
data set that has a large number of variables that are redefined repeatedly
or exist for only a few years (out of 48). In my current structure, where
variables are columns and rows are years, more than 90 percent of the cells
and more than 3/4 of the total size of my file are NAs.
I am wondering if there is
2013 Dec 09
2
How can I find nonstandard or control characters in a large file?
I have a humongous csv file containing census data, far too big to read into
RAM. I have been trying to extract individual columns from this file using
the colbycol package. This works for certain subsets of the columns, but not
for others. I have not yet been able to precisely identify the problem
columns, as there are 731 columns and running colbycol on the file on my old
slow machine takes
2011 Oct 05
6
reporting multiple objects out of a function
Dear folks,
I?m trying to build a function to create and make available some variables I
frequently use for testing purposes. Suppose I have a function that takes
some inputs and creates (internally) several named objects. Say,
fun1 <- function(x, y, z) {obj1 <- x; obj2 <- y; obj3 <- z
<missing stuff>
}
Here is the challenge: After I run it, I want the objects to be
2012 Nov 13
5
Getting information encoded in a SAS, SPSS or Stata command file into R.
Dear folks ?
I have a large (26 gig) ASCII flat file in fixed-width format with about 10
million observations of roughly 400 variables. (It is 51 years of Current
Population Survey micro data from IPUMS, roughly half the fields for each
record). The file was produced by automatic process in response to a data
request of mine.
The file is not accompanied by a human-readable file giving the
2011 Aug 16
1
Can you send "side effect" text into a variable?
Dear folks --
There are a number of functions -- I am thinking of str() as an example --
that produce text as a side-effect, rather then returning it. Is there any
way to send the text produced by such functions into a character variable?
Any suggestions would be greatly appreciated.
andrewH
--
View this message in context:
2006 Feb 03
1
Using string vectors as for loop arguments
Is there a mechanism to interate through a vector of strings? Say I
have a data frame of 50 variables (VAR1 to VAR50), each with 100
measurements along with some coding factors (EXP and DOSE). I want to
calculate the mean of a subset of each of VAR1 to VAR 50 (selecting
by EXP and DOSE). Rather than just copy/pasting the same code 50
times, I thought of using a for loop to go through a
2011 Sep 15
2
Returning the name of an object passed directly or from a list by lapply
Dear folks:
Let?s suppose I want a function to print return the name of the object
passed to it.
> myname <- function(object) {out<-deparse(substitute(object)); out}
This works fine on a single object:
> O1 <-c(1:4)
> myname(O1)
[1] "O1"
However it does not work if you use lapply to pass it the same object from a
list:
> O2 <-c(1:4)
> object.list <-
2011 Sep 17
1
Name the dots! ("...")
Dear Folk--
Suppose I have some objects A, B & C, and a function
getDots <- function(...) {args <- list(...) etc.}
If I do a call to getDots(A, B, C) then the variable args will be assigned
to a list which contains the objects to which A, B & C refer, but which will
not (except by happenstance) contain the names A, B, or C. I would like
getDots to return a named list, with the
2011 Sep 16
2
Referring to an object by a variable containing its name: 6 failures
Dear Folks--
I'm trying to make a function that takes the columns I select from a data
frame and then uses a for loop to print some information about each one,
starting with the column name. I succeed in returning the column name, but
nothing else I have tried using the variable colName, containing the name of
the column, to refer to the column itself has worked.
Below I show my
2009 Jul 15
2
Differing Variable Length Inconsistencies in Random Effects/Regression Models
Dear All,
I am quite new to R and am having a problem trying to run a linear model
with random effects/ a regression- with particular regard to my variable
lengths being different and the models refusing to compute any further.
The codes I have been using are as follows:
vc<-read.table("P:\\R\\Testvcomp10.txt",header=T)
>> attach(vc)
>
> family<-factor(family)
>
2011 Oct 27
2
Consistant test for NAs in a factor when exclude = NULL?
Dear folks?
Is there a function to correctly find (and count) the NAs in a factor when
exclude=NULL, regardless of whether their origin is in the original data or
by subsequent assignment?
In example number 1 below, where NAs are assigned by is.na()<-, testing the
factor with is.na() finds the correct number of NAs. In example number 2,
where the NAs are from the data, neither is.na(), ==NA,
2013 Mar 04
4
Learning the R way – A Wish
There is something that I wish I had that I think would help me a lot to be a
better R programmer, that I think would probably help many others as well.
I put the wish out there in the hopes that someone might think it was worth
doing at some point.
I wish I had the code of some substantial, widely used package ? lm, say ?
heavily annotated and explained at roughly the level of R knowledge of
2005 May 24
3
obtaining first and last record for rows with same identifier
I have a dataframe that contains fields such as patid, labdate, labvalue.
The same patid may show up in multiple rows because of lab measurements on
multiple days. Is there a simple way to obtain just the first and last
record for each patient, or do I need to write some code that performs that.
Thanks,
Steven
2012 Nov 27
1
Using factor variables with overlapping categories
ear folks ?
I have a question, though it is more of a logic- or a good
practices-question than a programming question per se. I am working with
data from the American Community Survey summary file. It is mainly
categorical count data. Currently I am working with about 40 tables covering
about 35 variables, mainly in two-way tables, with some 3-way and a handful
of four-way tables. I am going to
2012 Feb 25
5
which is the fastest way to make data.frame out of a three-dimensional array?
foo <- rnorm(30*34*12)
dim(foo) <- c(30, 34, 12)
I want to make a data.frame out of this three-dimensional array. Each dimension will be a variabel (column) in the data.frame.
I know how this can be done in a very slow way using for loops, like this:
x <- rep(seq(from = 1, to = 30), 34)
y <- as.vector(sapply(1:34, function(x) {rep(x, 30)}))
month <- as.vector(sapply(1:12,
2011 Jul 09
3
Using str() in a function.
Using str() in a function.
I am in the early phase of learning R, and I find I spend a lot of time
trying to figure out what is actually in objects I have created or read in
from a file. I'm trying to make a simple little function to display a
couple of things about a object, let's say the summary() and the str(),
sequentially, preferably without a bunch of surplus lines between them. I
2011 Sep 13
2
Reading R Code aloud
Dearfolks--
I have been told by an experienced R programmer and teacher whom I trust
that it is easier to understand R code if you read it aloud, as the language
that it is. However, she was clear that reading it aloud was not simply
reading the marks on the screen: you read A.df[5,] as "the fifth row of
A.df" (or "the fifth row of data frame A"), not as "A dot df left