Displaying 20 results from an estimated 500 matches similar to: "Converting dataframe to matrix"
2008 May 27
4
help with simple function
I have a matrix of frequency counts from 0-160.
x<-as.matrix(c(0,1,0,0,1,0,0,0,1,0,0,0,0,1))
I would like to apply a function creating a new column (x[,2])containing
values equal to:
a) log(x[m,1]) if x[m,1] > 0; and
b) for all x[m,1]= 0, log(next x[m,1] > 0 / count of preceding zero values
+1)
for example, x[1,2] should equal log(x[2,1]/2) = log(1/2) = -0.6931472
whereas x[3,2] should
2009 Nov 15
2
Relase positive with log and zero of negative with 0
This is a very simple question but I couldn't form a site search quesry that would return a reasonable result set.
Say I have a vector:
x <- c(0,2,3,4,5,-1,-2)
I want to replace all of the values in 'x' with the log of x. Naturally this runs into problems since some of the values are negative or zero. So how can I replace all of the positive elements of x with the log(x) and the
2009 Jan 29
2
svmpath
Hi everyone,
I cannot install package "svmpath" on R 2.8.1 on Redhat Linux
.In fact I cannot install package externally.I am new to Linux so it would
be of great help if you all can help me out.
Regards,
Subhajit.
[[alternative HTML version deleted]]
2009 Jul 30
3
Looping through R objects with $ operator and tags
Hi all,
Suppose I want to set the values in a column to the log of the values
of another column like so:
object$LogDist <- log10(object$Distance)
How do I loop through the objects if I have object1, object2, etc to
perform this function?
object1$LogDist <- log10(object1$Distance)
object2$LogDist <- log10(object2$Distance)
object3$LogDist <- log10(object3$Distance)
I was trying to
2006 May 04
2
R 2.3.0 and rgl on OS X 10.4.6 (PR#8833)
I just downloaded and installed R 2.3.0 on my Mac G5 running
OS X 10.4.6. I also updated with R.app revision 3114 as
recommended. Now, when I attemp to use package rgl
I get the error
> library(rgl)
Error: package 'rgl' is not installed for 'arch=ppc'
>
I have tried reinstalling from CRAN using both binary
and source. The source install fails, The binary install
yields
2017 Jun 08
3
Math ops behaviour with multiple classes
I would expect that several math operations should always return values
with a class of numeric. If the input is defined with multiple classes,
however, the class attribute is preserved. I would think this may have
some unintended side-effects. Here's an example:
> sessionInfo()$R.version$version.string
[1] "R version 3.4.0 (2017-04-21)"
> x <- seq.int(5)
>
2008 Oct 03
1
NA's in segmented
I am trying to fit a very simple broken stick model using the package
"segmented" but I have hit a roadblock.
> str(data)
'data.frame': 18 obs. of 2 variables:
$ Bin : num 0.25 0.75 1.25 1.75 2.25 2.75 3.25 3.75 4.25 4.75 ...
$ LnFREQ: num 5.06 4.23 3.50 3.47 2.83 ...
I fit the lm easily:
> fit.lm<-lm(LnFREQ~Bin, data=id07)
But I keep getting an error
2018 Feb 19
0
questions regarding the svmpath package (functions svmpath and predict)
Hello,
I have two questions.
The svmpath package provides a svmpath function:
---
fit <- svmpath(xtrain, ytrain, kernel.function = radial.kernel, param.kernel = 0.8)
---
1) How to get the optimal lambda value out of this result?
The svmpath package also provides a predict function:
---
ytest <- predict(fit, xtest)
---
How to get a score (or a probability of belonging to one of the two
2011 Feb 21
0
list of features from svmpath?
How can I get the list of non-zero features from svmpath at any given
lambda? All I get is following information and information about what
features were selected. In Iris example, we have 4 features and 60 cases. In
my own example which is 200cases by 300 features, I can't figure out how to
print the list of non-zero (beta) or features from svmpath.
Any help? Thanks.
----------------
>
2011 Aug 05
2
[?]apply functions or for loop
Hello,
First time posting to this mail list.
I'd like to use R in the most efficient way. I'm accomplishing what I want,
but feel there is a more R'ish way to do it. Just learning R.
*My goal: get ranks of value across rows with row names and column names
intact.*
I'm guessing one of the [?]apply functions will do what I need, but I
couldn't sort out which one (after a lot
2010 Dec 15
1
lmList and lapply(... lm) different std. errors
Am I trying to perform multiple linear regressions on each 'VARIABLE2'. I
figured out that there are different ways, using the following code: (data
is given at the end of this message)
reg <- lapply(split(TRY, VARIABLE2), function(X){lm(X2 ~ X3, data=X)})
lapply(reg, summary)
Which produces the following:
$`1`
Call:
lm(formula = X2 ~ X3, data = X)
Residuals:
Min
2017 Jun 08
0
Math ops behaviour with multiple classes
I think you may be confusing (S3) class and ?mode.
> x <- seq.int(1:3)
> class(x)
[1] "integer"
> mode(x)
[1] "numeric"
> class(x+.5) ## coercion
[1] "numeric"
> mode(x+.5)
[1] "numeric"
But note:
> y <- as.integer(1)
> class(y)
[1] "integer"
> class(y) <- "foo"
> mode(y)
[1] "numeric"
>
2009 May 05
0
Re : Re : Support Vector Machines
Of course SVM is for supervise learning method (classification or regression). You cannot use a boat to fly man !
Justin BEM
BP 1917 Yaoundé
Tél (237) 99597295
(237) 22040246
________________________________
Envoyé le : Mardi, 5 Mai 2009, 16h07mn 10s
Objet : Re : [R] Support Vector Machines
Thank you.
I will look this later but I think i've saw this function and i'm not sure
2010 Sep 16
2
question about converting a matrix to a dataframe
First I have a matrix called stocks1:
> class(stocks1)
[1] "matrix"
Here are the first 5 rows of the last 4 columns:
> stocks1[1:5,2:5]
[,1] [,2] [,3] [,4]
[1,] 80.73 31.95 25.4 25.69
[2,] 83.66 31.95 27.12 25.2
[3,] 83.27 32.93 28.74 26.29
[4,] 83.9 34.07 29.77 26.6
[5,] 82.74 35.18 30.24 27.41
Now, why can't I convert this into a dataframe?
2017 Jun 08
1
Math ops behaviour with multiple classes
Thanks Bert, I think we agree on the current behaviour, but I'm still not sure if it's desirable. The mode isn't used for method dispatch. In the following example, I have to write `log.foo` in order for the correct method to be called.
> x <- seq.int(5)
> class(x) <- c("integer", "foo")
> half <- function(x) UseMethod("half")
>
2010 Aug 10
3
grep problem decimal points looping
Hi R Users,
I have been trying to work out how to rename column names using grep,
basically I have generated these column names using tapply:
[1] "NAME" "X1.1" "X2.1" "X3.1" "X4.1" "X5.1" "X6.1" "X7.1" "X8.1"
[10] "X1.2" "X2.2" "X3.2" "X4.2"
2007 May 24
4
Function to Sort and test AIC for mixed model lme?
Hi List
I'm running a series of mixed models using lme, and I wonder if there
is a way to sort them by AIC prior to testing using anova
(lme1,lme2,lme3,....lme7) other than by hand.
My current output looks like this.
anova
(lme.T97NULL.ml,lme.T97FULL.ml,lme.T97NOINT.ml,lme.T972way.ml,lme.T97fc.
ml, lme.T97ns.ml, lme.T97min.ml)
Model df AIC BIC logLik
2001 Oct 22
1
No subject
Dear all,
I may have overlooked something but the following piece of code causes me
trouble:
> a_data.frame(1:4)
> a
X1.4
1 1
2 2
3 3
4 4
> apply(a,2,cat)
1 2 3 4Error in ans[[1]] : subscript out of bounds
> apply(a,1,cat)
1234NULL
Is this the fact my data.frame has only one dimension ?
(and do I forget somewhere (but where ?) to specify not to 'drop'
2008 Jun 02
4
NOT-SO-SIMPLE function!
I am trying to set up a function which processes my data according to the
following rules:
1. if (x[i]==0) NA
2. if (x[i]>0) log(x[i]/(number of consecutive zeros immediately preceding
it +1))
The data this will apply to include a variety of whole numbers not limited
to 1 & 0, a number of which may appear consecutively and not separated by
zeros. Below is an example with a detailed
2008 Jan 21
2
experiments with slot functions and possible problems NOTE
Hello,
first of all, thanks to LT for \pkg{codeutils}. I agree that it is
indeed very useful to identify errors and also to encourage re-thinking
past solutions. My problem:
I want to compare different sets of related sub-functions which should
be used alternatively by the same top-level function. Sets of related
functions should be bound together (as lists) and the workspace should
be as clean