Questions tagged [dataframe]
A data frame is a 2D tabular data structure. Usually, it contains data where rows are observations and columns are variables and are allowed to be of different types (as distinct from an array or matrix). While "data frame" or "dataframe" is the term used for this concept in several languages (R, Apache Spark, deedle, Maple, the pandas library in Python and the DataFrames library in Julia), "table" is the term used in MATLAB and SQL.
dataframe
146,984
questions
8
votes
1
answer
1k
views
Data.frame becomes factor/vector after filtering/subsetting
I have a data.frame with one column, like so:
>d = data.frame(animal=c("horse","dog","cat"))
then I filter it by excluding all items also present in a vector. e.g.:
> res = d[!(d$animal %in% ...
102
votes
11
answers
239k
views
How to plot all the columns of a data frame in R
The data frame has n columns and I would like to get n plots, one plot for each column.
I'm a newbie and I am not fluent in R, anyway I found two solutions.
The first one works but it does not print ...
7
votes
3
answers
6k
views
Selecting rows and ordering the result in R
The seemingly trivial task of selecting rows in a data frame and then ordering them is eluding me, and driving me crazy at the same time. For example, lets have a trivial data frame:
country = c("US",...
50
votes
4
answers
15k
views
Fast vectorized merge of list of data.frames by row
Most of the questions about merging data.frame in lists on SO don't quite relate to what I'm trying to get across here, but feel free to prove me wrong.
I have a list of data.frames. I would like to "...
1083
votes
20
answers
2.4m
views
Remove rows with all or some NAs (missing values) in data.frame
I'd like to remove the lines in this data frame that:
a) contain NAs across all columns. Below is my example data frame.
gene hsap mmul mmus rnor cfam
1 ENSG00000208234 0 NA NA ...
0
votes
2
answers
230
views
List of List in Data Frame
I have a data that is generated like this:
> dat1 <- data.frame(V1 = rep(1, 5), V2 = sample(c(40:45), 5))
> dat2 <- data.frame(V1 = sample(c(0,1), 5, replace = TRUE), V2 = sample(c(40:45),...
13
votes
3
answers
8k
views
Joining factor levels of two columns
I have 2 columns of data with the same type of data (Strings).
I want to join the levels of the columns. ie. we have:
col1 col2
Bob John
Tom Bob
Frank Jane
Jim Bob
Tom Bob
... ... (...
1
vote
2
answers
8k
views
How to Create Nested Data Frame
I have a data that looks like this.
> file1="dat1.tab"
> file2="dat2.tab"
> dat1<-read.table(file1)
> print(dat1)
V1 V2
1 1 43
2 1 43
3 1 43
>
> dat2<-read.table(file2)
&...
3
votes
3
answers
1k
views
R: Fast multiply selected rows in data.frame (or other data structure)
I have an object of type data.frame like this, but much bigger:
> head(mydf)
id1 id2 n
1 0 1032142 3
2 0 1072163 1
3 0 119323 2
I need to print to a file ...
3
votes
1
answer
3k
views
Plotting scatterplots with pairs in R, in log scale with data containing zeros
I am trying to plot some pairs of scatterplots using "pairs".
My dataframe look like :
>e
X Y Z
0 0 0
2 3 4
0 3 4
3 3 3
A completely standard dataframe here.
I use this ...
1
vote
2
answers
9k
views
chisq.test Error Message
Here's a problem I'm encountering:
Example Data
df <- data.frame(1,2,3,4,5,6,7,8)
df <- rbind(df,df,df,df)
What I would like to do is find the p.value for the chisq.test of 1,2,3 vs. 4,5,6 ...
2
votes
2
answers
1k
views
R Question: ifelse producing unexpected results
I am new to R and am getting unexpected results while using the ifelse() function. Here is an example. Below is a subset of the data frame I am working with. After the last command, why does the ...
5
votes
2
answers
3k
views
R: Split unbalanced list in data.frame column
Suppose you have a data frame with the following structure:
df <- data.frame(a=c(1,2,3,4), b=c("job1;job2", "job1a", "job4;job5;job6", "job9;job10;job11"))
where the column b is a semicolon-...
2
votes
3
answers
3k
views
Subsetting a data frame in a function using another data frame as parameter
I would like to submit a data frame to a function and use it to subset another data frame.
This is the basic data frame:
foo <- data.frame(var1= c(1, 1, 1, 2, 2, 3), var2=c('A', 'A', 'B', 'B', 'C'...
0
votes
1
answer
616
views
R merge dataframes in specific order
I have three equal-sized data frames that I want to merge in a particular order so that I can then use write.table to make a formatted text file for use in another program.
I want this:
...