Displaying 20 results from an estimated 30000 matches similar to: "creating a function"
2002 Apr 30
1
data.frame package?
Is there a library that is able for example to
1. merge 2 dataframes by row eg.: rbind(dataframe1, dataframe2):data.frame
2. delete a column from a dataframe del(dataframe, colname) or
del(dataframe, colindex= 1):data.frame?
3. Select lines from a dataframe by a specific function ?
select(dataframe, func=small(x){x<1}, colindex=3): data.frame?
4. converting all double columns of a data.frame
2009 May 15
1
creating and then executing command strings
Hi:
I very recently started experimenting with R and am occasionally
running into very basic problems that I can't seem to solve. If there
is an R-newbies forum that is more appropriate for these kinds of
questions, please direct me to it.
I'd like to automatically add vectors to a dataframe. I am able to
build command strings that would do what I want, but R is not
executing them.
A
2011 Sep 16
2
Referring to an object by a variable containing its name: 6 failures
Dear Folks--
I'm trying to make a function that takes the columns I select from a data
frame and then uses a for loop to print some information about each one,
starting with the column name. I succeed in returning the column name, but
nothing else I have tried using the variable colName, containing the name of
the column, to refer to the column itself has worked.
Below I show my
2007 Jan 30
2
rbind-ing list
hi,
i have a list of data.frame that has same structure. i would like to know a
efficient way of rbind-ing it.
right now, i write:
n = length(temp) # 'temp' is a list of data.frames
temp2 = data.frame()
for (i in 1:n) temp2 = rbind( temp2, temp[[i]])
return(temp2)
but this is not an efficient way since we keeping overwriting temp2. i
wonder if there's faster way.
thanks
--
2013 May 27
1
Plot histograms in a loop
Hi,
Try either:
set.seed(28)
stats1<- as.data.frame(matrix(rnorm(5*10000),ncol=5))
pdf(paste("test",1,".pdf",sep=""))
par(mfrow=c(2,1))
lst1<- lapply(names(stats1),function(i) {hist(stats1[,i],100,col="lightblue",main=paste0("Histogram of ",i),xlab=i );qqnorm(stats1[,i])})
dev.off()
#or
2010 Jun 05
1
Write.fwf works from Mac, throws different number of row error in Windows
Hello,
I am having a problem with write.fwf in Windows. I wrote a code to ingest a
number of text files with weather data in them, process them, and then
output a text file with two parts: 1) a set of column names, 2) the
processed data table.
I wrote and tested the program on my Mac, and it worked fine. However, on
the windows machine, where I intend the work to be done, when I run the
2004 Dec 23
2
subsetting a data.frame to the 'unique' of a column
Hi,
I often run into this problem:
I have a data.frame with one column containing entries that are not
unique. What I then want is a subset of the data.frame in which
the entries in that column have become the 'unique' of the original
column.
Normally I program around it by taking the unique of the column and
making a new data.frame with it and filling the rest of the data.
(By the way,
2011 Feb 09
2
assign factor levels based on list
All,
Given a data frame and a list containing factor definitions for certain columns, how can I apply those definitions from the list, rather than doing it the standard way, as noted below. I'm lost in the world of do.call, assign, paste, and can't find my way through. For example:
#set up df
y <- data.frame(colOne = c(1,2,3), colTwo =
2003 Apr 07
4
subsetting a dataframe
How does one remove a column from a data frame when the name of
the column to remove is stored in a variable?
For Example:
colname <- "LOT"
newdf <- subset(olddf,select = - colname)
The above statement will give an error, but thats what I'm trying to
accomplish.
If I had used:
newdf <- subset(olddf,select = - LOT)
then it would have worked, but as I said the column
2007 Jul 30
2
apply, lapply and data.frame in R 2.5
Hello everyone,
A recent (in 2.5 I suspect) change in R is giving me trouble. I want
to apply a function (tolower) to all the columns of a data.frame and
get a data.frame in return.
Currently, on a data.frame, both apply (for arrays) and lapply (for
lists) work, but each returns its native class (resp. matrix and list):
apply(mydat,2,tolower) # gives a matrix
lapply(mydat,tolower) # gives
2016 Jun 01
2
data.frame colname igraph
Si, ese es el problema, lo que implica por ejemplo que no pueda ordenar el data.frame por grados.
Javier Rubén Marcuzzi
De: JCMld
Enviado: miércoles, 1 de junio de 2016 4:28
Para: 'Javier Marcuzzi'; R-help-es en r-project.org
Asunto: RE: [R-es] data.frame colname igraph
Creo que la conversión a data.frame está devolviendo un data frame con una sola columna llamada
2010 Jul 09
2
select columns from vector of column names
Hi
I want to extract columns from a data frame using a vector with the desired
column names.
This short example uses the select argument in the subset function to
accomplish what I am trying to do. Is there a better solution?
#names of desired columns
colnames <- c("col1","col3")
#my data
data <-
2009 Jan 26
2
name scoping within dataframe index
Every time I have to prefix a dataframe column inside the indexing
brackets with the dataframe name, e.g.
df[df$colname==value,]
-- I am wondering, why isn't there an R scoping rule that search
starts with the dataframe names, as if we'd said
with(df, df[colname==value,])
-- wouldn't that be a reasonable default to prepend to the name search
path?
Cheers,
Alexy
2009 Nov 16
1
extracting values from correlation matrix
Hi! All,
I have 2 correlation matrices of 4000x4000 both with same row names and
column names say cor1 and cor2. I have extracted some information from 1st
matrix cor1 which is something like this:
rowname colname cor1_value
a b 0.8
b a 0.8
c f 0.62
d k 0.59
- - --
-
2005 Oct 29
1
how to get colnames of a dataframe within a function called by 'apply'
Hello alltogether,
how is it possible to assign the colnames of a data.frame to a function
called by apply, e.g. for labeling a plot?
Example: I want to plot several qqnorm-plots side by side and there
should be a maintitle for each qqnorm-plot which is identical to the
respective colname.
I checked, but the column which is processed by the function called by
apply does not contain a colname
2012 Aug 11
1
using eval to handle column names in function calling scatterplot graph function
I am running R version 2.15.1 in Windows XP
I am having problems with a function I'm trying to create to:
1. subset a data.frame based on function arguments (colname & parmname)
2. rename the PARMVALUE column in the data.frame based on function
argument (xvar)
3. generate charts
plotvar <- function(parentdf,colname, parmname,xvar,yvar ){
subdf <-
2011 Feb 15
1
summary for factors is not very informative
summary() for a factor prints:
ColName
SNDK : 72
VXX : 36
MWW : 30
ACI : 28
FRO : 28
(Other):1801
it would have been much more useful if it additionally
printed frequency stats as if by
summary(aggregate(frame$ColName,by=list(frame$ColName),FUN=length)$x)
--
Sam Steingold (http://sds.podval.org/) on CentOS release 5.3 (Final)
http://jihadwatch.org
2010 Sep 15
1
optim with BFGS--what may lead to this, a strange thing happened
Dear R Users
on a self-written function for calculating maximum likelihood probability (plz
check function code at the bottom of this message), one value, wden, suddenly
jump to zero. detail info as following:
w[11]=2.14
lnw =2.37 2.90 3.76 ...
regw =1.96 1.77 1.82 ....
wden=0.182 0.178 0.179...
w[11]=2.14
lnw=2.37 2.90 3.76 ...
regw =1.96 1.77 1.82 ....
wden=0.182
2005 Feb 07
2
Programming/scripting with "expressions - variables"
Hello to Rusers!
I am puzzled with R and I really do not know where to look
in for my problem. I am moving from SAS and I have difficulties
in translating SAS to R world. I hope I will get some hints
or pointers so I can study from there on.
I would like to do something like this. In SAS I can write
a macro as example bellow, which is afcourse a silly one but
shows what I don't know how
2010 Jul 09
1
select columns from dataframe
Hi,
I would like to extract columns from a dataframe using a vector of desired
column names.
The following working example uses the select argument in the subset
function to accomplish what I am trying to do. Is there a better solution?
Thanks.
#my data
data <- data.frame("col1"=c(1,2,3),"col2"=c("A","B","C"),"col3"=c(4,5,6))