similar to: extracting named vector from dataframe

Displaying 20 results from an estimated 20000 matches similar to: "extracting named vector from dataframe"

2010 Mar 10
4
write.fortran
Dear all, I'm trying to write tabular data to a text file, these data will be the input of a Fortran program. The format needs to be "(i7,2x,7(e15.7,2x))". I have not been able to find a clean way of producing this output with write.table. I searched for a "write.fortran" function similar to read.fortran() in package utils but I couldn't find any. Below is a small
2010 Oct 24
3
Long model formulae
What is a good way to enter a very long model formula. For example: y ~ Input.2 + Input.3 + ... + Input.1000 (assuming the corresponding dataframe has many other columns). Is there a way to convert a character string to a formula? Are there command line expansions in R besides the simple '.'? Thanks. [[alternative HTML version deleted]]
2010 Sep 09
1
scalable < > delimiters in plotmath
Dear list, I read in ?plotmath that I can use bgroup to draw scalable delimiters such as [ ] and ( ). The same technique fails with < > however, and I cannot find a workaround, grid.text(expression(bgroup("<",atop(x,y),">"))) Error in bgroup("<", atop(x, y), ">") : invalid group delimiter Regards, baptiste sessionInfo() R version
2010 Sep 09
1
scalable < > delimiters in plotmath
Dear list, I read in ?plotmath that I can use bgroup to draw scalable delimiters such as [ ] and ( ). The same technique fails with < > however, and I cannot find a workaround, grid.text(expression(bgroup("<",atop(x,y),">"))) Error in bgroup("<", atop(x, y), ">") : invalid group delimiter Regards, baptiste sessionInfo() R version
2010 Oct 04
3
read columns of quoted numbers as factors
Suppose I have a data file (possibly with a huge number of columns), where the columns with factors are coded as "1", "2", "3", etc ... The default behavior of read.table is to convert these columns to integer vectors. Is there a way to get read.table to recognize that columns of quoted numbers represent factors (while unquoted numbers are interpreted as
2009 Oct 01
1
inverse currying
Dear list, I have the following function, sugar = function(fun, id = "id"){ ff <- formals(fun) if( id %in% names(ff)) stop("id is part of args(fun)") formals(fun) <- c(unlist(ff), alist(id=)) fun } which one may use on a function foo, foo = function(x){ x } sugar(foo) # results in the extended closure, function (x, id) { x } Its limitation (other
2010 Sep 21
3
bivariate vector numerical integration with infinite range
Dear list, I'm seeking some advice regarding a particular numerical integration I wish to perform. The integrand f takes two real arguments x and y and returns a vector of constant length N. The range of integration is [0, infty) for x and [a,b] (finite) for y. Since the integrand has values in R^N I did not find a built-in function to perform numerical quadrature, so I wrote my own after
2011 Apr 18
4
splom, plotmath: how to add three lines of information with alignment?
Dear expeRts, I would like to create a scatter plot matrix with splom(). The lower panel should contain some additional information about the samples shown in the upper panel plot, see the splom() call below. Now two questions came up: (1) The lower panels show "tau" and "alpha" on top of each other. How can I plot *three* expressions on top of each other? I tried several
2009 Sep 28
2
dichromat, regexp, and grid objects
Dear list, The dichromat package defines a dichromat function which "Collapses red-green color distinctions to approximate the effect of the two common forms of red-green colour blindness, protanopia and deuteranopia." library(dichromat) library(grid) colorStrip <- function (colors = 1:3, draw = TRUE) { x <- seq(0, 1 - 1/length(colors), length = length(colors)) y <-
2009 Oct 06
2
ggplot equivalent of par(xaxt)
I am playing around learning ggplot and cannot see how to suppress the x or y axis values ( equivalent of xaxt in basic graphics) It must be obvious but I'm not seeing it. Problem ================================================================= timedata <- structure(list(month = structure(c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
2009 Jul 03
3
Variable names in lattice XY-plot
Hi, how can I get a more descriptive text instead of the variable names in my XY-lattice plot, according to the table below? Variable text acet = "Acetylaspartate Thalamus" chol = "Choline Thalamus" acetp = "Acetylaspartate parieoc" ino = "Inositole Thalamus" I could not find a solution. Please have a look at my syntax. Thanks a lot,
2009 Apr 14
2
subset dataframe by rows using character vector?
Dear List, I'm stuck on what seems like a simple indexing problem, I'd be very grateful to anyone willing to help me out. I queried a dataframe which returns a character vector called "plot". I have another dataframe from which I want to subset or select only those rows that match "plot". I've tried subset, and also the "which" command. plot
2009 Apr 03
3
plyr and table question
Dear all, I'm puzzled by the following example inspired by a recent question on R-help, cc <- textConnection("user_id website time 20 google 0930 21 yahoo 0935 20 facebook 1000 25 facebook 1015 61 google 0940") d <- read.table(cc, head=T) ; close(cc) table(d$user_id) # count the
2010 Aug 11
2
help to polish plot in ggplot2
Hi, I wanted to generate a plot which is almost like the plot generated by the following codes. category <- paste("Geographical Category", 1:10) grp1 <- rnorm(10, mean=10, sd=10) grp2 <- rnorm(10, mean=20, sd=10) grp3 <- rnorm(10, mean=15, sd=10) grp4 <- rnorm(10, mean=12, sd=10) mydat <- data.frame(category,grp1,grp2,grp3,grp4) dat.m <- melt(mydat) p <-
2016 Mar 29
1
documentation / warning when passing a vector as lower/upper bound in stats::integrate()
Dear R-dev list, I wonder if stats::integrate shouldn't warn the user when a numeric vector of length > 1 is passed as lower or upper bounds. If a vector is passed, only the first value is used and the others are silently ignored: integrate(sin, lower=0, upper=pi) integrate(sin, lower=0:10, upper=pi) ?integrate doesn't appear to mention explicitly that the function is not vectorised
2011 Mar 09
2
switch and factors
Dear list, Reading the help page for ?switch didn't give me more than a hint at what's going on here, x = 5 y = 2 foo <- function(a="x"){ switch(a, "x" = x, "y" = y) } foo(factor('x', levels=c('y', 'x'))) # 2 It seems that switch, when given a factor, uses the numeric codes rather than the string
2009 Mar 25
2
"[.data.frame" and lapply
Dear all, Trying to extract a few rows for each element of a list of data.frames, I'm puzzled by the following behaviour, > d <- lapply(1:4, function(i) data.frame(x=rnorm(5), y=rnorm(5))) > str(d) > > lapply(d, "[", i= c(1)) # fine, this extracts the first columns > lapply(d, "[", j= c(1, 3)) # doesn't do nothing ?! > > library(plyr)
2009 Mar 25
2
"[.data.frame" and lapply
Dear all, Trying to extract a few rows for each element of a list of data.frames, I'm puzzled by the following behaviour, > d <- lapply(1:4, function(i) data.frame(x=rnorm(5), y=rnorm(5))) > str(d) > > lapply(d, "[", i= c(1)) # fine, this extracts the first columns > lapply(d, "[", j= c(1, 3)) # doesn't do nothing ?! > > library(plyr)
2009 Nov 10
3
drop unused levels in subset.data.frame
Dear list, subset has a 'drop' argument that I had often mistaken for the one in [.factor which removes unused levels. Clearly it doesn't work that way, as shown below, d <- data.frame(x = factor(letters[1:15]), y = factor(LETTERS[1:3])) s <- subset(d, y=="A", drop=TRUE) str(s) 'data.frame': 5 obs. of 2 variables: $ x: Factor w/ 15 levels
2009 Jun 09
2
removing elements from a "unit" vector
Dear list, I'm quite surprised by this, unit(1:5,"char")[-c(1:2)] #4char 3char # what's going on?? while I expected something like, c(1:5)[-c(1:2)] # 3 4 5 Note that, unit(1:5,"char")[c(1:2)] # 1char 2char # fine ?unit warns about unit.c for concatenating, but also says, It is possible to subset unit objects in the normal way (e.g.,