Displaying 20 results from an estimated 20000 matches similar to: "How to left or right truncate a character string?"
2010 Dec 14
2
How to bind models into a list of models?
Hi R-helpers,
I have a character object called dd that has 32 elements each of which
is a model formula contained within quotation marks. Here's what it
looks like:
> dd
[1] "lm(y ~ 1,data=Cement)" "lm(y ~
X,data=Cement)" "lm(y ~ X1,data=Cement)"
[4] "lm(y ~ X2,data=Cement)" "lm(y ~
2017 Sep 19
3
what do you think about write.table(... qmethod = "excel")?
Last week one of our clients reported trouble with a csv file I
generated with write.table. He said that columns with quotes for
character variables were rejected by their data importer, which was
revised to match the way Microsoft Excel uses quotation marks in
character variables. I explained to them that quoted character
variables are virtuous and wise, of course, but they say Microsoft
Excel
2004 Oct 28
1
gsub() on Matrix
Hi,
Suppose I've got a matrix, and the first few elements look like
"x1 + x3 + x4 + x5 + x1:x3 + x1:x4"
"x1 + x2 + x3 + x5 + x1:x2 + x1:x5"
"x1 + x3 + x4 + x5 + x1:x3 + x1:x5"
and so on (have got terms from x1 ~ x14).
If I want to replace all the x1 with i7, all x2 with i14, all x3 with i13,
for example. Is there an easy way?
I tried to put what I want
2010 Aug 20
4
Regex exercise
For regular expression afficianados, I'd like a cleverer solution to
the following problem (my solution works just fine for my needs; I'm
just trying to improve my regex skills):
Given the string (entered, say, at a readline prompt):
"1 2 -5, 3- 6 4 8 5-7 10" ## only integers will be entered
parse it to produce the numeric vector:
c(1, 2, 3, 4, 5, 3, 4, 5, 6, 8, 5, 6,
2017 Sep 19
2
what do you think about write.table(... qmethod = "excel")?
On 19/09/2017 4:10 PM, Ista Zahn wrote:
> On Tue, Sep 19, 2017 at 1:04 PM, Paul Johnson <pauljohn32 at gmail.com> wrote:
>> Last week one of our clients reported trouble with a csv file I
>> generated with write.table. He said that columns with quotes for
>> character variables were rejected by their data importer, which was
>> revised to match the way Microsoft
2009 Oct 05
1
gsub - replace multiple occurences with different strings
Hi,
I search a way to replace multiple occurrences of a string with
different strings
depending on the place where it occurs.
I tried the following;
x <- c("xx y e d xx e t f xx e f xx")
x <- gsub("xx", c("x1", "x2", "x3", "x4"), x)
what I want to get is;
x =
x1 y y e d x2 e t f x3 e f x4
but what I get is;
x =
x1 y y e
2012 Feb 17
5
How to change the order of columns in a data frame?
Dear all,
I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below.
> colnames(pos1)
[1] "X" "X1" "X10" "X11" "X12" "X13" "X14" "X15" "X16"
2013 Jun 10
2
please check this
Hi,
Try this:
which(duplicated(res10Percent))
# [1] 117 125 157 189 213 235 267 275 278 293 301 327 331 335 339 367 369 371 379
#[20] 413 415 417 441 459 461 477 479 505
res10PercentSub1<-subset(res10Percent[which(duplicated(res10Percent)),],dummy==1)? #most of the duplicated are dummy==1
res10PercentSub0<-subset(res10Percent[which(duplicated(res10Percent)),],dummy==0)
2010 Sep 12
4
using read.table, removing extra quotation mark from a text field? (e.g. ""cat" )
I am using read.table to import a text file within R.
There are several "errors" in my text file. An "extra" quotation mark has
inadvertently been included within a few text fields.
e.g. for a pipe (|) delimited text file, I have something similar to this:
1|7|30| "dog"
2|6|25| ""cat"
3|4|20|""
4|5| 56| "mouse"
5|3|56|
2012 Apr 30
2
Matrix transposition
Hi everyone.
I want to transpose a data frame. Lets say the following DF:
df = data.frame(matrix(ncol=4, nrow = 10))
df[,1] = c(rep(1,5),rep(2,5))
df[,2] = c(rep('a',4),rep('b',3),rep('c',3))
df[,3] = c(letters[5:14])
df[,4] = runif(10)
I would like to form a data frame with each line corresponding to colon X1
and create a variable with columns X2 and X3.
This would
2013 Nov 17
4
quotation marks and scan
Dear R People:
I'm sure that this is a very simple problem, but I have been wresting with
it for some time.
I have the following file that has the following one line:
CRS("+init=epsg:28992")
Fair enough. I scan it into R and get the following:
> u
[1] "CRS(\"+init=epsg:28992\")"
> gsub(pattern='\"',replacement='"',x=u)
[1]
2012 Jan 24
1
gsub semicolon with double quotation mark
Hi,
I would like to substitute a semicolon with two double quotation marks and
a comma inbetween.
It suppose to look like that:
I have:
FBpp0070086;FBpp0099643;FBpp0112915
I would like to have:
"FBpp0070086","FBpp0099643","FBpp0112915"
I tried with various numbers of backslashes, but noe have worked.
for example:
gsub(";", "\\\",\"",
2003 Oct 13
1
extracting quoted text from character string
Hello all,
I am trying to solve a problem, and my solution is rather ugly and not very
general. The posts for "[R] help with gsub and grep functions" seemed
relevent
and gave me hope for a more refined and more general solution.
The Problem:
line <- "'this text has spaces' 'thisNot' 3 4 5 6 7 8 9 10"
bad.line <- "'this text has spaces'
2010 Apr 24
2
left-to-right series of box and whisker plots from a csv file
Hi,
I've got a csv file with scores like this:
40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,32,38,40,20,40,26,40,30,40,5,5,13,12,40,40,3,33,29,23,2,24,9,15,4,21,16,5,26,8,8,18
40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,32,40,40,30,40,40,37,34,40,36,13,40,13,40,5,40,8,29,5,15,34,5,22,14,20
2006 Jul 16
1
Generating valid R code using R
Hi,
I'm trying to generate valid R code using R. Parts of the task is to
read a sequence of characters from file and escape them such that they
can be put in quotation marks to form a valid R code string. Example:
Let the input file be (four rows containing ASCII 0-255 characters):
abcdef<tab>ghijk\nlmno
second row\t\a\\
fourth and so on...
<EOF>
Now, find escapeString() such
2006 Jul 16
1
Generating valid R code using R
Hi,
I'm trying to generate valid R code using R. Parts of the task is to
read a sequence of characters from file and escape them such that they
can be put in quotation marks to form a valid R code string. Example:
Let the input file be (four rows containing ASCII 0-255 characters):
abcdef<tab>ghijk\nlmno
second row\t\a\\
fourth and so on...
<EOF>
Now, find escapeString() such
2011 Feb 04
4
aggregate function - na.action
Can someone please tell me what is up with na.action in aggregate?
My (somewhat) reproducible example:
(I say somewhat because some lines wouldn't run in a separate session, more
below)
set.seed(100)
dat=data.frame(
x1=sample(c(NA,'m','f'), 100, replace=TRUE),
x2=sample(c(NA, 1:10), 100, replace=TRUE),
x3=sample(c(NA,letters[1:5]), 100, replace=TRUE),
2012 Oct 20
2
Help with programming a tricky algorithm
Hi All,
I'm a little stumped by the following problem. I've got a dataset with
the following structure:
idxy ix iy country (other variables)
1 1 1 c1 x1
2 1 2 c1 x2
3 1 3 c1 x3
. . . . .
3739 55 67 c7 x3739
3740 55 68 c7 x3740
where ix and
2012 May 16
1
Merging multiple data sets
Hello R user,
I have four data sets in dir "D:/Bharat Warule/Rdata_file" which are
output_data_prod_1.rda, output_data_prod_2.rda, output_data_prod_3.rda,
output_data_prod_4.rda.
Each data set is huge size like number of rows 343297 and columns are near
to 50.
For example:
x1 <- data.frame(x11=c(1,2,3,4,5),x112=c(10,10,10,10,10))
x2 <-
2010 Sep 22
4
Crash report: regexpr("a{2-}", "")
Each of the following calls crash ("core dumps") R (R --vanilla) on
various versions and OSes:
regexpr("a{2-}", "")
sub("a{2-}", "")
gsub("a{2-}", "")
EXAMPLES:
> sessionInfo()
R version 2.11.1 Patched (2010-09-16 r52949)
Platform: i386-pc-mingw32 (32-bit)
...
> regexpr("a{2-}", "")
Assertion