Displaying 16 results from an estimated 16 matches for "gferraz29".
2012 Nov 08
4
Accessing selected elements of a list
Hi,
If I have a vector:
junk <- c(2,0,0,3,0)
and want to access, say, all the elements that are greater than zero. I just do:
junk[which(junk>0)]
Now, If I have a list:
jlist <- list(NULL,c(1,0),NULL,c(1,2,3), NULL)
and want to access all the elements that have length greater than zero, I know how to find the elements with:
which(sapply(jlist,length)>0)
But how do I get a
2007 Aug 17
4
matching elements from two vectors
Hi,
Imagine a vector x with elements (1,2,1,1,3,5,3,3,1) and a vector y with
elements (2,3). I need to find out what elements of x match any of the
elements of y.
Is there a simple command that will return a vector with elements
(F,T,F,F,T,F,T,T,F). Ideally, I would like a solution that works with
dataframe colums as well.
I have tried x==y and it doesn't work.
x==any(y) doesn't work
2007 Aug 21
2
extracting month from date in numeric form
Hi,
Anyone knows what would be a short way of extracting a month from a date in
numeric or integer format?
months("1979-12-20")
returns
"December" in character format.
How could I get 12 in numeric or integer format?
Thanks!
G.
[[alternative HTML version deleted]]
2013 Nov 21
2
overlaying 2D grid on randomly distributed points
Hi, I have a cloud of randomly distributed points in 2-dimensional space and want to set up a grid, with a given grid-cell size, that minimizes the distance between my points and the grid nodes. Does anyone know of an R function or toolbox that somehow addresses this problem? This is a problem of optimizing the location of the grid, not a problem of deciding what should be the grid-cell size,
2007 Aug 17
1
finding the row(s) for a date in a data frame
Hi,
If I have a data frame A with the following format:
Day1 Day2 Day3 Day4
1 1979-11-02 1979-11-03 1979-11-04 <NA>
2 1979-12-06 <NA> <NA> <NA>
3 1979-12-13 1979-12-14 1979-12-15 1979-12-16
4 1979-12-20 <NA> <NA> <NA>
And a date "1979-12-14", for
2008 Jan 27
1
calling a list element from a list name passed to a function
Hi,
'true_name' is a list of numerical, matrix, and text items
I do
pass_name <- "true_name"
and pass the name of the list to a function so that the character
class variable 'passed_name' contains the name of the list called
'true_name'
Inside the function, how can I get a specified element from the list?
For example, if I want to get
2009 Jan 21
1
finding row and column indices of date in multiple columns of a data frame
Hi,
I have a data.frame SAMPLES with columns:
Site Site# Season Day1 Day2 Day3
Day1, Day2, Day3 are class "Date", the other columns are numeric or
factor.
I have a date "mydate" that may or may not be listed in my data.frame
and I need to find that out.
If "mydate" is there, I want to get the number of the data.frame row
where it occurs.
2007 Sep 11
0
Odp: storing text and decimal values in a matrix form
Hi
Gon?alo Ferraz <gferraz29 at gmail.com> napsal dne 11.09.2007 16:35:57:
> Thanks! What is the easiest way of declaring an empty data frame. Is
there
> anything similar to:
> matrix(0,x,y)
> In the help files, I am only finding longer commands that ask me to
specify
> each individual column.
You can e...
2008 Mar 13
2
joining matrices, vectors, scalars in one object
Hi,
I have:
a <- matrix(c(0,1,0,1),nrow=2)
b <- matrix(c(1,1,1,0,0,0),nrow=3)
c <- 1
d <- c(1,0,1)
And I would like to join them in an object 'thing' so that I can
access a, b, c, or d through an index in a for loop.
For example:
thing[4]
would return
[1] 1 0 1
Note however, that I have many of these 'thing' components. So many
that a command like
thing
2010 Aug 20
3
change object name within for loop
Hi,
I am writing a for loop that creates one object, say 'outn' on every
round of the loop. I would like the name of each object to include the
index of the loop as in, for example:
out1, out2, out3, ...
And I would like the naming of the object to take place automatically
as the loop moves through?
Similarly, I would like to be able to call different objects (in1,
in2, in3,
2011 Sep 08
3
Density function: Area under density plot is not equal to 1. Why?
Hi, I have a vector 'data' of 58 probability values (bounded between 0 and 1) and want to draw a probability density function of these values. For this, I used the commands:
data <- runif(58)
a <- density(data, from=0, to=1)
plot(a, type="l",lwd=3)
But then, when I try to approximate the area under the plotted curve with the command:
area <- sum(a$y)*(a$x[1]-a$y[2])
2008 Aug 30
1
writing text and output to file with flexibility
Hi,
I want a function to write some of its output into a text file with
the following format:
'some text'
output matrix A
'some more text'
output matrix B
'some other text still'
output matrix C
...
The dimensions of matrices A, B, ... are different and the total
number of matrices
that I want to place in the text file depends on what I pass to the
function. (I
2009 Jan 30
1
simulating outcomes - categorical distribution (?)
Hi,
I am simulating an event that has 15 possible outcomes and I have a
vector 'pout' that gives me the probability of each outcome -
different outcomes have different probabilities. Does anyone know a
simple way of simulating the outcome of my event?
If my event had only two possible outcomes (0/1) I would pick a
uniform random number between 0 and 1 and use it to choose between the
two
2007 Sep 11
1
storing text and decimal values in a matrix form
Hi,
I would like to store some text and decimal values in the following
form:
name dec.val dec.val ... dec.val
name dec.val dec.val ... dec.val
...
name dec. val dec.val ... dec.val
To do so, I created a matrix of the necessary size (x row per y cols)
with the command
matrixname <- matrix(0,x,y)
and proceeded to fill in the matrix with information drawn from a
data frame.
The
2008 Mar 15
3
locating minimum value in matrix
Hi,
I have a matrix BEE and want to find the row and column numbers of
the minimum value in that matrix.
The command
which(BEE==min(BEE))
returns only one value which, I take, is the position of the minimum
in a vector with as many elements as the matrix.
Is there a quick and simple way of getting row and column numbers?
Thanks,
Gonçalo
[[alternative HTML version deleted]]
2007 Oct 15
2
clipping off words inside a vector of strings
Hi,
I have a vector of strings (class character) with 6 elements (length
6). I call it 'names'.
"Graham Chapman"
"John Cleese"
"Terry Gilliam"
"Eric Idle"
"Terry Jones"
"Michael Palin"
And I want to turn it into another vector of strings called
'shortnames' with the same length.
The new vector should look like: