Displaying 20 results from an estimated 40000 matches similar to: "Adding Column to Data Frames Using a Loop"
2013 Apr 29
3
Function for Data Frame
Dear R Helpers,
I have about 20 data frames that I need to do a series of data scrubbing
steps to. I have the list of data frames in a list so that I can use
lapply. I am trying to build a function that will do the data scrubbing
that I need. However, I am new to functions and there is something
fundamental that I am not understanding. I use the return function at the
end of the function and
2013 Apr 30
1
Looping Over Data Frames
Dear R Helpers,
I am re-phrasing a question that I put forth earlier today due to some
particulars in the solution that I am searching for. Many thanks to those
who answered the previous post and to any who would be willing to answer
this one.
I have a set of data frames. I need to perform some data scrubbing on
each of them. I am trying to figure out how to perform the same steps on
each
2013 May 17
2
Selecting A List of Columns
Dear R Helpers,
I need help with a slightly unusual situation in which I am trying to
select some columns from a data frame. I know how to use the subset
statement with column names as in:
x=as.data.frame(matrix(c(1,2,3,
1,2,3,
1,2,2,
1,2,2,
1,1,1),ncol=3,byrow=T))
all.cols<-colnames(x)
to.keep<-all.cols[1:2]
Kept<-subset(x,select=to.keep)
Kept
2013 Feb 07
1
Select only unique rows from a data frame
Hello!
I have a data frame with several rows, for example:
x=as.data.frame(matrix(c(1,2,3,
1,2,3,
1,2,2,
1,2,2,
1,1,1),ncol=3,byrow=T))
I would like to find y - a data frame that only has the unique rows from x,
i.e.:
1,2,3
1,2,2
1,1,1
Thanks a lot for your hints!
Dimitri
--
Dimitri Liakhovitski
gfk.com <http://marketfusionanalytics.com/>
[[alternative HTML
2013 Feb 03
1
Adding complex new columns to data frame depending on existing column
Hello
I have a data frame as below
V1 V2 V3 V4 V5 V6
chr1 18884 C CAAAA 2 0
chr1 135419 TATACA T 2 0
chr1 332045 T TTG 0 2
chr1 453838 T TAC 2 0
chr1 567652 T TG 1 0
chr1 602541 TTTA T 2 0
on which I want to perform complex rearrangement such that:
if V3 is a string >1 (i.e line 2) then I
2011 Mar 14
2
code for "permutative" operation
Hello, I need some form of a "permutative" operation on a numeric
vector x
x = (v1, v2, v3, ..., vN)
that produces
x.r = (v1, v1+2, v1+v2+v3, ... v1+v2+...+vN)
If the operation is sum() I can run
x <- 5:8
m <- matrix(rep(x, length(x)), ncol=length(x))
(x.r <- rowsum(m * upper.tri(m, diag=TRUE), rep(1, length(x))))
But there's two things I don't know and kindly
2023 Aug 12
1
Expresión en un objeto
No tuve tiempo de mirarlo, pero, ¿es coherente lo que dice?
El vie, 11 ago 2023 a las 21:02, Griera-yandex (<griera en yandex.com>)
escribió:
> Muchas gracias, Manuel:
>
> Que bueno! No se me había ocurrido lo de GPT!
>
> Lo pruebo.
>
> Saludos.
>
> On Fri, 11 Aug 2023 18:15:18 +0200
> Manuel Mendoza <mmendoza en fulbrightmail.org> wrote:
>
> >
2023 Aug 10
2
Expresión en un objeto
Hola a todos:
Se me ha planteado un problema que no está ligado a ningún problema
concreto. Es más teórico.
Supongamos que tenemos tres variables:
V1 <- c (47, 71, 41, 23, 83, 152, 82, 8, 160, 18)
V2a <- c (NA, 36, 15, 5, 56, 18, NA, 5, NA, 5)
V2b <- c (37, NA, 15, NA, NA, NA, 90, NA, 161, NA)
Supongamos que tengo la expresión (que no puedo asignarlo a
2023 Aug 11
1
Expresión en un objeto
Esta es la respuesta que te da ChatGPT-4:
Entiendo tu pregunta y, aunque no hay una función nativa en R que te
permita hacer exactamente lo que estás pidiendo, puedes lograr el mismo
resultado utilizando una función. Una función te permitiría encapsular la
lógica de la expresión que quieres reutilizar y luego llamar a esa función
donde sea necesario.
He aquí cómo podrías hacerlo:
V1 <-
2023 Aug 11
1
Expresión en un objeto
Muchas gracias, Manuel:
Que bueno! No se me había ocurrido lo de GPT!
Lo pruebo.
Saludos.
On Fri, 11 Aug 2023 18:15:18 +0200
Manuel Mendoza <mmendoza en fulbrightmail.org> wrote:
> Esta es la respuesta que te da ChatGPT-4:
>
> Entiendo tu pregunta y, aunque no hay una función nativa en R que te
> permita hacer exactamente lo que estás pidiendo, puedes lograr el mismo
>
2010 Jul 07
2
Sum vectors and numbers
We want to sum many vectors and numbers together as a vector if there is
at least one vector in the arguments.
For example, 1 + c(2,3) = c(3,4).
Since we are not sure arguments to sum, we are using sum function:
sum(v1,v2,...,n1,n2,..).
The problem is that sum returns the sum of all the values present in its
arguments:
sum(1,c(2,3))=6
sum(1,2,3)=6
We do not want to turn sum(v1,v2,...,n1,n2,..) to
2012 Jul 20
3
Execute a function
Hi,
I would like to evaluate a function, with 3 arguments, for instance,
myfunc<-function(a,b,c) { sqrt(a)-exp(b)+4*c
}
How to execute myfunc(x,y,z), for all x, all y and all z, where x,y,z are
vectors?
Thank you very much in advance
--
View this message in context: http://r.789695.n4.nabble.com/Execute-a-function-tp4637182.html
Sent from
2007 Apr 12
2
data file import - numbers and letters in a matrix(!)
Hello,
I have a problem with the import of a date file. I seems verry tricky.
I have a text file (end of the mail). Every file has a different number of measurments
witch start with "START OF HEIGHT DATA" and ende with "END OF HEIGHT DATA".
I imported the file in a matrix but the letters before the numbers are my problem
(S= ,S=,x=,y=).
Because through the letters and the
2003 May 20
1
How to use pakcage SEM
Hi.
I have tried to use Package "SEM".
As a learning, I try to convert a program running well of EQS
which is as follows to SEM:
### EQS ###
/SPECIFICATION
CAS=100; VAR=5 MAT=COR; ANA=COR;
/EQUATIONS
V1=*F1+E1; V2=*F1+E2; V3=*F1+*F2+E3; V4=**F1+*F2*E4;
V5=*F2+E5;
/VAR
E1 TO E5=*; F1*1.0; F2=1.0;
/COV
E1,E2=*; F1,F2=*:
/PRINT
FIT ALL;
/MATRIX ......
/END
This is the converted SEM
2005 Mar 28
2
Generating list of vector coordinates
Hi.
Can anyone suggest a simple way to obtain in R a list of vector
coordinates of the following form? The code below is Mathematica.
In[5]:=
Flatten[Table[{i,j,k},{i,3},{j,4},{k,5}], 2]
Out[5]=
{{1,1,1},{1,1,2},{1,1,3},{1,1,4},{1,1,5},{1,2,1},{1,2,2},{1,2,3},{1
,2,4},{1,2,
5},{1,3,1},{1,3,2},{1,3,3},{1,3,4},{1,3,5},{1,4,1},{1,4,2},{1,4,3},
{1,4,
2011 Mar 29
4
Simple but elusive - expand back from counts
Dear R-users,
This should be simple but still eludes me:
Given the following
tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12,
"abc", 2), 3, 4, byrow=T))
I want to expand the data to the following form:
V1 V2 V3 V4
1 44 10 abc 1
2 44 10 def 1
3 44 12 abc 1
4 44 12 abc 1
The last row of the original df was duplicated the row by the
2013 Apr 14
3
Create New Column Inside Data Frame for Many Data Frames
Dear R Helpers,
I have a large number of data frames and I need to create a new column
inside each data frame. Because there is a large number, I need to "loop"
through this, but I don't know the syntax of assigning a new column name
dynamically.
Below is a simple example of what I need to do. Assume that I have to do
this for all 26 letters and you should see the form of the
2009 Jul 27
2
Splitting matrix into several small matrices
Dear R users...
I need to split this matrix(or dataframe), for example,
z <- matrix(c(13,1,1,1,1,12,0,0,0,0,8,1,0,1,1,8,0,1,0,0,
10,1,1,1,1,3,0,1,0,0,3,1,0,1,1,6,1,1,1,1),8,5,byrow = T)
> z
[,1] [,2] [,3] [,4] [,5]
[1,] 13 1 1 1 1
[2,] 12 0 0 0 0
[3,] 8 1 0 1 1
[4,] 9 0 1 0 0
[5,] 10 1 1 1 1
2007 Mar 05
3
Rbind with data frames -- column names question
As part of my work, I am trying to append matrices onto data frames.
Naively I assumed that when rbinding a data.frame and matrix, the matrix
would be coerced and appended, keeping the names from the data frame.
Clearly, I am not fully understanding the process by which rbind works.
Example code:
> A<-data.frame(1,1,1); names(A)=letters[1:3] ; B<-matrix(0,2,3)
> rbind(A,B)
2004 Oct 04
7
Strange Matrix Multiplication Behaviour
Hi there fellow R-users,
Im seeing some strange behaviour when I multiply a vector by a matrix
Here is my script:
> tr
1 2 3 4 5 6
0.2217903 0.1560525 0.1487908 0.1671354 0.1590643 0.1471667
>
> ex1
a b c d e f
1 0.2309579 -3.279045 -0.6694697 -1.1024404 0.2303928 -1.5527404
2