Displaying 20 results from an estimated 10000 matches similar to: "Turning strings into expressions"
2004 Nov 04
5
Conversion of strings to expressions
Hello,
I'm not sure how to state my question in a technically accurate manner, so
I'll use a short example to clarify my problem:
Say I have a vector,
vec<-c(1,2,3,2)
I would like to be able to "reference" the vector by using the string
containing the name of the vector - that is, I would like to know of some
function which is able to convert the string "vec"
2004 Nov 25
4
Creating lists from matrices
Hello,
I am using R 1.9.1 on Windows 2000 SP4. I have the following problem:
Say I have a matrix,
>my.matrix
[,1] [,2] [,3]
[1,] "A" "B" "C"
[2,] "D" "E" "F"
[3,] "G" "H" "I"
I would like to apply an operation to this matrix which returns a list my.list
containing the
2004 Nov 11
11
Logical "and"
Hello,
I have the following very simple problem:
Say I have two vectors,
a<-c(1,7,4,5,9,11)
b<-c(7,4,9)
I would like to create a vector containing the elements in a which are not in
b.
Obviously, this is possible by writing
a[a!=b[1] & a!=b[2] & a!=b[3]]
But I would like a solution which is applicable to the situation where the
number of elements in b is unknown.
I have
2004 Jul 19
5
converting character strings to eval
Hi there fellow R-users,
I'm stuck on this seemingly trivial problem.
All I want to coerce a character string into a command.
For example:
x<-rnorm(20)
y<-rnorm(20)
str<-"lm(y~x)"
I want to evaluate the "str" command.
I have tried
eval(as.expression(str))
But it doesn't seem to work. I am aware of the call command, but for
reasons I won't go
2006 Jun 18
1
about the analysis of strings, thanks
Dear R-helpers:
thank your for your attention.
i am a newer to R and i am doing some protein category classification based on
the amino acid sequence.while i have some question urgent.
1. any packages for analysis amino acid sequence
2. given two sequences "AAA" and "BBB",how can i combine them into "AAABBB"
3. based on "AAABBB",how can i get some
2008 May 13
3
Regular Expressions
Hi R,
Again struck with regular expressions...
Suppose,
S=c("World_is_beautiful", "one_two_three_four","My_book")
I need to extract the last but one element of the strings. So, my output should look like:
Ans=c("is","three","My")
gsub() can do this...but wondering how do I give the regular expression....
2007 Aug 23
2
Splitting strings
I'm having a Thursday morning mental block, any suggestions on the following
would be most appreciated...
I have (as an example)
surgery = c("d48", "d67", "dnc37", "a75", "d10", "a78", "d31",
"d55", "d1")
before each number part the possibilities are c("a", "d",
2006 Sep 13
3
functions and strings
Hi
If
string <- "xyz"
f <- function(x){1 + sin(cos(x)) + exp(x^2)}
How do I manipulate "string" and f() to give the string
"1 + sin(cos(xyz)) + exp(xyz^2)"
?
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
2006 May 02
2
evaluation of expressions
Hi, all. I'm trying to automate some regression operations in R but am
confused about how to evaluate expressoins that are expressed as
character strings. For example:
y <- ifelse (rnorm(10)>0, 1, 0)
sex <- rnorm(10)
age <- rnorm(10)
test <- as.data.frame (cbind (y, sex, age))
# this works fine:
glm (y ~ sex + I(age^2), data=test, family=binomial(link="logit"),
2007 Oct 11
2
Identifying and characterizing strings of NA in a vector
Dear R users,
I was wondering if someone could suggest a few lines of code for my problem.
I want to count the number and the length of strings of NA in a vector.
For example:
vec <- c(1, 2, 1, NA, NA, 1, 2, NA, NA, NA, 3, 4, NA, NA)
has 2 strings of NA's of length 2 and 1 string of NA' of length 3.
I can easily count the number of NA's per vector, but I am having a hard
time
2004 Nov 17
8
referencing values of strings
Say you have a vector named x and a function which returns the character
string "x" . How would I take "x" as an input and return the vector x?
DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}}
2008 Apr 09
4
apply lm() for all the columns of a matrix
Hi all,
My question is not really urgent. I can write a loop and solve the
problem. But I know that I'll be in a similar situation many more times so
it would be useful to find out the answer
Is there a fast way to perform linear fit to all the columns of a matrix?
(or in the one dimension of a multi-dimensional array.) I'm talking about
many single linear fits, not about a multiple fit.
2006 May 12
3
Maximum likelihood estimate of bivariate vonmises-weibulldistribution
Thanks Dimitris!!! That's much clearer now. Still have a lot of work to
do this weekend to understand every bit but your code will prove very
useful.
Cheers,
Aziz
-----Original Message-----
From: Dimitrios Rizopoulos [mailto:Dimitris.Rizopoulos at med.kuleuven.be]
Sent: May 12, 2006 4:35 PM
To: Chaouch, Aziz
Subject: RE: [R] Maximum likelihood estimate of bivariate
2007 Dec 13
6
spliting strings ...
Hi everyone,
I have a vector of strings, each string made up by different number of words. I want to get a new vector which has only the first word of each string in the first vector. I came up with this:
str <- c('aaa bbb', 'cc', 'd eee aa', 'mmm o n')
str1 <- rep(1, length(str))
for (i in 1:length(str)) {
str1[i] <- strsplit(str, "
2006 Mar 02
2
'...' passed to both plot() and legend()
Dear R-devels,
I'd like to create a plot method for a class of objects that passes
the '...' argument to both plot() and legend(), e.g.,
x <- list(data = rnorm(1000))
class(x) <- "foo"
plot.foo <- function(x, legend = FALSE, cx = "topright", cy = NULL,
...){
dx <- sort(x$data)
plot(dx, dnorm(dx), type = "l", ...)
if (legend)
2008 May 06
2
Concatenate a vector into a string, only using distinct component
I'm trying to use combine c('a','b','c','a','c') into 'a, b, c', the order
does not matter.
paste(c('a','b','c','a','c'), collapse=', ') yields 'a, b, c, a, c'.
Any idea?
--
Regards,
Anh Tran
[[alternative HTML version deleted]]
2005 May 19
2
plot question
hi all:
xlim and ylim are used to define the interval limits of a plot. I'm interested in the scale of values between this limits.
suppose xlim=c(0,10)
we can have e.g.
0 5 10
0 2 4 6 8 10
0 1 2 3 4 5 6 7 8 9 10
which is the parameter that allows me to modify this?
thanks in advance
alexandre
2007 May 20
2
Number of NA's in every second column
Hi R-users,
How do I calculate a number of NA's in a row of every second column in my
data frame?
As a starting point:
dfr <- data.frame(sapply(x, function(x) sample(0:x, 6, replace = TRUE)))
dfr[dfr==0] <- NA
So, I would like to count the number of NA in row one, two, three etc. of
columns X1, X3, X5 etc.
Thanks in advance
Lauri
[[alternative HTML version deleted]]
2006 Jun 16
3
Vector Manipulation
I have a vector that has 1,974 elements and each element is one of the
following (B, F, N, Y). How do I recreate that vector accept in the
place of N put 0 and in the place of B, F or Y put a 1?
Thanks,
Jacob
[[alternative HTML version deleted]]
2005 Jan 21
2
chi-Squared distribution
Dear Rs:
outer(1:3, 1:3, function(df1, df2) qf(0.95, df1, df2))
I compare this F distribution results with the table, the answers were perfect. But I need to see for chi-sqaured distribution. When I employed the similar formula
outer(1:3, 1:3, function(df1, df2) qchisq(0.95, df1, df2)) , I am getting unexpected results. I need to see the following values:
p=0.750 .....
1 1.323