Displaying 20 results from an estimated 600 matches similar to: "again, a question between R and C++"
2012 Aug 01
4
apply function over same column of all objects in a list
Hello. Please forgive me if this problem has already been posted (and solved)
by someone else ... I can't find it anywhere though it seems so very basic.
Here it is:
I have a list comprised of several matrices, each of which has two columns.
> list
[[1]]
[,1] [,2]
[1,] 1 3
[2,] 2 4
[[2]]
[,1] [,2]
[1,] 5 7
[2,] 6 8
[[3]]
[,1] [,2]
2007 May 16
2
substitute "x" for "pattern" in a list, while preservign list "structure". lapply, gsub, list...?
I am experimenting with some of the common r functions.
I had a question re:using "gsub" (or some similar functions) on the contents of a list.
I want to design a function that looks at "everything" contained din a list, and anytime it finds the text string "pattern" replace it with "x". I also wish to preserve the "structure" of the original
2009 Oct 12
1
Creating object referant from argument name
Hi all. I'd like to define an object within a function based on an argument
to that function.
Specifically, I've got:
do.something<-function(input){
id<-substring(input,3,3)
j<-list1
if(id==2)j<-list2
if(id==3)j<-list3
if(id==4)j<-list4
...}
Instead of all these if() arguments, I was hoping to use something like:
2010 Feb 26
3
Preserving lists in a function
Dear R users,
A co-worker and I are writing a function to facilitate graph plotting in R. The function makes use of a lot of lists in its defaults.
However, we discovered that R does not necessarily preserve the defaults if we were to input them in the form of list() when initializing the function. For example, if you feed the function codes below into R:
myfunction=function(
list1=list
2012 Jul 02
4
Assigning a vector to every element of a list.
I have a vector d of unknown length, and a list b of unknown length. I
would like to replace every element of b with d. Simply writing b<-d does
not work as R tries to fit every element of d to a different element of d,
and b<-rep(d,length(b)) does not work either as it makes a list of
length length(d)*length(b) not a list of length(b). I know how to do this
with a for loop, but I feel that
2004 Jun 23
5
assigning from multiple return values
I know that if I have a function that returns multiple values, I should
do return(list(foo, bar)). But what do I do on the recieving end?
fn <- function(x) {
return(list(foo, bar))
}
I know that at this point I could say
values.list <- fn(x)
and then access
values.list[1]
values.list[2]
But that's hideous. I'd rather be able to say something like
list(local_foo, local_bar)
2011 Feb 08
2
Extrcat selected rows from a list
Hi,
I have two lists
1) List1- 30,000 rows and 104 columns
2) List2- a list of 14000 selected rownames from List 1
Now, I want to extract all the 104 columns of List1 matching with the 14000 selected rownames from List2.
Psedocode will be something like this:
match rownames(List2) with rownames(List1)
extract selected matched 104 coloumns from (List1)
strore in-> List3
So the
2013 Feb 19
1
data format
Hi,
Try this:
el<- read.csv("el.csv",header=TRUE,sep="\t",stringsAsFactors=FALSE)
?elsplit<- split(el,el$st)
?
datetrial<-data.frame(date1=seq.Date(as.Date("1930.1.1",format="%Y.%m.%d"),as.Date("2010.12.31",format="%Y.%m.%d"),by="day"))
elsplit1<- lapply(elsplit,function(x)
2012 Jul 05
2
vector entry in matix
hi,
i'm trying to figure out if there's any possibility to write a whole vector
into a matrix or data.frame or something like that. i don't mean
transormation. Here an example:
[,1] [,2]
[1,] "a" "d"
[2,] "b" "e"
[3,] "c" "f"
where e.g. a is a<-c(0,1) vector of length 2, b a vector of length 4,... (i
know that
2004 Jun 02
1
How to iterate through two objects of class "list" fast?
Hi!
I have 2 list objects
One list contains the data (list1) the second list2 contains the e.g linear model for each element of list 1.
list2 <- lapply(list1,mylm,response) I obtain list 2 by something like this.
now I have a function myfunc which takes an element from list1 and the coresponding element from list2 does something and ....
list3[[x]] <- myfunc(list1[[x]],list2[[x]])
Until
2002 Oct 14
1
Question: concatenating lists
Dear R users,
I have the following problem. I have a number of lists with identical
structure. Each component is a vector, matrix or array, but components of
different lists may be of different size. How do I combine the lists to get
a new list such that each component of this list contains the components of
the individual lists?
An example may explain most clearly what I need.
Suppose I have
2009 Apr 15
6
Intersection of two sets of intervals
Hi,
Algorithm question: I have two sets of "intervals", where an interval is
an ordered pair [a,b] of two numbers. Is there an efficient way in R to
generate the intersection of two lists of same?
For concreteness: I'm representing a set of intervals with a data.frame:
> list1 = as.data.frame(list(open=c(1,5), close=c(2,10)))
> list1
open close
1 1 2
2 5
2011 Dec 28
3
transparency using plot+points with sp classes
How can I make one point graphics with transparency
These are all sp classes:
plot(polygons_area,axes=TRUE,asp=1.5,main="Title",xlab="Latitude",
ylab="Longitude")
points(observations2000,type = "p",pch=21,col="green")
points(observation1999,type = "p",pch=21,col="blue")
points(reference.points,type =
2006 Jun 26
0
sortables and accept question
i did some searching through the archives and didn''t really find an
answer to my question, so i''m going to just ask it.
i have a situation where there are 3 sortable lists. list1, list2,
and list3 i need list2 to accept divs from all 3 lists, but list1 and
list3 to only accept divs from the list1 and list3 i''ve added two
classes to the divs in my sortables: .rail
2006 Mar 03
13
Listing help
Hi,
I''ve created a Rails application and am having a problem listing by a
particular category in an associated table. I followed the instructions
found at the O''Reilly tutorial
(http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html?page=3) but have
not had success. Can anyone please outline a better set of instructions
than in the "Showing Recipes in a
2012 Oct 10
7
multiple t-tests across similar variable names
Hi everyone-
I have a dataset with multiple "pre" and "post" variables I want to compare. The variables are named "apple_pre" or "pre_banana" with the corresponding post variables named "apple_post" or "post_banana". The variables are in no particular order.
apple_pre orange_pre orange_post pre_banana apple_post post_banana
person_1
2004 Jul 27
4
SVD with positivity constraints
Hello,
I have a matrix equation, Ax=b, that I need to solve for x. x should be a
vector of positive numbers (between 0 and 1). A is not a square matrix in
general. This lead me to using the SVD. However, using the SVD gives me
positive and negative numbers, as well. I have some constraints included in
the A matrix itself (i.e., that the sum of some xi should be equal to 1) but
I do not know how
2016 Aug 18
5
[PATCH v2 0/4] New getprogname module
Hi,
as discussed in [1], this series adds a new getprogname module.
All it does is providing a getprogname function, much like what is
found on e.g. *BSD systems, and using it in gnulib instead of progname.
Also, using it explicitly by modules avoids gnulib users the need of
either use the progname module (GPL), or to provide program_name (and
call set_program_name manually, which is not always
2005 Dec 02
5
what is best for scripting?
I am using R in Windows. I see that I will have to use batch processes with
R. I will have to read and write text files, and run some R code; probably
some external code too. I have never done scripting. Is there any document
that explains simple steps with examples? I also have heard that Python is a
good scripting language. Is it worth the effort? (I do not have too much
free time, so if I could
2009 Jun 22
2
question about using _apply and/or aggregate functions
Hi R-list,
I'll apologize in advance for (1) the wordiness of my note (not sure
how to avoid it) and (2) any deficiencies on my part that lead to my
difficulties.
I have an application with several stages that is meant to simulate
and explore different scenarios with respect to product sales (in
units sold per month). My session info is at the bottom of this note.
The steps include (1) an