Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a set of 20 column, each contains number value. I would like to have a function in excel or in r or somewhere else to extract the shared values among all the columns.
Several of the online Venn tools can visualize and list among up to 6 columns.
Any tool?
Thanks
in R, we can use intersect with Reduce to get the common values across all the columns
Reduce(intersect, dftest)
data
dftest <- data.frame(col1 = 1:5, col2 = 2:6, col3 = 3:7)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have two columns x and y. I want to have one column which contains the ranking for both columns. I thought about sum both column and then get it ranked, does any one have a function that rank two columns in r?
Many thanks
If you are just wanting to use the rank function as you suggest:
df1 <- data.frame(x = rnorm(10), y = rnorm(10))
apply(df1, 2, rank) # 2 columns with separate rankings
rank(rowSums(df1)) # sum by rows first, then rank
rank(rowMeans(df1)) # avg by rows first, then rank (same result!)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
The community reviewed whether to reopen this question 11 months ago and left it closed:
Duplicate This question has been answered, is not unique, and doesn’t differentiate itself from another question.
Improve this question
How can I scale(x) only certain columns of a dataframe? I have a dataframe with 7 columns and I want to scale only column 3 and 6. The rest should stay as it is.
We can do this with lapply. Subset the columns of interest, loop through them with lapply, assign the output back to the subset of data. Here, we are using c because the outpuf of scale is a matrix with a single column. Using c or as.vector, it gets converted to vector
df[c(3,6)] <- lapply(df[c(3, 6), function(x) c(scale(x)))
Or another option is mutate_at from dplyr
library(dplyr)
df %>%
mutate_at(c(3,6), funs(c(scale(.))))
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
dat = runif(10,1,10)
dat2 = runif(10,1,10)
dat3 = runif(10,1,10)
data = rbind(dat,dat2,dat3)
In the case of above data, I am wondering how I can filter out rows as long as there is one element in that row exceeding 5.
I know that I can use loop to achieve this, but I am wondering if there is more succinct way to do this.
try this:
data[apply(data>5, 1, sum)>0,]
This says "for condition having more than zero number exceeding 5 in each row, filter data".
data[do.call(pmax,data.frame(data))<=5,]
Cheers,
Bert
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I would like to conditionally replace the values of each columns in R. My data looks like below image.
In this, I want to check if the values are >UCL then want to replace with UCL value and If the values are
The Output should look like below image:
Like this I have many rows and columns data and I'm looking for solution in R.
We create a 'df2' as a copy of 'df1'. Using the 'i1' and 'i2' index, we replace the columns 1:4 in 'df2' with corresponding 'UCL' and 'ICL' values that fits the condition.
df2 <- df1
i1 <- df1[1:4] > df1$UCL
i2 <- df1[1:4] < df1$LCL
df2[1:4][i1] <- df2$UCL[row(df2[1:4])][i1]
df2[1:4][i2] <- df2$LCL[row(df2[1:4])][i2]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Does anybody know the examples on how to run paired ttest in Matlab/R/SAS or Python/Java on many columns (I have 1139 variables) in all combinations or selected respective columns in a loop.
thank you
MATLAB Solution:
If I understand correctly, you're just looking for a way to feed ttest with two different columns from your input matrix everytime. You can get all possible combinations of column pairs using nchoosek:
pairs = nchoosek(1:size(X, 2), 2);
Now you can iterate over these indices, each time invoking ttest with a different pair:
for idx = transpose(pairs)
h = ttest(X(:, idx(1)), X(:, idx(2)));
%// Do something with the result...
end