Displaying 20 results from an estimated 4000 matches similar to: "Apply as.factor (or as.numeric etc) to multiple columns"
2009 Apr 03
1
"factorise" variables in a data.frame
Dear list,
I often need to convert several variables from numeric or integer into
factors (before plotting, for instance), as in the following example,
d <- data.frame(
x = seq(1, 10),
y = seq(1, 10),
z = rnorm(10),
a = letters[1:10])
d2 <-
within(d, {
x = factor(x)
y = factor(y)
})
str(d)
str(d2)
I'd like to write a function factorise() which takes a data.frame and
2009 Jun 12
2
Squaring one column of data
Hi,
A fairly basic problem I think, here although searching the inetrnet doesn't
seem to reveal a solution. I have a dataset with two columns of real
numbers. It is read in via read.table. I simply need to square the data in
the second column and then plot it. I have tried extracting the second
column (b <- z[2]) and then squaring it and merging it to a variable which
is the first column
2006 Feb 21
6
How to sum values across multiple variables using a wildcard?
I have a dataframe called "data" with 5 records (in rows) each of
which has been scored on each of many variables (in columns).
Five of the variables are named var1, var2, var3, var4, var5 using
headers. The other variables are named using other conventions.
I can create a new variable called var6 with the value 15 for each
record with this code:
> var6=var1+var2+var3+var4+var5
2009 Dec 01
3
Using two (...) in a function
Hello R-Helpers,
I am not sure if it is a very simple question but I would like to use two
(...) in a function, for example,
this is a script where I would like to input the variable names (in one of
the (...)) and the variances associated to those variables which are not
calculated in the script because there is a specific software to calculate
it (the other (...))
data <- function
2009 Jul 15
1
Averaging dataframes that are stored in a list
Dear R-helpers,
I have a list containing 5000 elements, each element is a dataframe
containing one ID column (identical over the 5000 dataframes) and 9 numeric
variables, e.g.
ID VAR1 VAR2 VAR3 ... VAR9
I would like to create a new dataframe containing the ID column and the mean
values of the 9 numeric variables. So, the structure of this new dataframe
would be identical to the structure of the
2012 Sep 12
3
how to create a substraction matrix (subtract a row of every column from the same row in other columns)
Hello
I have data like this
x1 x2 x3 x4 x5
I want to create a matrix similar to a correlation matrix, but with the
difference between the two values, like this
x1 x2 x3 x4 x5
x1 x2-x1 x3-x1 x4-x1 x5-x1
x2 x3-x2 x4-x2 x5-x2
x3 x4-x3 x5-x3
x4 x5-x4
x5
Then I
2010 Jan 26
6
Help
> Dear All
>
> I have data as follows.
>
> D T M L
> 0.20 1 03 141
> 0.32 1 07 62
> 0.50 1 05 49
> 0.80 1 04 46
> 0.20 2 14 130
> 0.32 2 17 52
> 0.50 2 13 41
> 0.80 2 14 36
> 0.20 3 24 120
> 0.32
2007 Oct 18
3
Changing php5 with php4 in CentOS 5
Hi,
In our server CentOS 5 is installed. Some of our web pages are compatible
with php4 but in centOS 5 , php5 is installed and we cannot see our pages.
I want to remove php5 and install php4 but i could not find php4 rpm for
CentOS 5. Can anybody help me?
Thanks
Can ?izer
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
2003 Feb 14
5
Translating lm.object to SQL, C, etc function
This is my first post to this list so I suppose a quick intro is in
order. I've been using SPLUS 2000 and R1.6.2 for just a couple of days,
and love S already. I'm reading MASS and also John Fox's book - both have
been very useful. My background in stat software was mainly SPSS (which
I've never much liked - thanks heavens I've found S!), and Perl is my
tool of choice for
2007 Sep 29
1
templates with same name before extension are cached
Hi all,
I was just wondering if this is the intended behavior. Here is my setup:
controller
def index
respond_to do |f|
f.xml { render :xml => true }
f.html { render :layout => :none }
end
end
In my views I have a file for each type
index.herb
index.xerb
The first request I send is cached and interferes with the other one.
For example, if I send an xml request
2007 Jul 10
1
Lattice: vertical barchart
barchart(Titanic, stack=F) produces a very nice horizontal barchart.
Each panel has four groups of two bars.
barchart(Titanic, stack=F, horizontal=F) doesn't produce the results I
would have expected, as it produces this warning message:
Warning message:
y should be numeric in: bwplot.formula(x = as.formula(form), data =
list(Class = c(1,
And it results in each panel having 22 groups of
2005 Oct 19
3
diag() problem
Hi
I have a matrix "u", for which diag() gives an error:
u <- structure(c(5.42334674128216, -2.31319389204264, -5.83059042218476,
-1.64112369640695, -2.31319389212801, 3.22737617646609,
1.85200668021569,
-0.57102273078531, -5.83059042231881, 1.85200668008156,
11.9488923894962,
-3.5525537165941, -1.64112369587405, -0.571022730886046,
-3.55255371755604,
2025 Mar 30
1
Creating model formulas programmatically
Gabor, Duncan, et. al.
1. Thank you for your great comments and solutions. This is what I was
hoping for!
2. Duncan: I completely agree with your criticisms. In fact, I realized the
for() loop only needed the <- assignment, but your comment is important to
note. However, I didn't like the for() loop either; I *much* preferred your
Reduce() solution which is exactly the sort of elegant
2007 Jun 01
2
Getting names of objects passed with "..."
Is there a tidy way to get the names of objects passed to a function via the
"..." argument?
rbind/cbind does what I want:
test.func1 <- function(...) {
nms <- rownames(rbind(..., deparse.level=1))
print(nms)
}
x <- "some stuff"
second <- "more stuff"
test.func1(first=x, second)
[1] "first" "second"
The usual
2006 Feb 24
3
Sorting alphanumerically
I'm trying to sort a DATAFRAME by a column "ID" that contains
alphanumeric data. Specifically,"ID" contains integers all preceeded
by the character "g" as in:
g1, g6, g3, g19, g100, g2, g39
I am using the following code:
DATAFRAME=DATAFRAME[order(DATAFRAME1$ID),]
and was hoping it would sort the dataframe by ID in the following manner
g1, g2, g3, g6, g19,
2015 May 12
2
Why is the diag function so slow (for extraction)?
>>>>> Steve Bronder <sbronder at stevebronder.com>
>>>>> on Thu, 7 May 2015 11:49:49 -0400 writes:
> Is it possible to replace c() with .subset()?
It would be possible, but I think "entirely" wrong.
.subset() is documented to be an internal function not to be
used "lightly" and more to the point it is documented to *NOT*
1999 Aug 18
2
diag()
I would like to suggest a slight modification to diag(). In the case
where x is a matrix with both row names and column names the same, it
would be reasonable if the resulting vector also had those names. I often
use diag() on variance matrices, where this modification is helpful.
The modification requires replacing
if (is.matrix(x) && nargs() == 1)
return(c(x)[1 +
2011 Feb 19
1
Accessing Package NEWS (NEWS.Rd)
Okay. So, after having spent quite some time never really tracking down
why my package NEWS files were unacceptable to readNEWS(), I
noticed that there was recent (to me anyway) development that allowed
the NEWS to be done as an Rd file. Sweet! A more standard format...
I converted a NEWS file in one of my unreleased packages to Rd format.
checkNEWS() gave it a thumbs up.
But then it went south.
2025 Mar 30
1
Creating model formulas programmatically
Another solution. reformulate + substitute + as.formula:
substitute(~ (.)^2, list(. = reformulate(somenames)[[2]])) |> as.formula()
On Sat, Mar 29, 2025 at 5:31?PM Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
> Note: I am almost certain that this has been asked and answered here
> before, so my apologies for the redundant query.
>
> I also know that there are several
2015 May 05
3
Why is the diag function so slow (for extraction)?
Looks like the c(x)[...] bit used to be as.matrix(x)[...]. Not sure
why the change was made many years ago, but this was before names were
handled explicitly. It would definitely be better to not force the
duplicate, at least in the case where we are sure c() and [ would not
dispatch.
Best,
luke
On Mon, 4 May 2015, peter dalgaard wrote:
>
>> On 04 May 2015, at 19:59 , franknarf