similar to: specifying column names in a vector of characters and the use?

Displaying 20 results from an estimated 20000 matches similar to: "specifying column names in a vector of characters and the use?"

2006 Jan 19
1
numericDeriv() giving a vector when multiple variables input
R Help List -- I have defined two time-series-vector-valued-functions, let them be f and g, and want to find the numeric derivative of f with respect to the variable x where f depends on x through g: (d/dx)(f (g(x) ) Moreover, x is a vector I tried this out the long way (naming every element of the x vector and then making the 'theta' argument in numericDeriv() the character vector of
2007 Mar 10
2
Table Construction from calculations
Hi- I am trying to create a table of values by adding pairs of vectors, but am running into some problems. The problem is best expressed by a simple example. Starting with a data table "basis": atom x y z 1 Cu 0.0 0.0 0.0 2 Cu 0.5 0.5 0.5 I want to add 0.5 0.5 0.5 (and also the 0 0 0 but it wouldn't change the values below so I won't refer to it in the rest
2006 Aug 16
1
Specifying Path Model in SEM for CFA
I'm using specify.model for the sem package. I can't figure out how to represent the residual errors for the observed variables for a CFA model. (Once I get this working I need to add some further constraints.) Here is what I've tried: model.sa <- specify.model() F1 -> X1,l11, NA F1 -> X2,l21, NA F1 -> X3,l31, NA F1 -> X4,l41, NA F1 -> X5, NA, 0.20
2010 Jun 10
2
Specifying formula inside a function
Hello, How does one specify a formula to lm inside a function (with variable names not known in advance) and have the formula appear explicitly in the output? For example, f <- function(d) { in.model <- sample(c(0,1), ncol(d)-1, replace=T) current.model <- lm(paste(names(d)[1], "~", paste(names(d[2:ncol(d)])[which(in.model == 1)], collapse= "+")), data=d) #***
2006 Nov 17
2
Data table in C
After getting one list done, I am now struggling to form a data frame in C. I tried to do a list of lists which gives me : $<NA> $<NA>[[1]] [1] "BID" $<NA>[[2]] [1] 0.6718 $<NA>[[3]] [1] 3e+06 $<NA> $<NA>[[1]] [1] "BID" $<NA>[[2]] [1] 0.6717 $<NA>[[3]] [1] 5e+06 $<NA> $<NA>[[1]] [1] "BID"
2012 Apr 01
1
indexing in a function doesn't work?
Hello, I've written a small function that's supposed to save me some time, and it's ending up killing it- the intention is to iteratively subset a dataset fram on framevec, fit a model (either lm or nls depending on type) and return the r2 or AIC from the model, respectively. Although as far as I can tell in my code the plots are dependent on the fit of the model to the data and 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
2011 Feb 17
2
sort by column and row names
Hello, All, How can one sort on column and row names. For example: How can this X1 X3 X2 X1 1 0 0 X3 0 1 0 X2 0 0 1 become this? X1 X2 X3 X1 1 0 0 X2 0 1 0 X3 0 0 1 Thank you for your time! Jim [[alternative HTML version deleted]]
2009 Apr 15
3
excluding a column from a data frame
Dear R People: Suppose I have the following data frame: x1 x2 x3 1 -0.1582116 0.06635783 1.765448 2 -1.1407422 0.47235664 0.615931 3 0.8702362 2.32301341 2.653805 > str(xx) 'data.frame': 3 obs. of 3 variables: $ x1: num -0.158 -1.141 0.87 $ x2: num 0.0664 0.4724 2.323 $ x3: num 1.765 0.616 2.654 I can exclude the second column nicely via: >
2008 May 07
1
Automatically generating new column names (and columns)
Once again I need to tap into the collective knowledge here. Let's say I have the following columns and data below Y X1 X2 X3 X4 I would like to generate additional new columns and column names (ie the data would be squared - and I'd like the column names to reflect this) like: Y X1 X2 X3 X4 X1^2 X2^2 X3^2 X4^2 I believe I can compute the values correctly with the code below, but I
2005 Dec 08
2
how to change a dataframe with characters to a numeric matrix?
hi netters, i have a dataframe TEST like this: Y1 Y2 Y3 X1 4 7 8 X2 6 2 Z X3 8 0 1 i would like to change it to a numeric matrix, replacing "Z" with NA Y1 Y2 Y3 X1 4 7 8 X2 6 2 NA X3 8 0 1 i've tried the function data.matrix but it didn't work. is there any easy way to do this? thanks a lot!
2013 Oct 04
3
quote a column of a dataframe by its name
Dear All, I have a question, suppose X is a dataframe, with column names as "x1", "x2", "x3", ..... And I would like to use the i-th column by X[,'xi']. But it seems the single quote and double quote are different. So if I run X[, names(X)[i]], it has some error. Please use the below example code X = matrix(rnorm(50),ncol = 5) X = data.frame(X)
2006 Oct 15
1
how can i compute the average of three blocks for each column ?
Dear all, I want to compute the average of the three blocks for each x-variable which is equal slide in the code below. How can I do that ? block x1 x2 x3 x4 x5 1 23 22 23 24 23 1 21 25 26 21 39 1 23 24 22 23 23 2 20 21 23 24 28 2 32 23 34 24 26 2 19
2010 Mar 23
1
Conditional replacement of NA depending on value in the previous column
Dear R-helpers, I have a dataframe like this: ID X1 X2 X3 X4 X5 X6 49 1 1 1 0 NA NA 50 1 1 1 1 NA 1 I would like to convert a missing value (NA) that follows a 0 (zero) or another missing value (NA) into a 0 (zero). So, the above lines would be converted to: ID X1 X2 X3 X4 X5 X6 49 1 1 1 0 0 0 50 1 1 1 1 NA 1 I have been struggling with
2017 Jul 16
3
Arranging column data to create plots
Dear All, I need some help arranging data that was imported. The imported data frame looks something like this (the actual file is huge, so this is example data) DF: IDKey X1 Y1 X2 Y2 X3 Y3 X4 Y4 Name1 21 15 25 10 Name2 15 18 35 24 27 45 Name3 17 21 30 22 15 40 32 55 I would like to create a new data frame with the following NewDF: IDKey X Y Name1 21 15 Name1
2012 Jun 22
4
Search list of elements for a specific pattern
Hi, I have a list of mutations, called "mutList", of the form: > head(mutList) Alu 1 AluJ 2 AluJ/F(R)AM 3 AluJ/FLAM 4 AluJ/FRAM 5 AluJ/monomer 6 AluJb It contains about 500 elements and not all of them contain the sequence "Alu". I tried using this code: Alu<-mutList[which(grep("Alu",mutList)==1)] But that simply returned
2007 Jul 08
1
generating a data frame with a subset from another data frame
R gurus, I have a data set that looks something like this: Site Species DBH #Vines G PLOC 45.9 4 G ACNE 23.3 1 G ACNE 12.0 0 G FRAM 35.9 5 G AEGL 11.2 2 N PLOC 77.3 12 N JUNI 78.6 7 N ACNE 18.9 1 N ACNE 15.7 3 N ACRU 35.5 4 H ACSA2 24.1 6 H ULAM 35.2 7 There are 730 individual trees (22 species) from four sites in the actual data set. I would like to create a second data frame that
2006 Jul 08
2
String mathematical function to R-function
hello I make a subroutine that give-me a (mathematical) function in string format. I would like transform this string into function ( R function ). thanks for any tips. cleber #e.g. fun_String = "-100*x1 + 0*x2 + 100*x3" fun <- function(x1,x2,x3){ return( ############ evaluation( fun_String ) ############ ) True String mathematical function :-( :-( > nomes [1]
2017 Jul 16
0
Arranging column data to create plots
On Sat, 15 Jul 2017, Michael Reed via R-help wrote: > Dear All, > > I need some help arranging data that was imported. It would be helpful if you were to use dput to give us the sample data since you say you have already imported it. > The imported data frame looks something like this (the actual file is > huge, so this is example data) > > DF: > IDKey X1 Y1 X2 Y2
2009 Nov 04
3
Constrained Optimization
Hi All, I'm trying to do the following constrained optimization example. Maximize x1*(1-x1) + x2*(1-x2) + x3*(1-x3) s.t. x1 + x2 + x3 = 1 x1 >= 0 and x1 <= 1 x2 >= 0 and x2 <= 1 x3 >= 0 and x3 <= 1 which are the constraints. I'm expecting the answer x1=x2=x3 = 1/3. I tried the "constrOptim" function in R and I'm running into some issues. I first start off