[R] R help

Sarah Goslee sarah.goslee at gmail.com
Tue Oct 13 21:42:26 CEST 2015


Hi,

First of all, you almost certainly want to get your data into R with
stringsAsFactors=FALSE rather than creating a factor with 345196
levels.

mydata <- read.table("whateverfile", stringsAsFactors=FALSE)

I'm just guessing, but you probably also don't really want filter(),
but subset() instead.

# fake data - you can use dput(head(mydata)) to provide some real data
mydata <- data.frame(Number=c("1.001", "1.002", "1.003", "2.001", "2.002",
"2.003"), Name=c("x", "y"), Amount=1:6, stringsAsFactors=FALSE)

subset(mydata, grepl("\\.002$", mydata$Number))


  Number Name Amount
2  1.002    y      2
5  2.002    x      5

If that's what you're after, you should probably take a look at
?filter to see what you were doing, and ?subset and ?grepl to see one
way to approach the question.

Sarah


On Tue, Oct 13, 2015 at 2:24 PM, Clayton Samples
<claytonsamples at gmail.com> wrote:
> Hello R community,
>
> I need a bit of direction. I am new to R, so please forgive any mistakes or
> confusion.
>
>
> Here is an example of the columns and data contained in my data frame.
> Number: Factor w 345196 levels "1.001", "1.002", "1.003", "2.001", "2.002",
> "2.003"
> Name: factor w 2 levels ("X", "Y")
> Variable: factor w 21 levels "unknown", "known"
> Amount: num(1, 2, 3, 4, 5, 6)
>
> My objective is to filter based on numbers ending in .002 within column
> Number
>
> I have used the melt function to organize the data and then tried
>
> filter(df, PO.Number %in% c(.002))
>
> However, this didn't work.
>
> Thanks for the help.
>


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list