Displaying 2 results from an estimated 2 matches for "unique_x".
2011 Jul 28
3
Data frame to list
...something obvious. Given:
x=c(1,1,1,2,2,3,3,3)
y=c(1:length(x))
dataframe=data.frame(x,y)
I would like to convert this to a list for use with certain functions,
where each entry of the list is a subsetted dataframe based on
dataframe$x
I can do this "brute force" by a for-next loop:
unique_x=unique(dataframe$x)
unique_x_N=length(unique_x)
dataframe_to_list=vector(mode="list",length=unique_x_N)
for(i in 1:unique_x_N)
{
dataframe_to_list[[i]]=subset(dataframe,x==unique_x[i])
}
My R-gut is telling me there's a much more efficient way of doing this
-- is it right?
--j
2010 Feb 26
1
Unique Values of a Matrix
I have a 280,000 x 11 matrix with various values and many NA values. What I would like to do is get a vector of every unique value in the matrix.
For example:
X = [ 1 2 NA
4 3 1
7 NA 2 ]
Returns:
Unique_X = [ 1, 2, 3, 4, 7]
Thanks,
Todd
[[alternative HTML version deleted]]