[R] How to create a new variable?

arun smartpink111 at yahoo.com
Sun Mar 2 05:47:41 CET 2014


Hi,

Not sure about your expected result.  If you need a logical index as the new variable:
##check str(Food)
Food[,-1] <- lapply(Food[,-1],function(x) as.numeric(as.character(x)))  

str(Food)

 Food1 <- within(Food,Healthy.food <- GRASSI < 20)
 HFood <- Food1[Food1$Healthy.food,-7]
 dim(HFood)
#[1] 152   6
A.K.


Hello, I have a table: 

> library(XML) 
> u='http://www.ininternet.org/calorie.htm'
> tables = readHTMLTable(u) 
> Food=tables[[9]] 
> View(Food) 

And now I don't know how to create a new variable named 
Healthy.food, in which would be all foods which fat(GRASSI) is lower 
than 20. Please help me 

Nina



More information about the R-help mailing list