Displaying 20 results from an estimated 8000 matches similar to: "How to extract row values?"
2009 Jul 09
2
correct way to subset a vector
Hi,
#make example data
dat <- data.frame(matrix(rnorm(15),ncol=5))
colnames(dat) <- c("ab","cd","ef","gh","ij")
If I want to get a subset of the data for the middle 3 columns, and I
know the names of the start column and the end column, I can do this:
mysub <- subset(dat,select=c(cd:gh))
If I wanted to do this just on the column names,
2011 Feb 10
2
for loop to merge .csvs
So I needed to merge 17 .csv files, and did so by brute force, but I might
need to do so again. Anyone have suggestions for a for loop that might do
the below for me (where a:r are separate .csv files)
ab<-merge(a,b,all=TRUE)
cd<-merge(c,d,all=TRUE)
ef<-merge(e,f,all=TRUE)
gh<-merge(g,h,all=TRUE)
ij<-merge(i,j,all=TRUE)
kl<-merge(k,l,all=TRUE)
no<-merge(m,n,all=TRUE)
2008 Jun 14
1
Correcting the display of colnames and rownames
Dear all,
I have a data frame of dimension 720 columns by 360 rows, to which I am trying to add numerical row and column labels to, using the 'sequence' command. The original data, which I read in using 'read.table', had no such labels at all.
I've got as far as successfully using the sequence command and getting the labels to display. However, I'm finding that for the
2008 Jun 17
2
Reshape or Stack? (To produce output as columns)
Dear all,
I have used 'read.table' to create a data frame of 720 columns and 360 rows (and assigned this to 'Jan'). The row and column names are numeric:
> columnnames <- sprintf("%.2f", seq(from = -179.75, to = 179.75, length = 720)).
> rnames <- sprintf("%.2f", seq(from = -89.75, to = 89.75, length = 360))
> colnames(Jan) <- columnnames
2010 May 07
3
Find the three best values in every row
Hello,
i have a dataframe with the GDP for different Country (in the columns) and
Years (in the rows).
Now i want for every year the best three values, if possible with name of
the countries (columnnames).
For the best it's no problem but for the other two values.
Thanks,
Alfred
2008 Jul 15
3
Melt (reshape) question
Dear all,
I
have a grid of 720 columns by 360 rows of global population density
values, and hope to convert this to column format using the 'melt' command in the 'reshape' package. I'm not receiving
any errors as such, but when the code has finished running, my output
looks like this:
> head(PopDens.long)
Latitude Longitude PopDensity
1 -84.75 V1 0
2
2009 Sep 19
1
how to add tables of different dimensions
Hi all!
I'm stuck with this "easy" problem. I have two tables (a and b) which i would like to add. table a looks like:
a
var1 var2
3 4
and table b looks like:
b
var1
10
I would like this result: c<- a+b
c
var1 var2
13 4
Best regards Henrik K?llberg
2009 Apr 08
2
Reshape - strange outputs
Dear R Users,
I am using the reshape package to reformat gridded data into column format using the code shown below. However, when I display the resulting object, a single column is fomed (instead of three) and all the latitude values (which should be in either column one or two) are collected at the bottom. Also, the NA values aren't removed, despite this being requested in the code.
Code:
2005 Jul 27
2
How to delete rows
Dear R-users,
I am very new to R, so maybe my question is very easy to answer.
I have the following table:
TAB1<-data.frame(Name,Number), "Name" and "Number" are all character
strings,
it looks like this:
Name Number
ab 2
ab 2
NA 15
NA 15
NA 15
cd 3
ef 1
NA 15
NA 15
gh 15
gh 15
I want to delete all the rows
2012 Feb 17
5
How to change the order of columns in a data frame?
Dear all,
I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below.
> colnames(pos1)
[1] "X" "X1" "X10" "X11" "X12" "X13" "X14" "X15" "X16"
2012 Dec 11
5
Renaming column names according to another dataframe
Hi,
I've got a dataframe having a code as column name.
Addtionally I have another dataframe with a two columns (and lots of
rows), the first
containing the code and the second some Text (real name).
Now I'd like to use the information (pairs of code and name) of the
second dataframe to rename all the columnnames in the first dataframe.
How is it possible to achieve that?
Here a small
2013 Mar 25
3
nested 'while' loops
Hi everyone,
I'm using the following code to go over every element of a data frame (row
wise). The problem I am facing is that the outer 'x' variable is not
incrementing itself, thus, only one row of values is obtained, and the
program does not proceed to the next row.
This is the code:
while(x<=coln)
{
while(y<=rown)
{
n<-as.numeric(df[[y]][x]);
2007 Jun 22
1
speed issues / pros & cons: dataframe vs. matrix
I've read that certain operations performed on a matrix (e.g. ribind, cbind) are often much faster compared to operations performed on a data frame.
Other then the "bind functions", what are the main operations that are significantly faster on a a matrix?
I know that data frames allow for columnnames and rownames, and that each column in a data frame can have different data types.
2010 Apr 13
2
transpose but different
Hi all,
I want to make extra columns in my datafile where the id of every
groupmember is mentioned in separate columns. To explain it better see the
example:
id<-c(1,2,3,4,5,6,7,8,9,10,11,12)
group<-c(1,1,1,1,2,2,3,3,3,3,3,3)
a<-as.data.frame(cbind(id,group))
a
id group
1 1 1
2 2 1
3 3 1
4 4 1
5 5
2009 Nov 29
3
How to z-standardize for subgroups?
Hi folks,
I have a dataframe df.vars with the follwing structure:
var1 var2 var3 group
Group is a factor.
Now I want to standardize the vars 1-3 (actually - there are many
more) by class, so I define
z.mean.sd <- function(data){
return.values <- (data - mean(data)) / (sd(data))
return(return.values)
}
now I can call for each var
z.var1 <- by(df.vars$var1, group,
2006 Sep 26
2
creation of new variables
Hello All,
I have 8 variables named
a b c d e f g h
I need to create four variables from these 8 vraibles in R.
the new variables are ab,cd,ef,gh.
Can anyone pleas help me
thanks,
Pratap
---------------------------------
[[alternative HTML version deleted]]
2010 Jun 10
1
To give column names of a data-frame
Sir,
I want to export the results of R in a data frame. So I want to give
rownames,columnnames & title to the data-frame.I have applied the following:
data.frame(matrix(c(...),nrow=,ncol=),row.names=c("a","b"),col.names=c("c","d"),title="aaa")
But, it does not work.
Can you help me?
Regards,
Suman Dhara
[[alternative HTML version
2011 Sep 23
1
Newbie question: Converting Table
Hi,
I'm new to R, and I have searched helpfiles and this forum on my 2
questions. Hope you guys can help me out! :-)
Many thanks in advance!
Cheers,
Lars
Q1: I imported a csv file with columnames subject and class. There are about
1000 different classes...
It looks like this:
subject1, class1
subject1, class2
subject2, class1
subject2, class3
...
subject999, class1
subject999, class2
2010 Mar 18
1
Imported tables from Access 2007
Hi all,
I am very new to R and I'm trying to import data from Microsoft Access. So
far, I've managed to do so successfully using the following code:
testdb <- file.path("c:\Databse.accdb")
channel2 <- odbcConnectAccess2007(testdb)
data.table <- sqlFetch(channel2,"data")
This successfully imports a table(?) called "data.table".
But when I try to
2009 Mar 31
0
Row/columns names within 'assign' command
Dear all,
I am attempting to add row and column names to a series of tables (120 in total) which have 2 variable parts to their name. These tables are created as follows:
# Create table indexes
index <- expand.grid(year = sprintf("%04d", seq(1986, 1995)), month = sprintf("%02d", 1:12))
# Read in and assign file names to individual objects with variable name components