Hi
r-help-bounces at r-project.org napsal dne 07.07.2009 19:06:17:
> Hi,
>
> I am confused about how to select elements from a list.
>
> I'm trying to select all rows of a table 'crossRsorted' such
that the
> mean of a related vector is > 0. The related vector is accessible as
> a list element l[[i]] where i is the row index.
>
> I thought this would work:
>
> > crossRsorted[mean(q[[ crossRsorted[,1] ]], na.rm = TRUE) > 0, ]
> Error in q[[crossRsorted[, 1]]] : no such index at level 2
Strange, I got completely different error. Couldn't be that only ***you***
have crossRsorted?
> crossRsorted[mean(q[[ crossRsorted[,1] ]], na.rm = TRUE) > 0, ]
Error: object 'crossRsorted' not found>
What is crossRsorted? Data frame?, List? What is q? List?
You need to provide at least output from
str(q) and str(crossRsorted) to get some reasonable answers.
and far better to provide artificial data to demonstrate the problem.
with 2 data frames
df1[rowMeans(df2)>0,]
selects rows of df1 which correspond to rows with row mean df2>0
with data frame and list
df1[sapply(list1,mean)>0,]
selects rows of df1 which correspond to list elements with mean >0
But without knowing structure of your data? Nobody knows.
Regards
Petr
>
> How can I express: "select only those rows 'r_i' from
crossRsorted
> where mean(q[[r_i[1]]]) > 0?
>
> Thanks,
>
> - Godmar
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.