Displaying 20 results from an estimated 1000 matches similar to: "writing text and output to file with flexibility"
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
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,
2009 Sep 04
2
transforming a badly organized data base into a list of data frames
Dear R-ers!
I have a badly organized data base in Excel. Once I read it into R it
looks like this (all variables become factors because of many spaces
and other characters in Excel):
2009 Oct 26
1
regular expressions
Dear list,
I have the following text to parse (originating from readLines as some
lines have unequal size),
st = c("START text1 1 text2 2.3", "whatever intermediate text", "START
text1 23.4 text2 3.1415")
from which I'd like to extract the lines starting with "START", and
group the subsequent fields in a data.frame in this format:
text1 text2
2006 Mar 26
2
Shared Columns in an STI
I have a an STI table which acts_as_tree, that has a large number of
classes/types. My common fields are:
id
parent_id
name
description
with 4 more text fields, I could cover most of my classes if I could
redefine the name of the field like this.
text1 AS address1
text2 AS address2
text3 AS zipcode
For one class and
text 1 AS model_number
text2 AS vendor
Is there a construct that will allow
2009 Sep 06
1
struggling with "split" function
I am very sorry for such a simple question, but I am struggling with "split".
I have the following data frame:
x<-data.frame(A=c(NA,NA,NA,NA,"split",NA,NA,NA,NA,"split",NA,NA,NA,NA,"split",NA,NA,NA,NA),
2017 Sep 28
2
Searching for Enumerated Items using str_count() from the stringr package
Hi all,
I have a large number of text strings to search for enumerated items.
However, I am receiving this error message even though I thought that I
properly escaped the special character closed parenthesis:
> Count<-str_count(text3,keywords)
Error in stri_count_regex(string, pattern, opts_regex = opts(pattern)) :
Syntax error in regexp pattern. (U_REGEX_RULE_SYNTAX)
===
Here is
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
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
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
2017 Sep 28
0
Searching for Enumerated Items using str_count() from the stringr package
On 09/28/2017 10:25 PM, Dan Abner wrote:
> Hi all,
>
> I have a large number of text strings to search for enumerated items.
> However, I am receiving this error message even though I thought that I
> properly escaped the special character closed parenthesis:
>
>
>> Count<-str_count(text3,keywords)
> Error in stri_count_regex(string, pattern, opts_regex =
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]]
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 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]]
2013 May 18
3
OT: Script Help
Sorry for the off topic, but don't a better resource. I'm not great at
scripting, but need a quick script to modify a file.
I have a long file that has lines like this:
some text
some text2
CN=DATA.OU=XYZ.O=CO
some text3
some text4
And this repeats, but XYZ changes. "DATA" is always called data. (it's
being renamed basically)
I need to change the middle line but leave
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:
2009 Oct 20
1
plotting labels (not values) on xy plot
I have 2 vectors, x and y and have done an xy plot.
I want to plot the label (name?) of the vector on the plot rather than the
value.
text(x,y, labels = x)
gives me the value of x.
text(x,y, labels = labels(x))
gives me something like c("text1","text2"..) plotted for each point
text(x,y, labels = names(x))
gives nothing
print(x) gives me
[,1]
text1
2005 Sep 08
1
Converting a matrix to a dataframe: how to prevent conversion to factor
Colleages
I am running R 2.1.0 on a Mac (same problem occurs in Linux). In
some situations, I have mixed text/numeric data that is stored as
characters in a matrix. If I convert this matrix to a dataframe, the
numeric data becomes factors, not what I intend.
TEXT <- paste("Text", 1:4, sep="")
NUMBERS <- 10 + 4:1
MATRIX <- cbind(TEXT,
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
2008 Jan 09
4
Using Prototype - Getting Javascript Error - "Object doesn't support this property or method"
I have the following javascript being called on my site and I am
getting a Javascript error - "Object doesn''t support this property or
method". The error is invoked on the line that has - "listItems = $
("vidList").childElements("li");".
The purpose of the Javascript is two fold: ''swapVideo'' to change the
Youtube video and