Re: [R] data.frame and subsetting problem

From: jim holtman <jholtman_at_gmail.com>
Date: Sat, 16 Jun 2007 17:36:42 -0400

Not sure what 'x2' is that you are plotting; it is not defined. read.delimand subset return dataframes, so you don't need data.frame.

Here is something that does work:

> x <- "shirt,size,40

+ shirt,color,10
+ shirt,length,10
+ shirt,brand, 1
+ shoes,style,5
+ shoes,brand,4
+ shoes,color,1"

> x <- read.csv(textConnection(x), header=FALSE)
>
>
> x

     V1 V2 V3
1 shirt size 40
2 shirt color 10
3 shirt length 10
4 shirt brand 1
5 shoes style 5
6 shoes brand 4
7 shoes color 1
> plot(subset(x, V1=="shirt")[,2:3])
>

On 6/16/07, Michelle Wynn <mlwynn_at_indiana.edu> wrote:
>
> I have read the R online help and wiki and I cannot seem to get something
> to
> work the way I need it to.
>
> I want to create a new data frame from an subset of an existing data frame
> which has no reference to the original superset. If you following this
> example, what I am trying to do may make more sense.
>
> I have a file with values like this:
>
> shirt,size,40
> shirt,color,10
> shirt,length,10
> shirt,brand, 1
> shoes,style,5
> shoes,brand,4
> shoes,color,1
>
> and I read it into a dataframe like:
> x <- data.frame(read.delim("temp2.txt", sep=",", header=FALSE))
>
> I then want to plot just a subset of this data (say shirts only)...
> y <- data.frame(subset(x, V1 == "shirt"))
> plot(x2[,2:3])
>
> when I do, the resulting plot contains an empty value for 'color' even
> though my subset has no value in column V2 that equals 'color' anymore.
>
> Is it possible create a new data.frame that truly deletes the rows from
> the
> original data frame that I am excluding with the subset parameter?
>
> Thanks,
> Michelle
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_stat.math.ethz.ch 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.
Received on Sat 16 Jun 2007 - 21:42:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 16 Jun 2007 - 23:32:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.